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 /framework/bundles/org.eclipse.ecf.identity/src
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
Diffstat (limited to 'framework/bundles/org.eclipse.ecf.identity/src')
-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
4 files changed, 136 insertions, 85 deletions
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;
}

Back to the top