Teams Winter 2011/team2/project

From CDOT Wiki
Revision as of 15:58, 16 April 2011 by Thupten (talk | contribs)
Jump to: navigation, search

Tutorial

In this tutorial, we will be elaborating on how to replicate our OSGI project application. We will provide a brief explanation of each plug-in project needed, the packages that corresponds to those projects, and of course the java source files that will be used to create the program.

Project

For this project, we are going to create a weather service program using the osgi framework. This project will contain three bundles: Consumer, Interface and Provider bundles. The Interface bundle will contain a set of interface and classes used by both Consumer and Provider. The Provider bundle will provide a service to return weather information for a selected city. The Consumer bundle will use the service reference to get weather information from the Provider and display in a GUI window based on Java Swing Library.

Prerequisites


Steps

Prepare eclipse

1. In Eclipse, create a new workspace. 2. Create a new Plug-in project following settings, name it consumer.
Ecl500-Team2-Project img01.png

Ecl500-Team2-Project img02.png

Ecl500-Team2-Project img03.png

3. Likewise create 2 more plug-in projects called interface and provider. Uncheck the 'Generate Activator' option for interface.

Interface bundle

1. In the interface bundle, we create a package, ecl.team2.project.weather. We will create classes and interface java files that are used by consumer and provider bundles.
Ecl500-Team2-Project img04 interface.png

2. The default MANIFEST.MF of interface bundle looks like this. It does not require any modification.

Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Weather
Bundle-SymbolicName: interface
Bundle-Version: 1.0.0.qualifier
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Export-Package: ecl.team2.project.weather

3. Create interface WeatherInterface.java

package ecl.team2.project.weather;

import java.util.ArrayList;

public interface WeatherInterface {
	WeatherAndCurrent getWeather(String city) throws Exception;
    ArrayList<Location> getCity (String city) throws Exception;
}

4. Create WeatherAndCurrent.java

package ecl.team2.project.weather;

import java.util.ArrayList;

public  class WeatherAndCurrent {
	CurrentCondition Current;
	public WeatherAndCurrent() {
		super();
		// TODO Auto-generated constructor stub
	}
	public WeatherAndCurrent(CurrentCondition current, ArrayList<Weather> weathers) {
		super();
		Current = current;
		this.weathers = weathers;
	}
	public CurrentCondition getCurrent() {
		return Current;
	}
	public void setCurrent(CurrentCondition current) {
		Current = current;
	}
	public ArrayList<Weather> getWeathers() {
		return weathers;
	}
	public void setWeathers(ArrayList<Weather> weathers) {
		this.weathers = weathers;
	}
	ArrayList<Weather> weathers;
}

5. Create Weather class

package ecl.team2.project.weather;


public class Weather {
	private String date;
	private String tempMaxC;
	private String tempMaxF;
	private String tempMinC;
	private String tempMinF;
	private String windspeedMiles;
	private String windspeedKmph;
	private String winddirection;
	private String winddir16Point;
	private String winddirDegree;
	private String weatherCode;
	private String weatherIconUrl;
	private String weatherDesc;
	private String precipMM;


	public Weather(){
		super();
	}
	public Weather(String date, String tempMaxC, String tempMaxF,
			String tempMinC, String tempMinF, String windspeedMiles,
			String windspeedKmph, String winddirection, String winddir16Point,
			String winddirDegree, String weatherCode, String weatherIconUrl,
			String weatherDesc, String precipMM) {
		super();
		this.date = date;
		this.tempMaxC = tempMaxC;
		this.tempMaxF = tempMaxF;
		this.tempMinC = tempMinC;
		this.tempMinF = tempMinF;
		this.windspeedMiles = windspeedMiles;
		this.windspeedKmph = windspeedKmph;
		this.winddirection = winddirection;
		this.winddir16Point = winddir16Point;
		this.winddirDegree = winddirDegree;
		this.weatherCode = weatherCode;
		this.weatherIconUrl = weatherIconUrl;
		this.weatherDesc = weatherDesc;
		this.precipMM = precipMM;
	}
	public String getDate() {
		return date;
	}
	public void setDate(String date) {
		this.date = date;
	}
	public String getTempMaxC() {
		return tempMaxC;
	}
	public void setTempMaxC(String tempMaxC) {
		this.tempMaxC = tempMaxC;
	}
	public String getTempMaxF() {
		return tempMaxF;
	}
	public void setTempMaxF(String tempMaxF) {
		this.tempMaxF = tempMaxF;
	}
	public String getTempMinC() {
		return tempMinC;
	}
	public void setTempMinC(String tempMinC) {
		this.tempMinC = tempMinC;
	}
	public String getTempMinF() {
		return tempMinF;
	}
	public void setTempMinF(String tempMinF) {
		this.tempMinF = tempMinF;
	}
	public String getWindspeedMiles() {
		return windspeedMiles;
	}
	public void setWindspeedMiles(String windspeedMiles) {
		this.windspeedMiles = windspeedMiles;
	}
	public String getWindspeedKmph() {
		return windspeedKmph;
	}
	public void setWindspeedKmph(String windspeedKmph) {
		this.windspeedKmph = windspeedKmph;
	}
	public String getWinddirection() {
		return winddirection;
	}
	public void setWinddirection(String winddirection) {
		this.winddirection = winddirection;
	}
	public String getWinddir16Point() {
		return winddir16Point;
	}
	public void setWinddir16Point(String winddir16Point) {
		this.winddir16Point = winddir16Point;
	}
	public String getWinddirDegree() {
		return winddirDegree;
	}
	public void setWinddirDegree(String winddirDegree) {
		this.winddirDegree = winddirDegree;
	}
	public String getWeatherCode() {
		return weatherCode;
	}
	public void setWeatherCode(String weatherCode) {
		this.weatherCode = weatherCode;
	}
	public String getWeatherIconUrl() {
		return weatherIconUrl;
	}
	public void setWeatherIconUrl(String weatherIconUrl) {
		this.weatherIconUrl = weatherIconUrl;
	}
	public String getWeatherDesc() {
		return weatherDesc;
	}
	public void setWeatherDesc(String weatherDesc) {
		this.weatherDesc = weatherDesc;
	}
	public String getPrecipMM() {
		return precipMM;
	}
	public void setPrecipMM(String precipMM) {
		this.precipMM = precipMM;
	}
}

6. CurrentCondition.java class will return current weather.

package ecl.team2.project.weather;

public class CurrentCondition {
	private String observation_time;
	private String temp_C;
	private String temp_F;
	private String weatherCode;
	private String weatherIconUrl;
	private String weatherDesc;
	private String windspeedMiles;
	private String windspeedKmph;
	private String winddirDegree;
	private String winddir16Point;
	private String precipMM;
	private String humidity;
	private String visibility;
	private String pressure;
	private String cloudcover;
	
	public CurrentCondition(String observation_time, String temp_C, String temp_F,
			String weatherCode, String weatherIconUrl, String weatherDesc,
			String windspeedMiles, String windspeedKmph, String winddirDegree,
			String winddir16Point, String precipMM, String humidity,
			String visibility, String pressure, String cloudcover) {
		super();
		this.observation_time = observation_time;
		this.temp_C = temp_C;
		this.temp_F = temp_F;
		this.weatherCode = weatherCode;
		this.weatherIconUrl = weatherIconUrl;
		this.weatherDesc = weatherDesc;
		this.windspeedMiles = windspeedMiles;
		this.windspeedKmph = windspeedKmph;
		this.winddirDegree = winddirDegree;
		this.winddir16Point = winddir16Point;
		this.precipMM = precipMM;
		this.humidity = humidity;
		this.visibility = visibility;
		this.pressure = pressure;
		this.cloudcover = cloudcover;
	}
	
	public CurrentCondition() {
		super();
	}

	public String getObservation_time() {
		return observation_time;
	}
	public void setObservation_time(String observation_time) {
		this.observation_time = observation_time;
	}
	public String getTemp_C() {
		return temp_C;
	}
	public void setTemp_C(String temp_C) {
		this.temp_C = temp_C;
	}
	public String getTemp_F() {
		return temp_F;
	}
	public void setTemp_F(String temp_F) {
		this.temp_F = temp_F;
	}
	public String getWeatherCode() {
		return weatherCode;
	}
	public void setWeatherCode(String weatherCode) {
		this.weatherCode = weatherCode;
	}
	public String getWeatherIconUrl() {
		return weatherIconUrl;
	}
	public void setWeatherIconUrl(String weatherIconUrl) {
		this.weatherIconUrl = weatherIconUrl;
	}
	public String getWeatherDesc() {
		return weatherDesc;
	}
	public void setWeatherDesc(String weatherDesc) {
		this.weatherDesc = weatherDesc;
	}
	public String getWindspeedMiles() {
		return windspeedMiles;
	}
	public void setWindspeedMiles(String windspeedMiles) {
		this.windspeedMiles = windspeedMiles;
	}
	public String getWindspeedKmph() {
		return windspeedKmph;
	}
	public void setWindspeedKmph(String windspeedKmph) {
		this.windspeedKmph = windspeedKmph;
	}
	public String getWinddirDegree() {
		return winddirDegree;
	}
	public void setWinddirDegree(String winddirDegree) {
		this.winddirDegree = winddirDegree;
	}
	public String getWinddir16Point() {
		return winddir16Point;
	}
	public void setWinddir16Point(String winddir16Point) {
		this.winddir16Point = winddir16Point;
	}
	public String getPrecipMM() {
		return precipMM;
	}
	public void setPrecipMM(String precipMM) {
		this.precipMM = precipMM;
	}
	public String getHumidity() {
		return humidity;
	}
	public void setHumidity(String humidity) {
		this.humidity = humidity;
	}
	public String getVisibility() {
		return visibility;
	}
	public void setVisibility(String visibility) {
		this.visibility = visibility;
	}
	public String getPressure() {
		return pressure;
	}
	public void setPressure(String pressure) {
		this.pressure = pressure;
	}
	public String getCloudcover() {
		return cloudcover;
	}
	public void setCloudcover(String cloudcover) {
		this.cloudcover = cloudcover;
	}	
}

7. Location.java class will contain location information. This class contains detailed information about a location like city, country, coordinates, population. We will only be using the city name for this project.

package ecl.team2.project.weather;

public class Location {
	private String areaName;
	private String country;
	private String region;
	private String latitude;
	private String longitude;
	private String population;
	public Location(String areaName, String country, String region,
			String latitude, String longitude, String population) {
		super();
		this.areaName = areaName;
		this.country = country;
		this.region = region;
		this.latitude = latitude;
		this.longitude = longitude;
		this.population = population;
	}
	public Location() {
		super();
		// TODO Auto-generated constructor stub
	}
	public String getAreaName() {
		return areaName;
	}
	public void setAreaName(String areaName) {
		this.areaName = areaName;
	}
	public String getCountry() {
		return country;
	}
	public void setCountry(String country) {
		this.country = country;
	}
	public String getRegion() {
		return region;
	}
	public void setRegion(String region) {
		this.region = region;
	}
	public String getLatitude() {
		return latitude;
	}
	public void setLatitude(String latitude) {
		this.latitude = latitude;
	}
	public String getLongitude() {
		return longitude;
	}
	public void setLongitude(String longitude) {
		this.longitude = longitude;
	}
	public String getPopulation() {
		return population;
	}
	public void setPopulation(String population) {
		this.population = population;
	}
	
}