diff options
author | slewis | 2014-03-31 21:40:59 +0000 |
---|---|---|
committer | slewis | 2014-03-31 21:40:59 +0000 |
commit | fe468456cfaab2707823d1587b2782d7086c2bc4 (patch) | |
tree | f98699305c284a2ac12a1c6dbe5e04809bfa6b78 /framework | |
parent | 27f62a65e46f9d1492a7ef0e31206b0465e89377 (diff) | |
parent | 8caf8c2de33df197a3416b48c7bb04efa71aa018 (diff) | |
download | org.eclipse.ecf-fe468456cfaab2707823d1587b2782d7086c2bc4.tar.gz org.eclipse.ecf-fe468456cfaab2707823d1587b2782d7086c2bc4.tar.xz org.eclipse.ecf-fe468456cfaab2707823d1587b2782d7086c2bc4.zip |
Merge remote-tracking branch 'origin/master' into rfc1.1
Conflicts:
examples/bundles/com.mycorp.examples.timeservice.consumer.filediscovery/launch/TimeServiceConsumer.launch
Change-Id: Ib83f0393403af7d629aa6cbffe731b5b251eaf3b
Diffstat (limited to 'framework')
29 files changed, 675 insertions, 496 deletions
diff --git a/framework/bundles/org.eclipse.ecf.discovery/src/org/eclipse/ecf/internal/discovery/DiscoveryNamespace.java b/framework/bundles/org.eclipse.ecf.discovery/src/org/eclipse/ecf/internal/discovery/DiscoveryNamespace.java index 258de6c17..264c95401 100644 --- a/framework/bundles/org.eclipse.ecf.discovery/src/org/eclipse/ecf/internal/discovery/DiscoveryNamespace.java +++ b/framework/bundles/org.eclipse.ecf.discovery/src/org/eclipse/ecf/internal/discovery/DiscoveryNamespace.java @@ -20,6 +20,14 @@ public class DiscoveryNamespace extends Namespace { private static final long serialVersionUID = 6474091408790223505L; public static final String NAME = "ecf.namespace.discovery"; //$NON-NLS-1$ + public DiscoveryNamespace() { + super(); + } + + public DiscoveryNamespace(String description) { + super(NAME, description); + } + /* * (non-Javadoc) * diff --git a/framework/bundles/org.eclipse.ecf.discovery/src/org/eclipse/ecf/internal/discovery/DiscoveryPlugin.java b/framework/bundles/org.eclipse.ecf.discovery/src/org/eclipse/ecf/internal/discovery/DiscoveryPlugin.java index 5cead024a..c6ff207c0 100644 --- a/framework/bundles/org.eclipse.ecf.discovery/src/org/eclipse/ecf/internal/discovery/DiscoveryPlugin.java +++ b/framework/bundles/org.eclipse.ecf.discovery/src/org/eclipse/ecf/internal/discovery/DiscoveryPlugin.java @@ -10,8 +10,8 @@ package org.eclipse.ecf.internal.discovery; import org.eclipse.core.runtime.*; -import org.eclipse.ecf.core.util.LogHelper; -import org.eclipse.ecf.core.util.PlatformHelper; +import org.eclipse.ecf.core.identity.Namespace; +import org.eclipse.ecf.core.util.*; import org.osgi.framework.BundleActivator; import org.osgi.framework.BundleContext; import org.osgi.service.log.LogService; @@ -29,7 +29,7 @@ public class DiscoveryPlugin implements BundleActivator { private BundleContext context; - private ServiceTracker adapterManagerTracker; + private AdapterManagerTracker adapterManagerTracker; private ServiceTracker logServiceTracker = null; /** @@ -43,22 +43,16 @@ public class DiscoveryPlugin implements BundleActivator { public IAdapterManager getAdapterManager() { // First, try to get the adapter manager via if (adapterManagerTracker == null) { - adapterManagerTracker = new ServiceTracker(this.context, IAdapterManager.class.getName(), null); + adapterManagerTracker = new AdapterManagerTracker(this.context); adapterManagerTracker.open(); } - IAdapterManager adapterManager = (IAdapterManager) adapterManagerTracker.getService(); - // Then, if the service isn't there, try to get from Platform class via - // PlatformHelper class - if (adapterManager == null) - adapterManager = PlatformHelper.getPlatformAdapterManager(); - if (adapterManager == null) - getDefault().log(new Status(IStatus.ERROR, PLUGIN_ID, IStatus.ERROR, "Cannot get adapter manager", null)); //$NON-NLS-1$ - return adapterManager; + return adapterManagerTracker.getAdapterManager(); } public LogService getLogService() { if (logServiceTracker == null) { - logServiceTracker = new ServiceTracker(this.context, LogService.class.getName(), null); + logServiceTracker = new ServiceTracker(this.context, + LogService.class.getName(), null); logServiceTracker.open(); } return (LogService) logServiceTracker.getService(); @@ -67,23 +61,34 @@ public class DiscoveryPlugin implements BundleActivator { public void log(IStatus status) { LogService logService = getLogService(); if (logService != null) { - logService.log(LogHelper.getLogCode(status), LogHelper.getLogMessage(status), status.getException()); + logService.log(LogHelper.getLogCode(status), + LogHelper.getLogMessage(status), status.getException()); } } /** * This method is called upon plug-in activation - * @param ctxt the bundle context - * @throws Exception + * + * @param ctxt + * the bundle context + * @throws Exception */ - public void start(BundleContext ctxt) throws Exception { + public void start(final BundleContext ctxt) throws Exception { this.context = ctxt; + SafeRunner.run(new ExtensionRegistryRunnable(this.context) { + protected void runWithoutRegistry() throws Exception { + ctxt.registerService(Namespace.class, new DiscoveryNamespace( + "Discovery Namespace"), null); + } + }); } /** * This method is called when the plug-in is stopped - * @param ctxt the bundle context - * @throws Exception + * + * @param ctxt + * the bundle context + * @throws Exception */ public void stop(BundleContext ctxt) throws Exception { if (logServiceTracker != null) { @@ -100,6 +105,7 @@ public class DiscoveryPlugin implements BundleActivator { /** * Returns the shared instance. + * * @return default discovery plugin instance. */ public synchronized static DiscoveryPlugin getDefault() { @@ -112,7 +118,7 @@ public class DiscoveryPlugin implements BundleActivator { public static boolean isStopped() { return plugin == null; } - + public BundleContext getBundleContext() { return context; } 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..dbd41dee3 100644 --- a/framework/bundles/org.eclipse.ecf.identity/META-INF/MANIFEST.MF +++ b/framework/bundles/org.eclipse.ecf.identity/META-INF/MANIFEST.MF @@ -2,13 +2,13 @@ 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.4.0.qualifier Bundle-Activator: org.eclipse.ecf.internal.core.identity.Activator Bundle-Localization: plugin Bundle-Vendor: %plugin.provider Eclipse-LazyStart: true Export-Package: org.eclipse.ecf.core.identity;version="3.2.0", - org.eclipse.ecf.core.util;version="3.2.0", + org.eclipse.ecf.core.util;version="3.4.0", org.eclipse.ecf.internal.core.identity;version="3.2.0";x-internal:=true Bundle-RequiredExecutionEnvironment: CDC-1.1/Foundation-1.1, J2SE-1.4 @@ -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..d56bd52d6 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.4 + */ + 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/AdapterManagerTracker.java b/framework/bundles/org.eclipse.ecf.identity/src/org/eclipse/ecf/core/util/AdapterManagerTracker.java new file mode 100644 index 000000000..a4346d064 --- /dev/null +++ b/framework/bundles/org.eclipse.ecf.identity/src/org/eclipse/ecf/core/util/AdapterManagerTracker.java @@ -0,0 +1,44 @@ +/******************************************************************************* + * Copyright (c) 2014 Composent, Inc. and others. All rights reserved. This + * program and the accompanying materials are made available under the terms of + * the Eclipse Public License v1.0 which accompanies this distribution, and is + * available at http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: Composent, Inc. - initial API and implementation + ******************************************************************************/ +package org.eclipse.ecf.core.util; + +import org.eclipse.core.runtime.*; +import org.eclipse.ecf.internal.core.identity.Activator; +import org.osgi.framework.BundleContext; +import org.osgi.util.tracker.ServiceTracker; +import org.osgi.util.tracker.ServiceTrackerCustomizer; + +/** + * @since 3.4 + */ +public class AdapterManagerTracker extends ServiceTracker { + + public AdapterManagerTracker(BundleContext context, + ServiceTrackerCustomizer customizer) { + super(context, IAdapterManager.class.getName(), customizer); + } + + public AdapterManagerTracker(BundleContext context) { + this(context, null); + } + + public IAdapterManager getAdapterManager() { + IAdapterManager adapterManager = (IAdapterManager) getService(); + // Then, if the service isn't there, try to get from Platform class via + // PlatformHelper class + if (adapterManager == null) + adapterManager = PlatformHelper.getPlatformAdapterManager(); + if (adapterManager == null) + Activator.getDefault().log( + new Status(IStatus.ERROR, Activator.PLUGIN_ID, + IStatus.ERROR, "Cannot get adapter manager", null)); //$NON-NLS-1$ + return adapterManager; + } + +} diff --git a/framework/bundles/org.eclipse.ecf.identity/src/org/eclipse/ecf/core/util/ExtensionRegistryRunnable.java b/framework/bundles/org.eclipse.ecf.identity/src/org/eclipse/ecf/core/util/ExtensionRegistryRunnable.java new file mode 100644 index 000000000..1264147d5 --- /dev/null +++ b/framework/bundles/org.eclipse.ecf.identity/src/org/eclipse/ecf/core/util/ExtensionRegistryRunnable.java @@ -0,0 +1,66 @@ +/******************************************************************************* + * Copyright (c) 2014 Composent, Inc. and others. All rights reserved. This + * program and the accompanying materials are made available under the terms of + * the Eclipse Public License v1.0 which accompanies this distribution, and is + * available at http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: Composent, Inc. - initial API and implementation + ******************************************************************************/ +package org.eclipse.ecf.core.util; + +import org.eclipse.core.runtime.*; +import org.eclipse.ecf.internal.core.identity.Activator; +import org.osgi.framework.BundleContext; +import org.osgi.util.tracker.ServiceTracker; + +/** + * @since 3.4 + */ +public class ExtensionRegistryRunnable implements ISafeRunnable { + + private BundleContext context; + + public ExtensionRegistryRunnable(BundleContext ctxt) { + this.context = ctxt; + } + + protected void runWithoutRegistry() throws Exception { + // by default do nothing + } + + protected void runWithRegistry(IExtensionRegistry registry) + throws Exception { + // by default do nothing + } + + protected void logWarning(Throwable exception) { + Activator a = Activator.getDefault(); + if (a != null) + a.log(new Status(IStatus.WARNING, Activator.PLUGIN_ID, + IStatus.WARNING, "Warning: code cannot be run", exception)); //$NON-NLS-1$ + } + + public void run() throws Exception { + try { + runWithRegistry(getExtensionRegistry()); + } catch (NoClassDefFoundError e) { + runWithoutRegistry(); + } + } + + private IExtensionRegistry getExtensionRegistry() { + if (context == null) + return null; + ServiceTracker extensionRegistryTracker = new ServiceTracker(context, + IExtensionRegistry.class.getName(), null); + extensionRegistryTracker.open(); + IExtensionRegistry result = (IExtensionRegistry) extensionRegistryTracker + .getService(); + extensionRegistryTracker.close(); + return result; + } + + public void handleException(Throwable exception) { + logWarning(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..08ccc7ce8 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,60 +25,49 @@ 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 debugOptionsTracker; - private ServiceTracker extensionRegistryTracker = null; + private ServiceTracker logServiceTracker; - private ServiceTracker debugOptionsTracker = null; + private LogService logService; - private ServiceTracker logServiceTracker = null; + private AdapterManagerTracker adapterManagerTracker; - private LogService logService = null; + private ServiceTracker namespacesTracker; - 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) return null; // First, try to get the adapter manager via if (adapterManagerTracker == null) { - adapterManagerTracker = new ServiceTracker(this.context, - IAdapterManager.class.getName(), null); + adapterManagerTracker = new AdapterManagerTracker(this.context); adapterManagerTracker.open(); } - IAdapterManager adapterManager = (IAdapterManager) adapterManagerTracker - .getService(); - // Then, if the service isn't there, try to get from Platform class via - // PlatformHelper class - if (adapterManager == null) - adapterManager = PlatformHelper.getPlatformAdapterManager(); - if (adapterManager == null) - getDefault().log( - new Status(IStatus.ERROR, PLUGIN_ID, IStatus.ERROR, - "Cannot get adapter manager", null)); //$NON-NLS-1$ - return adapterManager; + return adapterManagerTracker.getAdapterManager(); } /** @@ -87,17 +77,6 @@ public class Activator implements BundleActivator { // public null constructor } - public synchronized IExtensionRegistry getExtensionRegistry() { - if (this.context == null) - return null; - if (extensionRegistryTracker == null) { - extensionRegistryTracker = new ServiceTracker(context, - IExtensionRegistry.class.getName(), null); - extensionRegistryTracker.open(); - } - return (IExtensionRegistry) extensionRegistryTracker.getService(); - } - public synchronized DebugOptions getDebugOptions() { if (context == null) return null; @@ -122,76 +101,102 @@ 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); - } - } - - 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; + namespacesTracker = new ServiceTracker(context, + Namespace.class.getName(), new ServiceTrackerCustomizer() { + + public Object addingService(ServiceReference reference) { + Namespace ns = (Namespace) context + .getService(reference); + if (ns != null && ns.getName() != null) + IDFactory.addNamespace0(ns); + return ns; + } + + public void modifiedService(ServiceReference reference, + Object service) { + } + + public void removedService(ServiceReference reference, + Object service) { + IDFactory.removeNamespace0((Namespace) service); + } + }); + namespacesTracker.open(); + + SafeRunner.run(new ExtensionRegistryRunnable(ctxt) { + protected void runWithRegistry(IExtensionRegistry registry) + throws Exception { + if (registry != 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: + IConfigurationElement[] members = delta[i] + .getExtension() + .getConfigurationElements(); + for (int m = 0; m < members.length; m++) { + final IConfigurationElement member = members[m]; + String name = null; + try { + name = member + .getAttribute(NAME_ATTRIBUTE); + if (name == null) { + name = member + .getAttribute(CLASS_ATTRIBUTE); + } + if (name == null) + continue; + final IIDFactory factory = IDFactory + .getDefault(); + final Namespace n = factory + .getNamespaceByName(name); + if (n == null + || !factory + .containsNamespace(n)) { + continue; + } + // remove + factory.removeNamespace(n); + } catch (final Exception e) { + getDefault() + .log(new Status( + IStatus.ERROR, + Activator.PLUGIN_ID, + IStatus.ERROR, + "Exception removing namespace", e)); //$NON-NLS-1$ + } + } + break; + } + } + } + }; + registry.addRegistryChangeListener((IRegistryChangeListener) registryManager); } } - } + }); } - /** - * Remove extensions for identity namespace extension point - * - * @param members - * the members to remove - */ - protected void removeNamespaceExtensions(IConfigurationElement[] members) { - for (int m = 0; m < members.length; m++) { - final IConfigurationElement member = members[m]; - String name = null; - try { - name = member.getAttribute(NAME_ATTRIBUTE); - if (name == null) { - name = member.getAttribute(CLASS_ATTRIBUTE); - } - if (name == null) - continue; - final IIDFactory factory = IDFactory.getDefault(); - final Namespace n = factory.getNamespaceByName(name); - if (n == null || !factory.containsNamespace(n)) { - continue; - } - // remove - factory.removeNamespace(n); - } catch (final Exception e) { - getDefault().log( - new Status(IStatus.ERROR, Activator.PLUGIN_ID, - REMOVE_NAMESPACE_ERRORCODE, - "Exception removing namespace", e)); //$NON-NLS-1$ - } - } + public BundleContext getBundleContext() { + return context; } - 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 +228,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,16 +275,19 @@ 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; + SafeRunner.run(new ExtensionRegistryRunnable(context) { + protected void runWithRegistry(IExtensionRegistry registry) + throws Exception { + if (registry != null) { + final IExtensionPoint extensionPoint = registry + .getExtensionPoint(NAMESPACE_EPOINT); + if (extensionPoint == null) + return; + addNamespaceExtensions(extensionPoint + .getConfigurationElements()); + } } - addNamespaceExtensions(extensionPoint.getConfigurationElements()); - } + }); } /* @@ -289,9 +297,17 @@ 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 ExtensionRegistryRunnable(ctxt) { + protected void runWithRegistry(IExtensionRegistry registry) + throws Exception { + if (registry != null) + registry.removeRegistryChangeListener((IRegistryChangeListener) registryManager); + } + }); + if (namespacesTracker != null) { + namespacesTracker.close(); + namespacesTracker = null; + } registryManager = null; if (logServiceTracker != null) { logServiceTracker.close(); @@ -302,10 +318,6 @@ public class Activator implements BundleActivator { debugOptionsTracker.close(); debugOptionsTracker = null; } - if (extensionRegistryTracker != null) { - extensionRegistryTracker.close(); - extensionRegistryTracker = null; - } if (idFactoryServiceRegistration != null) { idFactoryServiceRegistration.unregister(); idFactoryServiceRegistration = null; @@ -324,9 +336,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.provider/META-INF/MANIFEST.MF b/framework/bundles/org.eclipse.ecf.provider/META-INF/MANIFEST.MF index bac5d5780..1165db1be 100644 --- a/framework/bundles/org.eclipse.ecf.provider/META-INF/MANIFEST.MF +++ b/framework/bundles/org.eclipse.ecf.provider/META-INF/MANIFEST.MF @@ -1,6 +1,6 @@ Manifest-Version: 1.0 Bundle-SymbolicName: org.eclipse.ecf.provider;singleton:=true -Bundle-Version: 4.4.0.qualifier +Bundle-Version: 4.5.0.qualifier Bundle-Name: %plugin.name Bundle-Vendor: %plugin.provider Bundle-Activator: org.eclipse.ecf.internal.provider.ProviderPlugin diff --git a/framework/bundles/org.eclipse.ecf.provider/build.properties b/framework/bundles/org.eclipse.ecf.provider/build.properties index 4203b3f2e..7a0fd6349 100644 --- a/framework/bundles/org.eclipse.ecf.provider/build.properties +++ b/framework/bundles/org.eclipse.ecf.provider/build.properties @@ -12,8 +12,7 @@ bin.includes = .,\ plugin.xml,\ META-INF/,\ about.html,\ - plugin.properties,\ - OSGI-INF/ + plugin.properties src.includes = about.html jars.compile.order = . source.. = src/ diff --git a/framework/bundles/org.eclipse.ecf.provider/src/org/eclipse/ecf/internal/provider/ProviderPlugin.java b/framework/bundles/org.eclipse.ecf.provider/src/org/eclipse/ecf/internal/provider/ProviderPlugin.java index 52099e772..6e7280610 100644 --- a/framework/bundles/org.eclipse.ecf.provider/src/org/eclipse/ecf/internal/provider/ProviderPlugin.java +++ b/framework/bundles/org.eclipse.ecf.provider/src/org/eclipse/ecf/internal/provider/ProviderPlugin.java @@ -14,7 +14,10 @@ package org.eclipse.ecf.internal.provider; import javax.net.ssl.SSLServerSocketFactory; import javax.net.ssl.SSLSocketFactory; import org.eclipse.core.runtime.*; +import org.eclipse.ecf.core.ContainerTypeDescription; import org.eclipse.ecf.core.util.*; +import org.eclipse.ecf.provider.generic.GenericContainerInstantiator; +import org.eclipse.ecf.provider.generic.SSLGenericContainerInstantiator; import org.osgi.framework.BundleActivator; import org.osgi.framework.BundleContext; import org.osgi.service.log.LogService; @@ -36,7 +39,7 @@ public class ProviderPlugin implements BundleActivator { private ServiceTracker logServiceTracker = null; - private ServiceTracker adapterManagerTracker = null; + private AdapterManagerTracker adapterManagerTracker = null; private ServiceTracker sslServerSocketFactoryTracker; private ServiceTracker sslSocketFactoryTracker; @@ -46,17 +49,10 @@ public class ProviderPlugin implements BundleActivator { return null; // First, try to get the adapter manager via if (adapterManagerTracker == null) { - adapterManagerTracker = new ServiceTracker(this.context, IAdapterManager.class.getName(), null); + adapterManagerTracker = new AdapterManagerTracker(this.context); adapterManagerTracker.open(); } - IAdapterManager adapterManager = (IAdapterManager) adapterManagerTracker.getService(); - // Then, if the service isn't there, try to get from Platform class via - // PlatformHelper class - if (adapterManager == null) - adapterManager = PlatformHelper.getPlatformAdapterManager(); - if (adapterManager == null) - getDefault().log(new Status(IStatus.ERROR, PLUGIN_ID, IStatus.ERROR, "Cannot get adapter manager", null)); //$NON-NLS-1$ - return adapterManager; + return adapterManagerTracker.getAdapterManager(); } /** @@ -70,8 +66,16 @@ public class ProviderPlugin implements BundleActivator { /** * This method is called upon plug-in activation */ - public void start(BundleContext context1) throws Exception { + public void start(final BundleContext context1) throws Exception { this.context = context1; + SafeRunner.run(new ExtensionRegistryRunnable(this.context) { + protected void runWithoutRegistry() throws Exception { + context1.registerService(ContainerTypeDescription.class, new ContainerTypeDescription(GenericContainerInstantiator.TCPSERVER_NAME, new GenericContainerInstantiator(), "ECF Generic Server", true, false), null); //$NON-NLS-1$ + context1.registerService(ContainerTypeDescription.class, new ContainerTypeDescription(GenericContainerInstantiator.TCPCLIENT_NAME, new GenericContainerInstantiator(), "ECF Generic Client", false, true), null); //$NON-NLS-1$ + context1.registerService(ContainerTypeDescription.class, new ContainerTypeDescription(SSLGenericContainerInstantiator.SSLSERVER_NAME, new SSLGenericContainerInstantiator(), "ECF SSL Generic Server", true, false), null); //$NON-NLS-1$ + context1.registerService(ContainerTypeDescription.class, new ContainerTypeDescription(SSLGenericContainerInstantiator.SSLCLIENT_NAME, new SSLGenericContainerInstantiator(), "ECF SSL Generic Client", false, true), null); //$NON-NLS-1$ + } + }); } /** diff --git a/framework/bundles/org.eclipse.ecf.provider/src/org/eclipse/ecf/provider/generic/GenericContainerInstantiator.java b/framework/bundles/org.eclipse.ecf.provider/src/org/eclipse/ecf/provider/generic/GenericContainerInstantiator.java index 0ffd749a3..429b4b3c3 100644 --- a/framework/bundles/org.eclipse.ecf.provider/src/org/eclipse/ecf/provider/generic/GenericContainerInstantiator.java +++ b/framework/bundles/org.eclipse.ecf.provider/src/org/eclipse/ecf/provider/generic/GenericContainerInstantiator.java @@ -107,7 +107,10 @@ public class GenericContainerInstantiator implements IContainerInstantiator, IRe return keepAlive; } - InetAddress getBindAddress() { + /** + * @since 4.5 + */ + public InetAddress getBindAddress() { return bindAddress; } } @@ -265,19 +268,33 @@ public class GenericContainerInstantiator implements IContainerInstantiator, IRe return port; } + /** + * @since 4.5 + */ + protected IContainer createClientContainer(GenericContainerArgs gcargs) throws Exception { + return new TCPClientSOContainer(new SOContainerConfig(gcargs.getID()), gcargs.getKeepAlive().intValue()); + } + + /** + * @since 4.5 + */ + protected IContainer createServerContainer(GenericContainerArgs gcargs) throws Exception { + return new TCPServerSOContainer(new SOContainerConfig(gcargs.getID()), gcargs.getBindAddress(), gcargs.getKeepAlive().intValue()); + } + public IContainer createInstance(ContainerTypeDescription description, Object[] args) throws ContainerCreateException { boolean isClient = isClient(description); try { GenericContainerArgs gcargs = null; if (isClient) { gcargs = getClientArgs(args); - return new TCPClientSOContainer(new SOContainerConfig(gcargs.getID()), gcargs.getKeepAlive().intValue()); + return createClientContainer(gcargs); } // This synchronized block is to prevent issues with // multithreaded access to ServerPort (to find available port) synchronized (this) { gcargs = getServerArgs(args); - return new TCPServerSOContainer(new SOContainerConfig(gcargs.getID()), gcargs.getBindAddress(), gcargs.getKeepAlive().intValue()); + return createServerContainer(gcargs); } } catch (Exception e) { Trace.catching(ProviderPlugin.PLUGIN_ID, ECFProviderDebugOptions.EXCEPTIONS_CATCHING, this.getClass(), "createInstance", e); //$NON-NLS-1$ diff --git a/framework/bundles/org.eclipse.ecf.provider/src/org/eclipse/ecf/provider/generic/SSLGenericContainerInstantiator.java b/framework/bundles/org.eclipse.ecf.provider/src/org/eclipse/ecf/provider/generic/SSLGenericContainerInstantiator.java index f6403eede..5737444fd 100644 --- a/framework/bundles/org.eclipse.ecf.provider/src/org/eclipse/ecf/provider/generic/SSLGenericContainerInstantiator.java +++ b/framework/bundles/org.eclipse.ecf.provider/src/org/eclipse/ecf/provider/generic/SSLGenericContainerInstantiator.java @@ -108,7 +108,10 @@ public class SSLGenericContainerInstantiator implements IContainerInstantiator, return keepAlive; } - InetAddress getBindAddress() { + /** + * @since 4.5 + */ + public InetAddress getBindAddress() { return bindAddress; } } @@ -272,19 +275,33 @@ public class SSLGenericContainerInstantiator implements IContainerInstantiator, return port; } + /** + * @since 4.5 + */ + protected IContainer createClientContainer(GenericContainerArgs gcargs) throws Exception { + return new SSLClientSOContainer(new SOContainerConfig(gcargs.getID()), gcargs.getKeepAlive().intValue()); + } + + /** + * @since 4.5 + */ + protected IContainer createServerContainer(GenericContainerArgs gcargs) throws Exception { + return new SSLServerSOContainer(new SOContainerConfig(gcargs.getID()), gcargs.getBindAddress(), gcargs.getKeepAlive().intValue()); + } + public IContainer createInstance(ContainerTypeDescription description, Object[] args) throws ContainerCreateException { boolean isClient = isClient(description); try { GenericContainerArgs gcargs = null; if (isClient) { gcargs = getClientArgs(args); - return new SSLClientSOContainer(new SOContainerConfig(gcargs.getID()), gcargs.getKeepAlive().intValue()); + return createClientContainer(gcargs); } // This synchronized block is to prevent issues with // multithreaded access to ServerPort (to find available port) synchronized (this) { gcargs = getServerArgs(args); - return new SSLServerSOContainer(new SOContainerConfig(gcargs.getID()), gcargs.getBindAddress(), gcargs.getKeepAlive().intValue()); + return createServerContainer(gcargs); } } catch (Exception e) { Trace.catching(ProviderPlugin.PLUGIN_ID, ECFProviderDebugOptions.EXCEPTIONS_CATCHING, this.getClass(), "createInstance", e); //$NON-NLS-1$ diff --git a/framework/bundles/org.eclipse.ecf.remoteservice.rest/src/org/eclipse/ecf/internal/remoteservice/rest/Activator.java b/framework/bundles/org.eclipse.ecf.remoteservice.rest/src/org/eclipse/ecf/internal/remoteservice/rest/Activator.java index 74dd34879..8f1cdea0e 100644 --- a/framework/bundles/org.eclipse.ecf.remoteservice.rest/src/org/eclipse/ecf/internal/remoteservice/rest/Activator.java +++ b/framework/bundles/org.eclipse.ecf.remoteservice.rest/src/org/eclipse/ecf/internal/remoteservice/rest/Activator.java @@ -10,8 +10,11 @@ package org.eclipse.ecf.internal.remoteservice.rest; import org.eclipse.core.runtime.IStatus; -import org.eclipse.ecf.core.util.LogHelper; -import org.eclipse.ecf.core.util.SystemLogService; +import org.eclipse.core.runtime.SafeRunner; +import org.eclipse.ecf.core.ContainerTypeDescription; +import org.eclipse.ecf.core.identity.Namespace; +import org.eclipse.ecf.core.util.*; +import org.eclipse.ecf.remoteservice.rest.identity.RestNamespace; import org.osgi.framework.BundleActivator; import org.osgi.framework.BundleContext; import org.osgi.service.log.LogService; @@ -40,9 +43,15 @@ public class Activator implements BundleActivator { * @see * org.eclipse.core.runtime.Plugins#start(org.osgi.framework.BundleContext) */ - public void start(BundleContext context1) throws Exception { + public void start(final BundleContext context1) throws Exception { plugin = this; this.context = context1; + SafeRunner.run(new ExtensionRegistryRunnable(context1) { + protected void runWithoutRegistry() throws Exception { + context1.registerService(Namespace.class, new RestNamespace(), null); + context1.registerService(ContainerTypeDescription.class, new ContainerTypeDescription("ecf.rest.client", new RestClientContainerInstantiator(), "Rest Client Container"), null); //$NON-NLS-1$ //$NON-NLS-2$ + } + }); } /* diff --git a/framework/bundles/org.eclipse.ecf.remoteservice.rest/src/org/eclipse/ecf/remoteservice/rest/client/RestClientContainer.java b/framework/bundles/org.eclipse.ecf.remoteservice.rest/src/org/eclipse/ecf/remoteservice/rest/client/RestClientContainer.java index e28c1edf4..e2e1ede83 100644 --- a/framework/bundles/org.eclipse.ecf.remoteservice.rest/src/org/eclipse/ecf/remoteservice/rest/client/RestClientContainer.java +++ b/framework/bundles/org.eclipse.ecf.remoteservice.rest/src/org/eclipse/ecf/remoteservice/rest/client/RestClientContainer.java @@ -10,11 +10,15 @@ package org.eclipse.ecf.remoteservice.rest.client; import java.util.Dictionary; +import java.util.Hashtable; +import org.eclipse.ecf.core.ContainerConnectException; import org.eclipse.ecf.core.identity.*; import org.eclipse.ecf.remoteservice.*; import org.eclipse.ecf.remoteservice.client.*; import org.eclipse.ecf.remoteservice.rest.identity.RestID; import org.eclipse.ecf.remoteservice.rest.identity.RestNamespace; +import org.eclipse.ecf.remoteservice.util.RemoteFilterImpl; +import org.osgi.framework.InvalidSyntaxException; /** * A container for REST services. @@ -28,6 +32,20 @@ public class RestClientContainer extends AbstractClientContainer implements IRem setResponseDeserializer(new XMLRemoteResponseDeserializer()); } + public IRemoteServiceReference[] getRemoteServiceReferences(ID target, ID[] idFilter, String clazz, String filter) throws InvalidSyntaxException, ContainerConnectException { + return super.getRemoteServiceReferences(transformTarget(target, filter), idFilter, clazz, filter); + } + + public IRemoteServiceReference[] getRemoteServiceReferences(ID target, String clazz, String filter) throws InvalidSyntaxException, ContainerConnectException { + return super.getRemoteServiceReferences(transformTarget(target, filter), clazz, filter); + } + + protected ID transformTarget(ID originalTarget, String filter) throws InvalidSyntaxException { + if (originalTarget != null && filter != null && originalTarget instanceof RestID) + ((RestID) originalTarget).setRsId(new RemoteFilterImpl(filter).getRsId()); + return originalTarget; + } + protected class RestRemoteServiceClientRegistration extends RemoteServiceClientRegistration { public RestRemoteServiceClientRegistration(Namespace namespace, IRemoteCallable[] restCalls, Dictionary properties, RemoteServiceClientRegistry registry) { @@ -35,7 +53,13 @@ public class RestClientContainer extends AbstractClientContainer implements IRem ID cID = getConnectedID(); if (cID != null) this.containerId = cID; - this.serviceID = new RemoteServiceID(namespace, containerId, registry.getNextServiceId()); + long rsId = ((RestID) containerId).getRsId(); + this.serviceID = new RemoteServiceID(namespace, containerId, rsId); + if (rsId > 0) { + if (this.properties == null) + this.properties = new Hashtable(); + this.properties.put(org.eclipse.ecf.remoteservice.Constants.SERVICE_ID, new Long(rsId)); + } } public RestRemoteServiceClientRegistration(Namespace namespace, String[] classNames, IRemoteCallable[][] restCalls, Dictionary properties, RemoteServiceClientRegistry registry) { @@ -43,7 +67,13 @@ public class RestClientContainer extends AbstractClientContainer implements IRem ID cID = getConnectedID(); if (cID != null) this.containerId = cID; - this.serviceID = new RemoteServiceID(namespace, containerId, registry.getNextServiceId()); + long rsId = ((RestID) containerId).getRsId(); + this.serviceID = new RemoteServiceID(namespace, containerId, rsId); + if (rsId > 0) { + if (this.properties == null) + this.properties = new Hashtable(); + this.properties.put(org.eclipse.ecf.remoteservice.Constants.SERVICE_ID, new Long(rsId)); + } } } diff --git a/framework/bundles/org.eclipse.ecf.remoteservice.rest/src/org/eclipse/ecf/remoteservice/rest/identity/RestID.java b/framework/bundles/org.eclipse.ecf.remoteservice.rest/src/org/eclipse/ecf/remoteservice/rest/identity/RestID.java index 82f30f93c..e497be50b 100644 --- a/framework/bundles/org.eclipse.ecf.remoteservice.rest/src/org/eclipse/ecf/remoteservice/rest/identity/RestID.java +++ b/framework/bundles/org.eclipse.ecf.remoteservice.rest/src/org/eclipse/ecf/remoteservice/rest/identity/RestID.java @@ -17,10 +17,20 @@ public class RestID extends URIID { private static final long serialVersionUID = 2082626839598770167L; + private long rsId = 0; + public RestID(Namespace namespace, URI uri) { super(namespace, uri); } + public long getRsId() { + return rsId; + } + + public void setRsId(long rsId) { + this.rsId = rsId; + } + public String toString() { StringBuffer sb = new StringBuffer("RestID["); //$NON-NLS-1$ sb.append(getName()).append("]"); //$NON-NLS-1$ diff --git a/framework/bundles/org.eclipse.ecf.remoteservice.rest/src/org/eclipse/ecf/remoteservice/rest/identity/RestNamespace.java b/framework/bundles/org.eclipse.ecf.remoteservice.rest/src/org/eclipse/ecf/remoteservice/rest/identity/RestNamespace.java index ea59ed4b3..72fb51ab4 100644 --- a/framework/bundles/org.eclipse.ecf.remoteservice.rest/src/org/eclipse/ecf/remoteservice/rest/identity/RestNamespace.java +++ b/framework/bundles/org.eclipse.ecf.remoteservice.rest/src/org/eclipse/ecf/remoteservice/rest/identity/RestNamespace.java @@ -32,7 +32,7 @@ public class RestNamespace extends Namespace { public static final String SCHEME = "rest"; //$NON-NLS-1$ public RestNamespace() { - // nothing + super(NAME, "Rest Namespace"); //$NON-NLS-1$ } public RestNamespace(String name, String desc) { diff --git a/framework/bundles/org.eclipse.ecf.remoteservice.rpc/src/org/eclipse/ecf/internal/remoteservice/rpc/Activator.java b/framework/bundles/org.eclipse.ecf.remoteservice.rpc/src/org/eclipse/ecf/internal/remoteservice/rpc/Activator.java index 9295d1c77..fb346dfaf 100644 --- a/framework/bundles/org.eclipse.ecf.remoteservice.rpc/src/org/eclipse/ecf/internal/remoteservice/rpc/Activator.java +++ b/framework/bundles/org.eclipse.ecf.remoteservice.rpc/src/org/eclipse/ecf/internal/remoteservice/rpc/Activator.java @@ -10,8 +10,11 @@ package org.eclipse.ecf.internal.remoteservice.rpc; import org.eclipse.core.runtime.IStatus; -import org.eclipse.ecf.core.util.LogHelper; -import org.eclipse.ecf.core.util.SystemLogService; +import org.eclipse.core.runtime.SafeRunner; +import org.eclipse.ecf.core.ContainerTypeDescription; +import org.eclipse.ecf.core.identity.Namespace; +import org.eclipse.ecf.core.util.*; +import org.eclipse.ecf.remoteservice.rpc.identity.RpcNamespace; import org.osgi.framework.BundleActivator; import org.osgi.framework.BundleContext; import org.osgi.service.log.LogService; @@ -39,9 +42,16 @@ public class Activator implements BundleActivator { * (non-Javadoc) * @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext) */ - public void start(BundleContext bundleContext) throws Exception { + public void start(final BundleContext bundleContext) throws Exception { plugin = this; Activator.context = bundleContext; + SafeRunner.run(new ExtensionRegistryRunnable(bundleContext) { + protected void runWithoutRegistry() throws Exception { + bundleContext.registerService(Namespace.class, new RpcNamespace(), null); + bundleContext.registerService(ContainerTypeDescription.class, new ContainerTypeDescription( + "ecf.xmlrpc.client", new RpcClientContainerInstantiator(), "Rpc Client Container"), null); //$NON-NLS-1$ //$NON-NLS-2$ + } + }); } /* diff --git a/framework/bundles/org.eclipse.ecf.remoteservice.rpc/src/org/eclipse/ecf/remoteservice/rpc/identity/RpcNamespace.java b/framework/bundles/org.eclipse.ecf.remoteservice.rpc/src/org/eclipse/ecf/remoteservice/rpc/identity/RpcNamespace.java index 01720e670..a11199906 100644 --- a/framework/bundles/org.eclipse.ecf.remoteservice.rpc/src/org/eclipse/ecf/remoteservice/rpc/identity/RpcNamespace.java +++ b/framework/bundles/org.eclipse.ecf.remoteservice.rpc/src/org/eclipse/ecf/remoteservice/rpc/identity/RpcNamespace.java @@ -33,7 +33,7 @@ public class RpcNamespace extends Namespace { public static final String SCHEME = "xmlrpc"; //$NON-NLS-1$ public RpcNamespace() { - // nothing + super(NAME, "Rpc Namespace"); //$NON-NLS-1$ } public RpcNamespace(String name, String desc) { diff --git a/framework/bundles/org.eclipse.ecf.remoteservice/.settings/.api_filters b/framework/bundles/org.eclipse.ecf.remoteservice/.settings/.api_filters deleted file mode 100644 index 950b0b2b5..000000000 --- a/framework/bundles/org.eclipse.ecf.remoteservice/.settings/.api_filters +++ /dev/null @@ -1,12 +0,0 @@ -<?xml version="1.0" encoding="UTF-8" standalone="no"?> -<component id="org.eclipse.ecf.remoteservice" version="2"> - <resource path="src/org/eclipse/ecf/remoteservice/util/RemoteFilterImpl.java" type="org.eclipse.ecf.remoteservice.util.RemoteFilterImpl"> - <filter comment="remote service filter can implement osgi Filter" id="574660632"> - <message_arguments> - <message_argument value="IRemoteFilter"/> - <message_argument value="Filter"/> - <message_argument value="RemoteFilterImpl"/> - </message_arguments> - </filter> - </resource> -</component> diff --git a/framework/bundles/org.eclipse.ecf.remoteservice/META-INF/MANIFEST.MF b/framework/bundles/org.eclipse.ecf.remoteservice/META-INF/MANIFEST.MF index 3d2b46166..1b52fcb33 100644 --- a/framework/bundles/org.eclipse.ecf.remoteservice/META-INF/MANIFEST.MF +++ b/framework/bundles/org.eclipse.ecf.remoteservice/META-INF/MANIFEST.MF @@ -2,7 +2,7 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: %plugin.name Bundle-SymbolicName: org.eclipse.ecf.remoteservice -Bundle-Version: 8.3.0.qualifier +Bundle-Version: 8.4.0.qualifier Bundle-Activator: org.eclipse.ecf.internal.remoteservice.Activator Bundle-Vendor: %plugin.provider Bundle-Localization: plugin diff --git a/framework/bundles/org.eclipse.ecf.remoteservice/src/org/eclipse/ecf/remoteservice/AbstractRemoteService.java b/framework/bundles/org.eclipse.ecf.remoteservice/src/org/eclipse/ecf/remoteservice/AbstractRemoteService.java index b24ce6b50..2d65eed5b 100644 --- a/framework/bundles/org.eclipse.ecf.remoteservice/src/org/eclipse/ecf/remoteservice/AbstractRemoteService.java +++ b/framework/bundles/org.eclipse.ecf.remoteservice/src/org/eclipse/ecf/remoteservice/AbstractRemoteService.java @@ -395,17 +395,17 @@ public abstract class AbstractRemoteService implements IRemoteService, Invocatio } /** - * @since 3.3 + * @since 8.4 */ - protected class AsyncArgs { + public class AsyncArgs { private IRemoteCallListener listener; private Object[] args; - private boolean isIFuture; + private Class returnType; - public AsyncArgs(Object[] originalArgs, boolean isIFuture) { + public AsyncArgs(Object[] originalArgs, Class returnType) { this.listener = null; this.args = originalArgs; - this.isIFuture = isIFuture; + this.returnType = returnType; } public AsyncArgs(IRemoteCallListener listener, Object[] originalArgs) { @@ -426,11 +426,8 @@ public abstract class AbstractRemoteService implements IRemoteService, Invocatio return args; } - /** - * @since 8.2 - */ - public boolean isIFuture() { - return isIFuture; + public Class getReturnType() { + return returnType; } } @@ -440,8 +437,7 @@ public abstract class AbstractRemoteService implements IRemoteService, Invocatio protected Object invokeAsync(final Method method, final Object[] args) throws Throwable { final String invokeMethodName = getAsyncInvokeMethodName(method); final AsyncArgs asyncArgs = getAsyncArgs(method, args); - IRemoteCallListener listener = asyncArgs.getListener(); - IRemoteCall call = new IRemoteCall() { + return callAsync(new IRemoteCall() { public String getMethod() { return invokeMethodName; } @@ -453,14 +449,23 @@ public abstract class AbstractRemoteService implements IRemoteService, Invocatio public long getTimeout() { return DEFAULT_TIMEOUT; } - }; - // IFuture or Future will have listener == null - if (listener == null) { - if (asyncArgs.isIFuture()) - return callAsync(call); - return callFutureAsync(call); - } - return callAsyncWithResult(call, listener); + }, asyncArgs.getListener(), asyncArgs.getReturnType()); + } + + /** + * @since 8.4 + */ + protected Object callAsync(IRemoteCall call, IRemoteCallListener listener, Class returnType) { + return (listener != null) ? callAsyncWithResult(call, listener) : callFuture(call, returnType); + } + + /** + * @since 8.4 + */ + protected Object callFuture(IRemoteCall call, Class returnType) { + if (IFuture.class.isAssignableFrom(returnType)) + return callAsync(call); + return callFutureAsync(call); } /** @@ -492,30 +497,26 @@ public abstract class AbstractRemoteService implements IRemoteService, Invocatio IRemoteCallListener listener = null; Class returnType = method.getReturnType(); // If the return type is of type java.util.concurrent.Future, then we return - if (returnType.isAssignableFrom(Future.class)) { - return new AsyncArgs(args, false); - } else if (returnType.isAssignableFrom(IFuture.class)) { - return new AsyncArgs(args, true); - } else { - // If the provided args do *not* include an IRemoteCallListener then we have a problem - if (args == null || args.length == 0) - throw new IllegalArgumentException("Async calls must include a IRemoteCallListener instance as the last argument"); //$NON-NLS-1$ - // Get the last arg - Object lastArg = args[args.length - 1]; - // If it's an IRemoteCallListener implementer directly, then just cast and return - if (lastArg instanceof IRemoteCallListener) { - listener = (IRemoteCallListener) lastArg; - } - // If it's an implementation of IAsyncCallback, then create a new listener based upon - // callback and return - if (lastArg instanceof IAsyncCallback) { - listener = new CallbackRemoteCallListener((IAsyncCallback) lastArg); - } - // If the last are is not an instance of IRemoteCallListener then there is a problem - if (listener == null) - throw new IllegalArgumentException("Last argument must be an instance of IRemoteCallListener"); //$NON-NLS-1$ - return new AsyncArgs(listener, args); + if (Future.class.isAssignableFrom(returnType) || IFuture.class.isAssignableFrom(returnType)) + return new AsyncArgs(args, returnType); + // If the provided args do *not* include an IRemoteCallListener then we have a problem + if (args == null || args.length == 0) + throw new IllegalArgumentException("Async calls must include a IRemoteCallListener instance as the last argument"); //$NON-NLS-1$ + // Get the last arg + Object lastArg = args[args.length - 1]; + // If it's an IRemoteCallListener implementer directly, then just cast and return + if (lastArg instanceof IRemoteCallListener) { + listener = (IRemoteCallListener) lastArg; + } + // If it's an implementation of IAsyncCallback, then create a new listener based upon + // callback and return + if (lastArg instanceof IAsyncCallback) { + listener = new CallbackRemoteCallListener((IAsyncCallback) lastArg); } + // If the last are is not an instance of IRemoteCallListener then there is a problem + if (listener == null) + throw new IllegalArgumentException("Last argument must be an instance of IRemoteCallListener"); //$NON-NLS-1$ + return new AsyncArgs(listener, args); } /** diff --git a/framework/bundles/org.eclipse.ecf.remoteservice/src/org/eclipse/ecf/remoteservice/util/RemoteFilterImpl.java b/framework/bundles/org.eclipse.ecf.remoteservice/src/org/eclipse/ecf/remoteservice/util/RemoteFilterImpl.java index 38963c2e7..b6906d83e 100644 --- a/framework/bundles/org.eclipse.ecf.remoteservice/src/org/eclipse/ecf/remoteservice/util/RemoteFilterImpl.java +++ b/framework/bundles/org.eclipse.ecf.remoteservice/src/org/eclipse/ecf/remoteservice/util/RemoteFilterImpl.java @@ -12,6 +12,8 @@ package org.eclipse.ecf.remoteservice.util; import java.util.*; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; import org.eclipse.ecf.internal.remoteservice.Activator; import org.eclipse.ecf.remoteservice.IRemoteFilter; import org.eclipse.ecf.remoteservice.IRemoteServiceReference; @@ -23,8 +25,15 @@ import org.osgi.framework.*; */ public class RemoteFilterImpl implements IRemoteFilter { + /** + * @since 8.4 + */ + public static final String REMOTE_SERVICEID_PREFIX = "(&(" + org.eclipse.ecf.remoteservice.Constants.SERVICE_ID + "="; //$NON-NLS-1$ //$NON-NLS-2$ + Filter filter; + long rsId = 0; + /** * @param createFilter */ @@ -32,6 +41,30 @@ public class RemoteFilterImpl implements IRemoteFilter { this(Activator.getDefault().getContext(), createFilter); } + private void parseForRsId(String createFilter) { + if (createFilter == null) + return; + if (createFilter.startsWith(REMOTE_SERVICEID_PREFIX)) { + String f = createFilter.substring(REMOTE_SERVICEID_PREFIX.length()); + int rightParenIndex = f.indexOf(')'); + if (rightParenIndex == -1) + return; + f = f.substring(0, rightParenIndex); + try { + this.rsId = Long.parseLong(f); + } catch (NumberFormatException e) { + Activator.getDefault().log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Exception parsing remote service filter=" + filter, e)); //$NON-NLS-1$ + } + } + } + + /** + * @since 8.4 + */ + public long getRsId() { + return rsId; + } + /** * @param createFilter * @since 6.0 @@ -39,6 +72,7 @@ public class RemoteFilterImpl implements IRemoteFilter { public RemoteFilterImpl(BundleContext context, String createFilter) throws InvalidSyntaxException { if (createFilter == null) throw new InvalidSyntaxException("Filter cannot be null", createFilter); //$NON-NLS-1$ + parseForRsId(createFilter); this.filter = context.createFilter(createFilter); } diff --git a/framework/bundles/org.eclipse.ecf.sharedobject/META-INF/MANIFEST.MF b/framework/bundles/org.eclipse.ecf.sharedobject/META-INF/MANIFEST.MF index 20d73c2cf..1ff1ba241 100644 --- a/framework/bundles/org.eclipse.ecf.sharedobject/META-INF/MANIFEST.MF +++ b/framework/bundles/org.eclipse.ecf.sharedobject/META-INF/MANIFEST.MF @@ -1,7 +1,7 @@ Manifest-Version: 1.0 Bundle-Name: %plugin.name Bundle-SymbolicName: org.eclipse.ecf.sharedobject;singleton:=true -Bundle-Version: 2.4.0.qualifier +Bundle-Version: 2.5.0.qualifier Bundle-Activator: org.eclipse.ecf.internal.core.sharedobject.Activator Bundle-Localization: plugin Bundle-Vendor: %plugin.provider @@ -17,7 +17,7 @@ Export-Package: org.eclipse.ecf.core.sharedobject;version="2.3", Bundle-ManifestVersion: 2 Bundle-RequiredExecutionEnvironment: J2SE-1.5 Require-Bundle: org.eclipse.equinox.common, - org.eclipse.equinox.registry, + org.eclipse.equinox.registry;resolution:=optional, org.eclipse.ecf Import-Package: org.eclipse.equinox.concurrent.future;version="1.0.0", org.osgi.framework, diff --git a/framework/bundles/org.eclipse.ecf.sharedobject/src/org/eclipse/ecf/internal/core/sharedobject/Activator.java b/framework/bundles/org.eclipse.ecf.sharedobject/src/org/eclipse/ecf/internal/core/sharedobject/Activator.java index 877613b33..651a292c0 100644 --- a/framework/bundles/org.eclipse.ecf.sharedobject/src/org/eclipse/ecf/internal/core/sharedobject/Activator.java +++ b/framework/bundles/org.eclipse.ecf.sharedobject/src/org/eclipse/ecf/internal/core/sharedobject/Activator.java @@ -40,15 +40,11 @@ public class Activator implements BundleActivator { // The shared instance private static Activator plugin; - private BundleContext context = null; - - private IRegistryChangeListener registryManager = null; - - private ServiceTracker extensionRegistryTracker = null; + BundleContext context = null; private ServiceTracker logServiceTracker = null; - private ServiceTracker adapterManagerTracker = null; + private AdapterManagerTracker adapterManagerTracker = null; /** * The constructor @@ -57,27 +53,25 @@ public class Activator implements BundleActivator { // null constructor } - public IExtensionRegistry getExtensionRegistry() { - return (IExtensionRegistry) extensionRegistryTracker.getService(); - } - /* * (non-Javadoc) * * @see org.eclipse.core.runtime.Plugins#start(org.osgi.framework.BundleContext) */ - @SuppressWarnings("unchecked") public void start(BundleContext ctxt) throws Exception { this.context = ctxt; plugin = this; - this.extensionRegistryTracker = new ServiceTracker(ctxt, IExtensionRegistry.class.getName(), null); - this.extensionRegistryTracker.open(); - IExtensionRegistry registry = getExtensionRegistry(); - if (registry != null) { - this.registryManager = new SharedObjectRegistryManager(); - registry.addRegistryChangeListener(registryManager); - } - setupSharedObjectExtensionPoint(ctxt); + + SafeRunner.run(new ExtensionRegistryRunnable(context) { + @Override + protected void runWithRegistry(IExtensionRegistry registry) throws Exception { + if (registry != null) { + IExtensionPoint extensionPoint = registry.getExtensionPoint(SHAREDOBJECT_FACTORY_EPOINT); + if (extensionPoint != null) + addSharedObjectExtensions(extensionPoint.getConfigurationElements()); + } + } + }); Trace.exiting(Activator.PLUGIN_ID, SharedObjectDebugOptions.METHODS_ENTERING, Activator.class, "start"); //$NON-NLS-1$ } @@ -88,14 +82,6 @@ public class Activator implements BundleActivator { */ public void stop(BundleContext ctxt) throws Exception { Trace.entering(Activator.PLUGIN_ID, SharedObjectDebugOptions.METHODS_EXITING, Activator.class, "stop"); //$NON-NLS-1$ - IExtensionRegistry reg = getExtensionRegistry(); - if (reg != null) - reg.removeRegistryChangeListener(registryManager); - this.registryManager = null; - if (extensionRegistryTracker != null) { - extensionRegistryTracker.close(); - extensionRegistryTracker = null; - } if (adapterManagerTracker != null) { adapterManagerTracker.close(); adapterManagerTracker = null; @@ -145,23 +131,15 @@ public class Activator implements BundleActivator { } } - @SuppressWarnings("unchecked") public IAdapterManager getAdapterManager() { if (context == null) return null; // First, try to get the adapter manager via if (adapterManagerTracker == null) { - adapterManagerTracker = new ServiceTracker(this.context, IAdapterManager.class.getName(), null); + adapterManagerTracker = new AdapterManagerTracker(this.context); adapterManagerTracker.open(); } - IAdapterManager adapterManager = (IAdapterManager) adapterManagerTracker.getService(); - // Then, if the service isn't there, try to get from Platform class via - // PlatformHelper class - if (adapterManager == null) - adapterManager = PlatformHelper.getPlatformAdapterManager(); - if (adapterManager == null) - getDefault().log(new Status(IStatus.ERROR, PLUGIN_ID, IStatus.ERROR, "Cannot get adapter manager", null)); //$NON-NLS-1$ - return adapterManager; + return adapterManagerTracker.getAdapterManager(); } /** @@ -170,7 +148,7 @@ public class Activator implements BundleActivator { * @param members * the members to remove */ - protected void removeSharedObjectExtensions(IConfigurationElement[] members) { + void removeSharedObjectExtensions(IConfigurationElement[] members) { for (int m = 0; m < members.length; m++) { IConfigurationElement member = members[m]; String name = null; @@ -203,7 +181,7 @@ public class Activator implements BundleActivator { * @param members * to add */ - protected void addSharedObjectExtensions(IConfigurationElement[] members) { + void addSharedObjectExtensions(IConfigurationElement[] members) { String bundleName = getDefault().getBundle().getSymbolicName(); // For each configuration element for (int m = 0; m < members.length; m++) { @@ -224,8 +202,22 @@ public class Activator implements BundleActivator { if (description == null) { description = ""; //$NON-NLS-1$ } + IConfigurationElement[] propertyElements = member.getChildren(PROPERTY_ELEMENT_NAME); + Properties props = new Properties(); + if (propertyElements != null) { + if (propertyElements.length > 0) { + for (int i = 0; i < propertyElements.length; i++) { + String name1 = propertyElements[i].getAttribute(NAME_ATTRIBUTE); + String value = propertyElements[i].getAttribute(VALUE_ATTRIBUTE); + if (name1 != null && !name1.equals("") && value != null //$NON-NLS-1$ + && !value.equals("")) { //$NON-NLS-1$ + props.setProperty(name1, value); + } + } + } + } // Get any property elements - Map properties = getProperties(member.getChildren(PROPERTY_ELEMENT_NAME)); + Map properties = props; // Now make description instance SharedObjectTypeDescription scd = new SharedObjectTypeDescription(name, exten, description, properties); org.eclipse.ecf.core.util.Trace.trace(Activator.PLUGIN_ID, SharedObjectDebugOptions.DEBUG, "setupSharedObjectExtensionPoint:createdDescription(" //$NON-NLS-1$ @@ -252,54 +244,4 @@ public class Activator implements BundleActivator { } } - /** - * Setup shared object extension point - * - * @param bc - * the BundleContext for this bundle - */ - protected void setupSharedObjectExtensionPoint(BundleContext bc) { - IExtensionRegistry reg = getExtensionRegistry(); - if (reg != null) { - IExtensionPoint extensionPoint = reg.getExtensionPoint(SHAREDOBJECT_FACTORY_EPOINT); - if (extensionPoint == null) { - return; - } - addSharedObjectExtensions(extensionPoint.getConfigurationElements()); - } - } - - protected Map getProperties(IConfigurationElement[] propertyElements) { - Properties props = new Properties(); - if (propertyElements != null) { - if (propertyElements.length > 0) { - for (int i = 0; i < propertyElements.length; i++) { - String name = propertyElements[i].getAttribute(NAME_ATTRIBUTE); - String value = propertyElements[i].getAttribute(VALUE_ATTRIBUTE); - if (name != null && !name.equals("") && value != null //$NON-NLS-1$ - && !value.equals("")) { //$NON-NLS-1$ - props.setProperty(name, value); - } - } - } - } - return props; - } - - protected class SharedObjectRegistryManager implements IRegistryChangeListener { - public void registryChanged(IRegistryChangeEvent event) { - IExtensionDelta delta[] = event.getExtensionDeltas(PLUGIN_ID, NAMESPACE_NAME); - for (int i = 0; i < delta.length; i++) { - switch (delta[i].getKind()) { - case IExtensionDelta.ADDED : - addSharedObjectExtensions(delta[i].getExtension().getConfigurationElements()); - break; - case IExtensionDelta.REMOVED : - removeSharedObjectExtensions(delta[i].getExtension().getConfigurationElements()); - break; - } - } - } - } - } diff --git a/framework/bundles/org.eclipse.ecf/META-INF/MANIFEST.MF b/framework/bundles/org.eclipse.ecf/META-INF/MANIFEST.MF index 619ac53a5..b201fbc5f 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.3.0.qualifier +Bundle-Version: 3.4.0.qualifier Bundle-Activator: org.eclipse.ecf.internal.core.ECFPlugin Bundle-Vendor: %plugin.provider Bundle-Localization: plugin @@ -17,7 +17,7 @@ Export-Package: org.eclipse.ecf.core;version="3.0.0", org.eclipse.ecf.core.start;version="3.1.0", org.eclipse.ecf.core.status;version="1.1.0", org.eclipse.ecf.core.user;version="3.1.0", - org.eclipse.ecf.core.util;version="3.2.0", + org.eclipse.ecf.core.util;version="3.4.0", org.eclipse.ecf.core.util.reflection;version="2.3.0", org.eclipse.ecf.internal.core;x-internal:=true Import-Package: org.eclipse.core.runtime.jobs, @@ -26,6 +26,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/core/BaseContainer.java b/framework/bundles/org.eclipse.ecf/src/org/eclipse/ecf/core/BaseContainer.java index bf004c746..e35c41a7c 100644 --- a/framework/bundles/org.eclipse.ecf/src/org/eclipse/ecf/core/BaseContainer.java +++ b/framework/bundles/org.eclipse.ecf/src/org/eclipse/ecf/core/BaseContainer.java @@ -25,6 +25,12 @@ import org.eclipse.ecf.core.security.IConnectContext; public class BaseContainer extends AbstractContainer { public static class Instantiator extends BaseContainerInstantiator { + + /** + * @since 3.4 + */ + public static final String NAME = "ecf.base"; //$NON-NLS-1$ + private static long nextBaseContainerID = 0L; public IContainer createInstance(ContainerTypeDescription description, Object[] parameters) throws ContainerCreateException { diff --git a/framework/bundles/org.eclipse.ecf/src/org/eclipse/ecf/core/ContainerTypeDescription.java b/framework/bundles/org.eclipse.ecf/src/org/eclipse/ecf/core/ContainerTypeDescription.java index c8cd25685..96555812e 100644 --- a/framework/bundles/org.eclipse.ecf/src/org/eclipse/ecf/core/ContainerTypeDescription.java +++ b/framework/bundles/org.eclipse.ecf/src/org/eclipse/ecf/core/ContainerTypeDescription.java @@ -53,6 +53,13 @@ public class ContainerTypeDescription { this.hidden = hidden; } + /** + * @since 3.4 + */ + public ContainerTypeDescription(String name, IContainerInstantiator instantiator) { + this(name, instantiator, null); + } + public ContainerTypeDescription(String name, IContainerInstantiator instantiator, String description) { this(name, instantiator, description, false, false); } 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..151df0d31 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,13 @@ public class ECFPlugin implements BundleActivator { // The shared instance. private static ECFPlugin plugin; - private BundleContext context = null; - - private ServiceTracker extensionRegistryTracker = null; + BundleContext context = 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; @@ -83,7 +84,7 @@ public class ECFPlugin implements BundleActivator { private LogService logService = null; - private ServiceTracker adapterManagerTracker = null; + private AdapterManagerTracker adapterManagerTracker = null; private BundleActivator ecfTrustManager; @@ -92,9 +93,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,14 +117,62 @@ 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); + // 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 && ctd.getName() != null) + ContainerFactory.getDefault().addDescription(ctd); + return ctd; + } + + 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(); } + SafeRunner.run(new ExtensionRegistryRunnable(this.context) { + protected void runWithRegistry(IExtensionRegistry registry) throws Exception { + 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() { public Object getService(Bundle bundle, ServiceRegistration registration) { @@ -135,25 +183,91 @@ 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 ExtensionRegistryRunnable(this.context) { + protected void runWithRegistry(IExtensionRegistry registry) throws Exception { + if (registry != null) { + final IExtensionPoint extensionPoint = registry.getExtensionPoint(START_EPOINT); + if (extensionPoint == null) { + return; + } + IConfigurationElement[] configurationElements = extensionPoint.getConfigurationElements(); + final String method = "runStartExtensions"; //$NON-NLS-1$ + // For each configuration element + for (int m = 0; m < configurationElements.length; m++) { + final IConfigurationElement member = configurationElements[m]; + try { + // The only required attribute is "class" + boolean sync = (member.getAttribute(ASYNCH_ATTRIBUTE) == null); + IECFStart clazz = (IECFStart) member.createExecutableExtension(CLASS_ATTRIBUTE); + // Create job to do start, and schedule + if (sync) { + IStatus result = null; + try { + result = clazz.run(new NullProgressMonitor()); + } catch (final Throwable e) { + final String message = "startup extension error"; //$NON-NLS-1$ + logException(new Status(IStatus.ERROR, PLUGIN_ID, IStatus.ERROR, message, e), message, e); + } + if (result != null && !result.isOK()) + logException(result, result.getMessage(), result.getException()); + } else { + final ECFStartJob job = new ECFStartJob(clazz.getClass().getName(), clazz); + job.schedule(); + } + } catch (final CoreException e) { + logException(e.getStatus(), method, e); + } catch (final Exception e) { + logException(new Status(IStatus.ERROR, getDefault().getBundle().getSymbolicName(), IStatus.ERROR, "Unknown start exception", e), method, e); //$NON-NLS-1$ + } + } + } + } + }); + + SafeRunner.run(new ExtensionRegistryRunnable(this.context) { + protected void runWithoutRegistry() throws Exception { + ECFPlugin.this.context.registerService(ContainerTypeDescription.class, new ContainerTypeDescription(BaseContainer.Instantiator.NAME, new BaseContainer.Instantiator()), null); + } + }); } + private ServiceTracker containerTypeDescriptionTracker; + public void initializeExtensions() { - setupContainerFactoryExtensionPoint(context); - setupContainerExtensionPoint(context); + SafeRunner.run(new ExtensionRegistryRunnable(this.context) { + protected void runWithRegistry(IExtensionRegistry registry) throws Exception { + if (registry != null) { + IExtensionPoint extensionPoint = registry.getExtensionPoint(CONTAINER_FACTORY_EPOINT); + if (extensionPoint == null) + return; + addContainerFactoryExtensions(extensionPoint.getConfigurationElements()); + extensionPoint = registry.getExtensionPoint(CONTAINER_EPOINT); + if (extensionPoint == null) + return; + addContainerExtensions(extensionPoint.getConfigurationElements()); + } + } + }); } public void stop(BundleContext ctxt) throws Exception { fireDisposables(); this.disposables = null; - final IExtensionRegistry reg = getExtensionRegistry(); - if (reg != null) - reg.removeRegistryChangeListener(registryManager); + SafeRunner.run(new ExtensionRegistryRunnable(ctxt) { + protected void runWithRegistry(IExtensionRegistry registry) throws Exception { + if (registry != null) + registry.removeRegistryChangeListener((IRegistryChangeListener) registryManager); + } + }); this.registryManager = null; + if (containerTypeDescriptionTracker != null) { + containerTypeDescriptionTracker.close(); + containerTypeDescriptionTracker = null; + } if (ecfTrustManager != null) { ecfTrustManager.stop(ctxt); ecfTrustManager = null; @@ -163,10 +277,6 @@ public class ECFPlugin implements BundleActivator { logServiceTracker = null; logService = null; } - if (extensionRegistryTracker != null) { - extensionRegistryTracker.close(); - extensionRegistryTracker = null; - } if (containerFactoryServiceRegistration != null) { containerFactoryServiceRegistration.unregister(); containerFactoryServiceRegistration = null; @@ -411,136 +521,15 @@ public class ECFPlugin implements BundleActivator { return results; } - /** - * Setup container factory extension point - * - * @param bc - * the BundleContext for this bundle - */ - protected void setupContainerFactoryExtensionPoint(BundleContext bc) { - final IExtensionRegistry reg = getExtensionRegistry(); - if (reg != null) { - final IExtensionPoint extensionPoint = reg.getExtensionPoint(CONTAINER_FACTORY_EPOINT); - if (extensionPoint == null) { - return; - } - addContainerFactoryExtensions(extensionPoint.getConfigurationElements()); - } - } - - protected void setupContainerExtensionPoint(BundleContext bc) { - final IExtensionRegistry reg = getExtensionRegistry(); - if (reg != null) { - final IExtensionPoint extensionPoint = reg.getExtensionPoint(CONTAINER_EPOINT); - if (extensionPoint == null) { - return; - } - addContainerExtensions(extensionPoint.getConfigurationElements()); - } - } - - public IExtensionRegistry getExtensionRegistry() { - if (context == null) - return null; - return (IExtensionRegistry) extensionRegistryTracker.getService(); - } - - /** - * Setup start extension point - * - * @param bc - * the BundleContext for this bundle - */ - protected void setupStartExtensionPoint(BundleContext bc) { - final IExtensionRegistry reg = getExtensionRegistry(); - if (reg != null) { - final IExtensionPoint extensionPoint = reg.getExtensionPoint(START_EPOINT); - if (extensionPoint == null) { - return; - } - runStartExtensions(extensionPoint.getConfigurationElements()); - } - } - - protected void runStartExtensions(IConfigurationElement[] configurationElements) { - final String method = "runStartExtensions"; //$NON-NLS-1$ - // For each configuration element - for (int m = 0; m < configurationElements.length; m++) { - final IConfigurationElement member = configurationElements[m]; - try { - // The only required attribute is "class" - boolean sync = (member.getAttribute(ASYNCH_ATTRIBUTE) == null); - IECFStart clazz = (IECFStart) member.createExecutableExtension(CLASS_ATTRIBUTE); - startExtension(clazz.getClass().getName(), clazz, sync); - } catch (final CoreException e) { - logException(e.getStatus(), method, e); - } catch (final Exception e) { - logException(new Status(IStatus.ERROR, getDefault().getBundle().getSymbolicName(), IStatus.ERROR, "Unknown start exception", e), method, e); //$NON-NLS-1$ - } - } - } - - private void startExtension(String name, IECFStart exten, boolean synchronous) { - // Create job to do start, and schedule - if (synchronous) { - IStatus result = null; - try { - result = exten.run(new NullProgressMonitor()); - } catch (final Throwable e) { - final String message = "startup extension error"; //$NON-NLS-1$ - logException(new Status(IStatus.ERROR, PLUGIN_ID, IStatus.ERROR, message, e), message, e); - } - if (result != null && !result.isOK()) - logException(result, result.getMessage(), result.getException()); - } else { - final ECFStartJob job = new ECFStartJob(name, exten); - job.schedule(); - } - } - - 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; // First, try to get the adapter manager via if (adapterManagerTracker == null) { - adapterManagerTracker = new ServiceTracker(this.context, IAdapterManager.class.getName(), null); + adapterManagerTracker = new AdapterManagerTracker(this.context); adapterManagerTracker.open(); } - IAdapterManager adapterManager = (IAdapterManager) adapterManagerTracker.getService(); - // Then, if the service isn't there, try to get from Platform class via - // PlatformHelper class - if (adapterManager == null) - adapterManager = PlatformHelper.getPlatformAdapterManager(); - if (adapterManager == null) - getDefault().log(new Status(IStatus.ERROR, PLUGIN_ID, IStatus.ERROR, "Cannot get adapter manager", null)); //$NON-NLS-1$ - return adapterManager; + return adapterManagerTracker.getAdapterManager(); } }
\ No newline at end of file |