1 package $packageName$; 2 3 import org.osgi.framework.BundleActivator; 4 import org.osgi.framework.BundleContext; 5 import org.osgi.util.tracker.ServiceTracker; 6 import org.osgi.service.prefs.PreferencesService; 7 import org.osgi.service.prefs.Preferences; 8 9 public class $activator$ implements BundleActivator { 10 11 private ServiceTracker tracker; 12 private PreferencesService service; 13 private static final String COLOR = "color"; 15 19 public void start(BundleContext context) throws Exception { 20 tracker = new ServiceTracker(context, PreferencesService.class.getName(), null); 21 tracker.open(); 22 23 service = (PreferencesService) tracker.getService(); 25 Preferences preferences = service.getSystemPreferences(); 26 27 preferences.put(COLOR, "$color$"); 28 29 System.out.println("My favourite color is: " + preferences.get(COLOR, "")); 30 } 31 32 36 public void stop(BundleContext context) throws Exception { 37 tracker.close(); 39 tracker = null; 40 41 service = null; 42 } 43 44 } 45 | Popular Tags |