Open main menu

CDOT Wiki β

Changes

Teams Winter 2011/team2/lab2

4,326 bytes added, 21:57, 17 February 2011
no edit summary
*click on the ecl.... package and click okay
[[File:Mani2T2.png]]
*Now close the manifest and save all changes
 
==Creating and Setting the Provide Bundle==
*Follow the same steps for creating a new plug-in projects but instead supply the name "ecl.team2.lab2.weathersystem.provider"
*Remove all contents within the src->current package and add a class file called "ProviderActivator"
*Add a new package to the current project we're dealing with and name it "ecl.team2.lab2.weathersystem.provider.internal" and within it create a class called "SimpleWeatherSystem"
*Copy and paste the following code to their respective file
'''ProviderActivator'''
<pre>
package ecl.team2.lab2.weathersystem.provider;
 
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
 
import ecl.team2.lab2.weather.WeatherSystem;
import ecl.team2.lab2.weathersystem.provider.internal.SimpleWeatherSystem;
 
public class ProviderActivator implements BundleActivator {
 
private static BundleContext context;
 
static BundleContext getContext() {
return context;
}
 
/*
* (non-Javadoc)
* @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext)
*/
public void start(BundleContext bundleContext) throws Exception {
ProviderActivator.context = bundleContext;
SimpleWeatherSystem sws = new SimpleWeatherSystem();
context.registerService(WeatherSystem.class.getName(), sws, null);
System.out.println("Weather Station On !");
}
 
/*
* (non-Javadoc)
* @see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext)
*/
public void stop(BundleContext bundleContext) throws Exception {
ProviderActivator.context = null;
System.out.println("Weather Station Off !");
}
 
}
</pre>
'''SimpleWeatherSystem'''
<pre>
package ecl.team2.lab2.weathersystem.provider.internal;
 
import ecl.team2.lab2.weather.WeatherSystem;
import ecl.team2.lab2.weather.Weather;
import java.util.ArrayList;
import java.util.Random;
 
 
public class SimpleWeatherSystem implements WeatherSystem {
ArrayList<Weather> weathers = new ArrayList<Weather>();
public SimpleWeatherSystem(){
ArrayList<String> cities = new ArrayList<String>();
cities.add("Toronto");
cities.add("New York");
cities.add("Calgary");
cities.add("Ottawa");
cities.add("Vancouver");
cities.add("Regina");
cities.add("Winnipeg");
cities.add("St. John");
cities.add("Fredericton");
cities.add("Halifax");
cities.add("Quebec City");
cities.add("Whitehorse");
cities.add("Yellowknife");
for(String c:cities){
Random randomGenerator = new Random();
float temp = randomGenerator.nextFloat()+35;
float rain = randomGenerator.nextFloat()+10;
float snow = randomGenerator.nextFloat()+10;
float windspeed = randomGenerator.nextFloat()+50;
char winddirection = '.';
int r = randomGenerator.nextInt(4);
switch(r){
case 0:
winddirection = 'E';
break;
case 1:
winddirection = 'W';
break;
case 2:
winddirection = 'N';
break;
case 3:
winddirection = 'S';
break;
}
Weather w = new Weather(c, temp, rain, snow, windspeed, winddirection);
this.weathers.add(w);
System.out.println(w.toString());
}
}
public Weather getWeather(String city) throws Exception {
// TODO Auto-generated method stub
Weather found = null;
for(Weather w:this.weathers){
city = city.toLowerCase();
String wcity =w.getCity().toLowerCase();
if(city.equals(wcity)){
found = w;
return found;
}
}
return found;
}
 
}
</pre>
**Save and close both files and now open the manifest file
*Click on the dependencies tab then click on add in the "import packages" panel.
*In the search field, enter "ecl", then click on "ecl.team2.lab2.weather", and afterwords click okay
[[File:Manifest3T2.png]]
=INCOMPLETE, WILL FINISH BY TOMORROW=
1
edit