diff options
Diffstat (limited to 'framework/bundles/org.eclipse.ecf.identity')
5 files changed, 139 insertions, 88 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; } |