Difference between revisions of "Teams Winter 2011/team2/project"

From CDOT Wiki
Jump to: navigation, search
Line 10: Line 10:
  
 
==Steps==
 
==Steps==
 +
 +
=Prepare eclipse=
 
1. In Eclipse, create a new workspace.  
 
1. In Eclipse, create a new workspace.  
 
2. Create a new Plug-in project following settings, name it consumer.<br/>
 
2. Create a new Plug-in project following settings, name it consumer.<br/>
Line 16: Line 18:
 
[[Image:ecl500-Team2-Project_img03.png ]]<br/><br/>
 
[[Image:ecl500-Team2-Project_img03.png ]]<br/><br/>
 
3. Likewise create 2 more plug-in projects called interface and provider. Uncheck the 'Generate Activator' option for interface.
 
3. Likewise create 2 more plug-in projects called interface and provider. Uncheck the 'Generate Activator' option for interface.
4. 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.<br/>
 
[[Image:Ecl500-Team2-Project img04 interface.png]]<br/><br/>
 
5. The default MANIFEST.MF of interface bundle looks like this. It does not require any modification.
 
  
 +
=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.<br/>
 +
[[Image:Ecl500-Team2-Project img04 interface.png]]<br/><br/>
 +
2. The default MANIFEST.MF of interface bundle looks like this. It does not require any modification.
 
<syntaxhighlight lang="xml">
 
<syntaxhighlight lang="xml">
 
Manifest-Version: 1.0
 
Manifest-Version: 1.0
Line 31: Line 34:
 
</syntaxhighlight>
 
</syntaxhighlight>
  
6. Create interface WeatherInterface.
+
3. Create interface WeatherInterface.java
 
<syntaxhighlight lang="java">
 
<syntaxhighlight lang="java">
 
package ecl.team2.project.weather;
 
package ecl.team2.project.weather;
Line 40: Line 43:
 
WeatherAndCurrent getWeather(String city) throws Exception;
 
WeatherAndCurrent getWeather(String city) throws Exception;
 
     ArrayList<Location> getCity (String city) throws Exception;
 
     ArrayList<Location> getCity (String city) throws Exception;
 +
}
 +
</syntaxhighlight>
 +
 +
4. Create WeatherAndCurrent.java
 +
 +
<syntaxhighlight lang="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;
 
}
 
}
 
</syntaxhighlight>
 
</syntaxhighlight>

Revision as of 16:52, 16 April 2011

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;
}