Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDJ Houghton2006-01-12 16:00:43 -0500
committerDJ Houghton2006-01-12 16:00:43 -0500
commit2c493bafb995cdcbe29eba329cd38ba1dc9b42c7 (patch)
tree97c321c5a659724441663ddbc77e0ee87d868795
parent227ba024e2ac043be212c22a719fae92a7b2b445 (diff)
downloadrt.equinox.bundles-2c493bafb995cdcbe29eba329cd38ba1dc9b42c7.tar.gz
rt.equinox.bundles-2c493bafb995cdcbe29eba329cd38ba1dc9b42c7.tar.xz
rt.equinox.bundles-2c493bafb995cdcbe29eba329cd38ba1dc9b42c7.zip
Bug 117418 - NPE in preferences
-rw-r--r--bundles/org.eclipse.equinox.preferences/src/org/eclipse/core/internal/preferences/Activator.java42
1 files changed, 34 insertions, 8 deletions
diff --git a/bundles/org.eclipse.equinox.preferences/src/org/eclipse/core/internal/preferences/Activator.java b/bundles/org.eclipse.equinox.preferences/src/org/eclipse/core/internal/preferences/Activator.java
index f69e53d1..2b897e6a 100644
--- a/bundles/org.eclipse.equinox.preferences/src/org/eclipse/core/internal/preferences/Activator.java
+++ b/bundles/org.eclipse.equinox.preferences/src/org/eclipse/core/internal/preferences/Activator.java
@@ -11,19 +11,27 @@
package org.eclipse.core.internal.preferences;
import java.util.Hashtable;
+
import org.eclipse.core.runtime.preferences.IPreferencesService;
import org.eclipse.osgi.service.environment.EnvironmentInfo;
import org.osgi.framework.*;
import org.osgi.util.tracker.ServiceTracker;
+import org.osgi.util.tracker.ServiceTrackerCustomizer;
/**
* The Jobs plugin class.
*/
-public class Activator implements BundleActivator {
+public class Activator implements BundleActivator, ServiceTrackerCustomizer {
private static final String OSGI_PREFERENCES_SERVICE = "org.osgi.service.prefs.PreferencesService"; //$NON-NLS-1$
/**
+ * Track the registry service - only register preference service if the registry is
+ * available
+ */
+ private ServiceTracker registryServiceTracker;
+
+ /**
* The bundle associated this plug-in
*/
private static BundleContext bundleContext;
@@ -44,14 +52,16 @@ public class Activator implements BundleActivator {
public void start(BundleContext context) throws Exception {
bundleContext = context;
processCommandLine();
- registerServices();
+ registryServiceTracker = new ServiceTracker(context,"org.eclipse.equinox.registry.IExtensionRegistry",this);
+ registryServiceTracker.open();
}
/**
* This method is called when the plug-in is stopped
*/
public void stop(BundleContext context) throws Exception {
- unregisterServices();
+ registryServiceTracker.close(); //unregisters services
+ registryServiceTracker = null;
PreferencesOSGiUtils.getDefault().closeServices();
bundleContext = null;
}
@@ -65,10 +75,27 @@ public class Activator implements BundleActivator {
osgiPreferencesService = bundleContext.registerService(OSGI_PREFERENCES_SERVICE, new OSGiPreferencesServiceManager(bundleContext), null);
}
- private void unregisterServices() {
- preferencesService.unregister();
- osgiPreferencesService.unregister();
-
+ public synchronized Object addingService(ServiceReference reference) {
+ if (preferencesService == null) {
+ registerServices();
+ //return the registry service so we track it
+ return bundleContext.getService(reference);
+ }
+ return null;
+ }
+
+ public void modifiedService(ServiceReference reference, Object service) {
+ }
+
+ public synchronized void removedService(ServiceReference reference, Object service) {
+ if (preferencesService != null) {
+ preferencesService.unregister();
+ preferencesService = null;
+ }
+ if (osgiPreferencesService != null) {
+ osgiPreferencesService.unregister();
+ osgiPreferencesService = null;
+ }
}
/**
@@ -94,5 +121,4 @@ public class Activator implements BundleActivator {
}
}
}
-
}

Back to the top