Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorslewis2014-01-25 16:24:13 -0500
committerslewis2014-01-25 16:24:13 -0500
commit467e7f2cb6a658d8784e9616e793dc3c5a1e8b68 (patch)
tree06a1edf16ee0e61f64f1e1f1b3a9028b5367e432
parentcf4ef0bacdd290b2f9e3be6660b696f8fb9fa46f (diff)
downloadorg.eclipse.ecf-467e7f2cb6a658d8784e9616e793dc3c5a1e8b68.tar.gz
org.eclipse.ecf-467e7f2cb6a658d8784e9616e793dc3c5a1e8b68.tar.xz
org.eclipse.ecf-467e7f2cb6a658d8784e9616e793dc3c5a1e8b68.zip
Additions and changes to implement changes specified in bug 421569.
Summary: Added OperationCodeSafeRunnable class (implements ISafeRunnable). This class can be used to isolate code that depends upon the extension registry (IExtensionRegistry, IRegistryChangeListener, etc). Added use of this new class to allow org.eclipse.ecf.identiy, and org.eclipse.ecf bundles to optionally depend upon the extension registry. Also added new 'Namespace' ServiceTracker, so that Namespaces can use the OSGI service whiteboard pattern to make ID creation available via the ECF IDFactory. Also added 'ecf.namespace' capability (see Provide-Capability declaration in org.eclipse.ecf.identity manifest). Added new ContainerTypeDescription ServiceTracker in org.eclipse.ecf, so that new ContainerFactories for new container types can be made available via the ECF IContainerFactory. Also added 'ecf.containertype' capability (see Provide-Capability declaration in org.eclipse.ecf manifest). Made dependency on org.eclipse.equinox.registry *optional* for both the org.eclipse.ecf.identity and the org.eclipse.ecf core bundles. Change-Id: I05ea17fb2cb55bb70d7415b7a2826b436cab34ac
-rw-r--r--framework/bundles/org.eclipse.ecf.identity/META-INF/MANIFEST.MF6
-rw-r--r--framework/bundles/org.eclipse.ecf.identity/src/org/eclipse/ecf/core/identity/IDFactory.java24
-rw-r--r--framework/bundles/org.eclipse.ecf.identity/src/org/eclipse/ecf/core/identity/NamespacePermission.java8
-rw-r--r--framework/bundles/org.eclipse.ecf.identity/src/org/eclipse/ecf/core/util/OptionalCodeSafeRunnable.java21
-rw-r--r--framework/bundles/org.eclipse.ecf.identity/src/org/eclipse/ecf/internal/core/identity/Activator.java168
-rw-r--r--framework/bundles/org.eclipse.ecf/META-INF/MANIFEST.MF5
-rw-r--r--framework/bundles/org.eclipse.ecf/src/org/eclipse/ecf/internal/core/ECFPlugin.java142
7 files changed, 237 insertions, 137 deletions
diff --git a/framework/bundles/org.eclipse.ecf.identity/META-INF/MANIFEST.MF b/framework/bundles/org.eclipse.ecf.identity/META-INF/MANIFEST.MF
index f840729f2..e8283316e 100644
--- a/framework/bundles/org.eclipse.ecf.identity/META-INF/MANIFEST.MF
+++ b/framework/bundles/org.eclipse.ecf.identity/META-INF/MANIFEST.MF
@@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %plugin.name
Bundle-SymbolicName: org.eclipse.ecf.identity;singleton:=true
-Bundle-Version: 3.2.0.qualifier
+Bundle-Version: 3.3.0.qualifier
Bundle-Activator: org.eclipse.ecf.internal.core.identity.Activator
Bundle-Localization: plugin
Bundle-Vendor: %plugin.provider
@@ -17,6 +17,6 @@ Import-Package: org.eclipse.osgi.service.debug;version="1.0.0",
org.osgi.service.log;version="1.3.0",
org.osgi.util.tracker;version="1.3.2"
Require-Bundle: org.eclipse.equinox.common,
- org.eclipse.equinox.registry
+ org.eclipse.equinox.registry;resolution:=optional
Bundle-ActivationPolicy: lazy; exclude:="org.eclipse.ecf.core.util"
-
+Provide-Capability: ecf.namespace;names:List<String>=”org.eclipse.ecf.core.identity.StringID,org.eclipse.ecf.core.identity.GUID,org.eclipse.ecf.core.identity.LongID,org.eclipse.ecf.core.identity.URIID”; version:Version=3.3
diff --git a/framework/bundles/org.eclipse.ecf.identity/src/org/eclipse/ecf/core/identity/IDFactory.java b/framework/bundles/org.eclipse.ecf.identity/src/org/eclipse/ecf/core/identity/IDFactory.java
index 7bbadf36a..8ba5747c5 100644
--- a/framework/bundles/org.eclipse.ecf.identity/src/org/eclipse/ecf/core/identity/IDFactory.java
+++ b/framework/bundles/org.eclipse.ecf.identity/src/org/eclipse/ecf/core/identity/IDFactory.java
@@ -8,7 +8,6 @@
******************************************************************************/
package org.eclipse.ecf.core.identity;
-import java.security.AccessController;
import java.util.*;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
@@ -23,12 +22,8 @@ public class IDFactory implements IIDFactory {
public static final String SECURITY_PROPERTY = IDFactory.class.getName()
+ ".security"; //$NON-NLS-1$
- private static final int IDENTITY_CREATION_ERRORCODE = 2001;
-
private static Hashtable namespaces = new Hashtable();
- private static boolean securityEnabled = false;
-
protected static IIDFactory instance = null;
static {
@@ -67,8 +62,6 @@ public class IDFactory implements IIDFactory {
public Namespace addNamespace(Namespace namespace) throws SecurityException {
if (namespace == null)
return null;
- checkPermission(new NamespacePermission(namespace.toString(),
- NamespacePermission.ADD_NAMESPACE));
initialize();
return addNamespace0(namespace);
}
@@ -81,8 +74,6 @@ public class IDFactory implements IIDFactory {
protected final static void checkPermission(
NamespacePermission namespacepermission) throws SecurityException {
- if (securityEnabled)
- AccessController.checkPermission(namespacepermission);
}
/*
@@ -96,8 +87,6 @@ public class IDFactory implements IIDFactory {
throws SecurityException {
if (namespace == null)
return false;
- checkPermission(new NamespacePermission(namespace.toString(),
- NamespacePermission.CONTAINS_NAMESPACE));
initialize();
return containsNamespace0(namespace);
}
@@ -128,8 +117,6 @@ public class IDFactory implements IIDFactory {
public Namespace getNamespace(Namespace namespace) throws SecurityException {
if (namespace == null)
return null;
- checkPermission(new NamespacePermission(namespace.toString(),
- NamespacePermission.GET_NAMESPACE));
initialize();
return getNamespace0(namespace);
}
@@ -187,8 +174,8 @@ public class IDFactory implements IIDFactory {
e = new IDCreateException(s);
}
Activator.getDefault().log(
- new Status(IStatus.ERROR, Activator.PLUGIN_ID,
- IDENTITY_CREATION_ERRORCODE, s, e));
+ new Status(IStatus.ERROR, Activator.PLUGIN_ID, IStatus.ERROR,
+ s, e));
throw e;
}
@@ -268,13 +255,14 @@ public class IDFactory implements IIDFactory {
public Namespace removeNamespace(Namespace n) throws SecurityException {
if (n == null)
return null;
- checkPermission(new NamespacePermission(n.toString(),
- NamespacePermission.REMOVE_NAMESPACE));
initialize();
return removeNamespace0(n);
}
- protected final static Namespace removeNamespace0(Namespace n) {
+ /**
+ * @since 3.3
+ */
+ public final static Namespace removeNamespace0(Namespace n) {
if (n == null)
return null;
return (Namespace) namespaces.remove(n.getName());
diff --git a/framework/bundles/org.eclipse.ecf.identity/src/org/eclipse/ecf/core/identity/NamespacePermission.java b/framework/bundles/org.eclipse.ecf.identity/src/org/eclipse/ecf/core/identity/NamespacePermission.java
index 13133a6f5..2053d1e14 100644
--- a/framework/bundles/org.eclipse.ecf.identity/src/org/eclipse/ecf/core/identity/NamespacePermission.java
+++ b/framework/bundles/org.eclipse.ecf.identity/src/org/eclipse/ecf/core/identity/NamespacePermission.java
@@ -40,14 +40,6 @@ public class NamespacePermission extends BasicPermission {
}
public boolean implies(Permission p) {
- if ((p == null) || (p.getClass() != getClass()))
- return false;
- NamespacePermission np = (NamespacePermission) p;
- String act = getActions();
- if (act == null)
- return false;
- if (act.equals(ALL_NAMESPACE) || act.equals(np.getActions()))
- return true;
return false;
}
} \ No newline at end of file
diff --git a/framework/bundles/org.eclipse.ecf.identity/src/org/eclipse/ecf/core/util/OptionalCodeSafeRunnable.java b/framework/bundles/org.eclipse.ecf.identity/src/org/eclipse/ecf/core/util/OptionalCodeSafeRunnable.java
new file mode 100644
index 000000000..463eb2bee
--- /dev/null
+++ b/framework/bundles/org.eclipse.ecf.identity/src/org/eclipse/ecf/core/util/OptionalCodeSafeRunnable.java
@@ -0,0 +1,21 @@
+package org.eclipse.ecf.core.util;
+
+import org.eclipse.core.runtime.*;
+import org.eclipse.ecf.internal.core.identity.Activator;
+
+/**
+ * @since 3.3
+ */
+public abstract class OptionalCodeSafeRunnable implements ISafeRunnable {
+
+ public void handleException(Throwable exception) {
+ Activator a = Activator.getDefault();
+ if (a != null)
+ a.log(new Status(IStatus.WARNING, Activator.PLUGIN_ID,
+ IStatus.WARNING,
+ "Warning: optional code cannot be run", exception)); //$NON-NLS-1$
+ }
+
+ public abstract void run() throws Exception;
+
+}
diff --git a/framework/bundles/org.eclipse.ecf.identity/src/org/eclipse/ecf/internal/core/identity/Activator.java b/framework/bundles/org.eclipse.ecf.identity/src/org/eclipse/ecf/internal/core/identity/Activator.java
index 0b186c026..b4973022a 100644
--- a/framework/bundles/org.eclipse.ecf.identity/src/org/eclipse/ecf/internal/core/identity/Activator.java
+++ b/framework/bundles/org.eclipse.ecf.identity/src/org/eclipse/ecf/internal/core/identity/Activator.java
@@ -15,6 +15,7 @@ import org.eclipse.osgi.service.debug.DebugOptions;
import org.osgi.framework.*;
import org.osgi.service.log.LogService;
import org.osgi.util.tracker.ServiceTracker;
+import org.osgi.util.tracker.ServiceTrackerCustomizer;
/**
* The activator class controls the plug-in life cycle
@@ -24,39 +25,39 @@ public class Activator implements BundleActivator {
// The plug-in ID
public static final String PLUGIN_ID = "org.eclipse.ecf.identity"; //$NON-NLS-1$
- protected static final String NAMESPACE_NAME = "namespace"; //$NON-NLS-1$
+ private static final String NAMESPACE_NAME = "namespace"; //$NON-NLS-1$
- protected static final String NAMESPACE_EPOINT = PLUGIN_ID + "." //$NON-NLS-1$
+ private static final String NAMESPACE_EPOINT = PLUGIN_ID + "." //$NON-NLS-1$
+ NAMESPACE_NAME;
- protected static final String NAME_ATTRIBUTE = "name"; //$NON-NLS-1$
+ private static final String NAME_ATTRIBUTE = "name"; //$NON-NLS-1$
- protected static final String CLASS_ATTRIBUTE = "class"; //$NON-NLS-1$
+ private static final String CLASS_ATTRIBUTE = "class"; //$NON-NLS-1$
- protected static final int REMOVE_NAMESPACE_ERRORCODE = 100;
+ private static final int FACTORY_NAME_COLLISION_ERRORCODE = 200;
- protected static final int FACTORY_NAME_COLLISION_ERRORCODE = 200;
-
- protected static final String DESCRIPTION_ATTRIBUTE = "description"; //$NON-NLS-1$
+ private static final String DESCRIPTION_ATTRIBUTE = "description"; //$NON-NLS-1$
// The shared instance
private static Activator plugin;
- private BundleContext context = null;
+ private BundleContext context;
- private IRegistryChangeListener registryManager = null;
+ private ServiceRegistration idFactoryServiceRegistration;
- private ServiceRegistration idFactoryServiceRegistration = null;
+ private ServiceTracker extensionRegistryTracker;
- private ServiceTracker extensionRegistryTracker = null;
+ private ServiceTracker debugOptionsTracker;
- private ServiceTracker debugOptionsTracker = null;
+ private ServiceTracker logServiceTracker;
- private ServiceTracker logServiceTracker = null;
+ private LogService logService;
- private LogService logService = null;
+ private ServiceTracker adapterManagerTracker;
- private ServiceTracker adapterManagerTracker = null;
+ // This is object rather than typed to avoid referencing the
+ // IRegistryChangedListener class directly
+ private Object registryManager;
public synchronized IAdapterManager getAdapterManager() {
if (this.context == null)
@@ -87,7 +88,7 @@ public class Activator implements BundleActivator {
// public null constructor
}
- public synchronized IExtensionRegistry getExtensionRegistry() {
+ synchronized IExtensionRegistry getExtensionRegistry() {
if (this.context == null)
return null;
if (extensionRegistryTracker == null) {
@@ -122,43 +123,48 @@ public class Activator implements BundleActivator {
idFactoryServiceRegistration = context.registerService(
IIDFactory.class.getName(), IDFactory.getDefault(), null);
- final IExtensionRegistry reg = getExtensionRegistry();
- if (reg != null) {
- this.registryManager = new IdentityRegistryManager();
- reg.addRegistryChangeListener(registryManager);
- }
+ SafeRunner.run(new OptionalCodeSafeRunnable() {
+ public void run() throws Exception {
+ final IExtensionRegistry reg = getExtensionRegistry();
+ if (reg != null) {
+ registryManager = new IRegistryChangeListener() {
+ public void registryChanged(IRegistryChangeEvent event) {
+ final IExtensionDelta delta[] = event
+ .getExtensionDeltas(PLUGIN_ID,
+ NAMESPACE_NAME);
+ for (int i = 0; i < delta.length; i++) {
+ switch (delta[i].getKind()) {
+ case IExtensionDelta.ADDED:
+ addNamespaceExtensions(delta[i]
+ .getExtension()
+ .getConfigurationElements());
+ break;
+ case IExtensionDelta.REMOVED:
+ removeNamespaceExtensions(delta[i]
+ .getExtension()
+ .getConfigurationElements());
+ break;
+ }
+ }
+ }
+ };
+ reg.addRegistryChangeListener((IRegistryChangeListener) registryManager);
+ }
+ }
+ });
}
public BundleContext getBundleContext() {
return context;
}
- protected class IdentityRegistryManager implements IRegistryChangeListener {
- public void registryChanged(IRegistryChangeEvent event) {
- final IExtensionDelta delta[] = event.getExtensionDeltas(PLUGIN_ID,
- NAMESPACE_NAME);
- for (int i = 0; i < delta.length; i++) {
- switch (delta[i].getKind()) {
- case IExtensionDelta.ADDED:
- addNamespaceExtensions(delta[i].getExtension()
- .getConfigurationElements());
- break;
- case IExtensionDelta.REMOVED:
- removeNamespaceExtensions(delta[i].getExtension()
- .getConfigurationElements());
- break;
- }
- }
- }
- }
-
/**
* Remove extensions for identity namespace extension point
*
* @param members
* the members to remove
*/
- protected void removeNamespaceExtensions(IConfigurationElement[] members) {
+ void removeNamespaceExtensions(IConfigurationElement[] members) {
for (int m = 0; m < members.length; m++) {
final IConfigurationElement member = members[m];
String name = null;
@@ -179,19 +185,19 @@ public class Activator implements BundleActivator {
} catch (final Exception e) {
getDefault().log(
new Status(IStatus.ERROR, Activator.PLUGIN_ID,
- REMOVE_NAMESPACE_ERRORCODE,
+ IStatus.ERROR,
"Exception removing namespace", e)); //$NON-NLS-1$
}
}
}
- public Bundle getBundle() {
+ Bundle getBundle() {
if (context == null)
return null;
return context.getBundle();
}
- protected synchronized LogService getLogService() {
+ synchronized LogService getLogService() {
if (context == null) {
if (logService == null)
logService = new SystemLogService(PLUGIN_ID);
@@ -223,7 +229,7 @@ public class Activator implements BundleActivator {
* @param members
* the members to add
*/
- protected void addNamespaceExtensions(IConfigurationElement[] members) {
+ void addNamespaceExtensions(IConfigurationElement[] members) {
final String bundleName = getDefault().getBundle().getSymbolicName();
for (int m = 0; m < members.length; m++) {
final IConfigurationElement member = members[m];
@@ -270,15 +276,51 @@ public class Activator implements BundleActivator {
*
*/
public void setupNamespaceExtensionPoint() {
- // Process extension points
- final IExtensionRegistry reg = getExtensionRegistry();
- if (reg != null) {
- final IExtensionPoint extensionPoint = reg
- .getExtensionPoint(NAMESPACE_EPOINT);
- if (extensionPoint == null) {
- return;
+ if (context != null)
+ setupNamespaceServices();
+ SafeRunner.run(new OptionalCodeSafeRunnable() {
+ public void run() throws Exception {
+ // Process extension points
+ final IExtensionRegistry reg = getExtensionRegistry();
+ if (reg != null) {
+ final IExtensionPoint extensionPoint = reg
+ .getExtensionPoint(NAMESPACE_EPOINT);
+ if (extensionPoint == null)
+ return;
+ addNamespaceExtensions(extensionPoint
+ .getConfigurationElements());
+ }
}
- addNamespaceExtensions(extensionPoint.getConfigurationElements());
+ });
+ }
+
+ private ServiceTracker namespacesTracker;
+
+ private void setupNamespaceServices() {
+ if (namespacesTracker == null) {
+ namespacesTracker = new ServiceTracker(context,
+ Namespace.class.getName(), new ServiceTrackerCustomizer() {
+
+ public Object addingService(ServiceReference reference) {
+ Namespace ns = (Namespace) context
+ .getService(reference);
+ if (ns != null) {
+ IDFactory.addNamespace0(ns);
+ return ns;
+ }
+ return null;
+ }
+
+ public void modifiedService(ServiceReference reference,
+ Object service) {
+ }
+
+ public void removedService(ServiceReference reference,
+ Object service) {
+ IDFactory.removeNamespace0((Namespace) service);
+ }
+ });
+ namespacesTracker.open();
}
}
@@ -289,9 +331,18 @@ public class Activator implements BundleActivator {
* org.eclipse.core.runtime.Plugin#stop(org.osgi.framework.BundleContext)
*/
public void stop(BundleContext ctxt) throws Exception {
- final IExtensionRegistry reg = getExtensionRegistry();
- if (reg != null)
- reg.removeRegistryChangeListener(registryManager);
+ SafeRunner.run(new OptionalCodeSafeRunnable() {
+ public void run() throws Exception {
+ final IExtensionRegistry reg = getExtensionRegistry();
+ if (reg != null)
+ reg.removeRegistryChangeListener((IRegistryChangeListener) registryManager);
+ }
+ });
+
+ if (namespacesTracker != null) {
+ namespacesTracker.close();
+ namespacesTracker = null;
+ }
registryManager = null;
if (logServiceTracker != null) {
logServiceTracker.close();
@@ -324,9 +375,8 @@ public class Activator implements BundleActivator {
* @return the shared instance
*/
public synchronized static Activator getDefault() {
- if (plugin == null) {
+ if (plugin == null)
plugin = new Activator();
- }
return plugin;
}
diff --git a/framework/bundles/org.eclipse.ecf/META-INF/MANIFEST.MF b/framework/bundles/org.eclipse.ecf/META-INF/MANIFEST.MF
index 45fb08bd7..9ed9b7700 100644
--- a/framework/bundles/org.eclipse.ecf/META-INF/MANIFEST.MF
+++ b/framework/bundles/org.eclipse.ecf/META-INF/MANIFEST.MF
@@ -1,7 +1,7 @@
Manifest-Version: 1.0
Bundle-Name: %plugin.name
Bundle-SymbolicName: org.eclipse.ecf;singleton:=true
-Bundle-Version: 3.2.0.qualifier
+Bundle-Version: 3.3.0.qualifier
Bundle-Activator: org.eclipse.ecf.internal.core.ECFPlugin
Bundle-Vendor: %plugin.provider
Bundle-Localization: plugin
@@ -25,6 +25,7 @@ Import-Package: org.eclipse.core.runtime.jobs,
org.osgi.service.log;version="1.3.0",
org.osgi.util.tracker;version="1.3.2"
Require-Bundle: org.eclipse.equinox.common,
- org.eclipse.equinox.registry,
+ org.eclipse.equinox.registry;resolution:=optional,
org.eclipse.ecf.identity;visibility:=reexport
Bundle-ActivationPolicy: lazy
+Provide-Capability: ecf.containertype;names:List<String>=”ecf.base”; version:Version=3.3
diff --git a/framework/bundles/org.eclipse.ecf/src/org/eclipse/ecf/internal/core/ECFPlugin.java b/framework/bundles/org.eclipse.ecf/src/org/eclipse/ecf/internal/core/ECFPlugin.java
index c36c03063..7fa4fc59a 100644
--- a/framework/bundles/org.eclipse.ecf/src/org/eclipse/ecf/internal/core/ECFPlugin.java
+++ b/framework/bundles/org.eclipse.ecf/src/org/eclipse/ecf/internal/core/ECFPlugin.java
@@ -19,6 +19,7 @@ import org.eclipse.ecf.internal.core.identity.Activator;
import org.osgi.framework.*;
import org.osgi.service.log.LogService;
import org.osgi.util.tracker.ServiceTracker;
+import org.osgi.util.tracker.ServiceTrackerCustomizer;
public class ECFPlugin implements BundleActivator {
@@ -67,13 +68,15 @@ public class ECFPlugin implements BundleActivator {
// The shared instance.
private static ECFPlugin plugin;
- private BundleContext context = null;
+ BundleContext context = null;
- private ServiceTracker extensionRegistryTracker = null;
+ ServiceTracker extensionRegistryTracker = null;
private Map disposables = new WeakHashMap();
- private IRegistryChangeListener registryManager = null;
+ // This is Object rather than IExtensionRegistryManager to avoid loading
+ // IRegistryChangeListener class (optional)
+ Object registryManager = null;
private ServiceRegistration containerFactoryServiceRegistration;
@@ -92,9 +95,8 @@ public class ECFPlugin implements BundleActivator {
* @return ECFPlugin
*/
public synchronized static ECFPlugin getDefault() {
- if (plugin == null) {
+ if (plugin == null)
plugin = new ECFPlugin();
- }
return plugin;
}
@@ -117,13 +119,42 @@ public class ECFPlugin implements BundleActivator {
log(new Status(IStatus.ERROR, getDefault().getBundle().getSymbolicName(), "Unexpected Error in ECFPlugin.start", t)); //$NON-NLS-1$
}
- this.extensionRegistryTracker = new ServiceTracker(ctxt, IExtensionRegistry.class.getName(), null);
- this.extensionRegistryTracker.open();
- final IExtensionRegistry registry = getExtensionRegistry();
- if (registry != null) {
- this.registryManager = new ECFRegistryManager();
- registry.addRegistryChangeListener(registryManager);
- }
+ SafeRunner.run(new OptionalCodeSafeRunnable() {
+ public void run() throws Exception {
+ extensionRegistryTracker = new ServiceTracker(context, IExtensionRegistry.class.getName(), null);
+ extensionRegistryTracker.open();
+ final IExtensionRegistry registry = getExtensionRegistry();
+ if (registry != null) {
+ registryManager = new IRegistryChangeListener() {
+ public void registryChanged(IRegistryChangeEvent event) {
+ final IExtensionDelta factoryDeltas[] = event.getExtensionDeltas(ECFNAMESPACE, CONTAINER_FACTORY_NAME);
+ for (int i = 0; i < factoryDeltas.length; i++) {
+ switch (factoryDeltas[i].getKind()) {
+ case IExtensionDelta.ADDED :
+ addContainerFactoryExtensions(factoryDeltas[i].getExtension().getConfigurationElements());
+ break;
+ case IExtensionDelta.REMOVED :
+ removeContainerFactoryExtensions(factoryDeltas[i].getExtension().getConfigurationElements());
+ break;
+ }
+ }
+ final IExtensionDelta containerDeltas[] = event.getExtensionDeltas(ECFNAMESPACE, CONTAINER_NAME);
+ for (int i = 0; i < containerDeltas.length; i++) {
+ switch (containerDeltas[i].getKind()) {
+ case IExtensionDelta.ADDED :
+ addContainerExtensions(containerDeltas[i].getExtension().getConfigurationElements());
+ break;
+ case IExtensionDelta.REMOVED :
+ removeContainerExtensions(containerDeltas[i].getExtension().getConfigurationElements());
+ break;
+ }
+ }
+ }
+ };
+ registry.addRegistryChangeListener((IRegistryChangeListener) registryManager);
+ }
+ }
+ });
// defer extension execution until first consumer calls
final ServiceFactory sf = new ServiceFactory() {
@@ -135,25 +166,69 @@ public class ECFPlugin implements BundleActivator {
// NOP
}
};
+
containerFactoryServiceRegistration = ctxt.registerService(IContainerFactory.class.getName(), sf, null);
containerManagerServiceRegistration = ctxt.registerService(IContainerManager.class.getName(), sf, null);
- // but eagerly start ECF startup extension
- setupStartExtensionPoint(context);
+ SafeRunner.run(new OptionalCodeSafeRunnable() {
+ public void run() throws Exception {
+ // but eagerly start ECF startup extension
+ setupStartExtensionPoint(context);
+ }
+ });
}
+ private ServiceTracker containerTypeDescriptionTracker;
+
public void initializeExtensions() {
- setupContainerFactoryExtensionPoint(context);
- setupContainerExtensionPoint(context);
+ // initialize from ContainerTypeDescription services
+ if (containerTypeDescriptionTracker == null) {
+ containerTypeDescriptionTracker = new ServiceTracker(this.context, ContainerTypeDescription.class.getName(), new ServiceTrackerCustomizer() {
+ public Object addingService(ServiceReference reference) {
+ ContainerTypeDescription ctd = (ContainerTypeDescription) context.getService(reference);
+ if (ctd != null) {
+ IContainerFactory cf = ContainerFactory.getDefault();
+ cf.addDescription(ctd);
+ return ctd;
+ }
+ return null;
+ }
+
+ public void modifiedService(ServiceReference reference, Object service) {
+ // nothing
+ }
+
+ public void removedService(ServiceReference reference, Object service) {
+ IContainerFactory cf = ContainerFactory.getDefault();
+ cf.removeDescription((ContainerTypeDescription) service);
+ }
+ });
+ containerTypeDescriptionTracker.open();
+ }
+ // Initialize from extension registry (if one exists)
+ SafeRunner.run(new OptionalCodeSafeRunnable() {
+ public void run() throws Exception {
+ setupContainerFactoryExtensionPoint(context);
+ setupContainerExtensionPoint(context);
+ }
+ });
}
public void stop(BundleContext ctxt) throws Exception {
fireDisposables();
this.disposables = null;
- final IExtensionRegistry reg = getExtensionRegistry();
- if (reg != null)
- reg.removeRegistryChangeListener(registryManager);
+ SafeRunner.run(new OptionalCodeSafeRunnable() {
+ public void run() throws Exception {
+ final IExtensionRegistry reg = getExtensionRegistry();
+ if (reg != null)
+ reg.removeRegistryChangeListener((IRegistryChangeListener) registryManager);
+ }
+ });
this.registryManager = null;
+ if (containerTypeDescriptionTracker != null) {
+ containerTypeDescriptionTracker.close();
+ containerTypeDescriptionTracker = null;
+ }
if (ecfTrustManager != null) {
ecfTrustManager.stop(ctxt);
ecfTrustManager = null;
@@ -451,7 +526,7 @@ public class ECFPlugin implements BundleActivator {
* @param bc
* the BundleContext for this bundle
*/
- protected void setupStartExtensionPoint(BundleContext bc) {
+ void setupStartExtensionPoint(BundleContext bc) {
final IExtensionRegistry reg = getExtensionRegistry();
if (reg != null) {
final IExtensionPoint extensionPoint = reg.getExtensionPoint(START_EPOINT);
@@ -498,33 +573,6 @@ public class ECFPlugin implements BundleActivator {
}
}
- protected class ECFRegistryManager implements IRegistryChangeListener {
- public void registryChanged(IRegistryChangeEvent event) {
- final IExtensionDelta factoryDeltas[] = event.getExtensionDeltas(ECFNAMESPACE, CONTAINER_FACTORY_NAME);
- for (int i = 0; i < factoryDeltas.length; i++) {
- switch (factoryDeltas[i].getKind()) {
- case IExtensionDelta.ADDED :
- addContainerFactoryExtensions(factoryDeltas[i].getExtension().getConfigurationElements());
- break;
- case IExtensionDelta.REMOVED :
- removeContainerFactoryExtensions(factoryDeltas[i].getExtension().getConfigurationElements());
- break;
- }
- }
- final IExtensionDelta containerDeltas[] = event.getExtensionDeltas(ECFNAMESPACE, CONTAINER_NAME);
- for (int i = 0; i < containerDeltas.length; i++) {
- switch (containerDeltas[i].getKind()) {
- case IExtensionDelta.ADDED :
- addContainerExtensions(containerDeltas[i].getExtension().getConfigurationElements());
- break;
- case IExtensionDelta.REMOVED :
- removeContainerExtensions(containerDeltas[i].getExtension().getConfigurationElements());
- break;
- }
- }
- }
- }
-
public IAdapterManager getAdapterManager() {
if (context == null)
return null;

Back to the top