diff options
6 files changed, 82 insertions, 153 deletions
diff --git a/examples/bundles/org.eclipse.ecf.examples.provider.trivial/META-INF/MANIFEST.MF b/examples/bundles/org.eclipse.ecf.examples.provider.trivial/META-INF/MANIFEST.MF index beb52f0c5..e591a7136 100644 --- a/examples/bundles/org.eclipse.ecf.examples.provider.trivial/META-INF/MANIFEST.MF +++ b/examples/bundles/org.eclipse.ecf.examples.provider.trivial/META-INF/MANIFEST.MF @@ -5,8 +5,9 @@ Bundle-SymbolicName: org.eclipse.ecf.examples.provider.trivial;singleton:=true Bundle-Version: 1.0.200.provider Bundle-Activator: org.eclipse.ecf.internal.examples.provider.trivial.Activator Bundle-Vendor: %bundle.provider -Require-Bundle: org.eclipse.core.runtime, - org.eclipse.ecf +Require-Bundle: org.eclipse.ecf, + org.eclipse.equinox.common;bundle-version="3.6.200", + org.eclipse.equinox.registry;bundle-version="3.5.400";resolution:=optional Eclipse-LazyStart: true Bundle-ActivationPolicy: lazy Bundle-RequiredExecutionEnvironment: CDC-1.1/Foundation-1.1, @@ -16,3 +17,4 @@ Export-Package: org.eclipse.ecf.examples.provider.trivial;version="1.0.0", org.eclipse.ecf.internal.examples.provider.trivial;x-internal:=true, org.eclipse.ecf.internal.examples.provider.trivial.container;x-internal:=true Bundle-Localization: bundle +Import-Package: org.osgi.framework diff --git a/examples/bundles/org.eclipse.ecf.examples.provider.trivial/plugin.xml b/examples/bundles/org.eclipse.ecf.examples.provider.trivial/plugin.xml index 7ace60c3d..4f21bafb2 100644 --- a/examples/bundles/org.eclipse.ecf.examples.provider.trivial/plugin.xml +++ b/examples/bundles/org.eclipse.ecf.examples.provider.trivial/plugin.xml @@ -19,17 +19,5 @@ server="false"> </containerFactory> </extension> - <extension - id="Trivial" - point="org.eclipse.core.runtime.applications"> - <application - cardinality="*" - thread="any" - visible="true"> - <run - class="org.eclipse.ecf.examples.provider.trivial.TrivialApplication"> - </run> - </application> - </extension> </plugin> diff --git a/examples/bundles/org.eclipse.ecf.examples.provider.trivial/src/org/eclipse/ecf/examples/provider/trivial/TrivialApplication.java b/examples/bundles/org.eclipse.ecf.examples.provider.trivial/src/org/eclipse/ecf/examples/provider/trivial/TrivialApplication.java deleted file mode 100644 index b34ad23d4..000000000 --- a/examples/bundles/org.eclipse.ecf.examples.provider.trivial/src/org/eclipse/ecf/examples/provider/trivial/TrivialApplication.java +++ /dev/null @@ -1,70 +0,0 @@ -package org.eclipse.ecf.examples.provider.trivial; - -import org.eclipse.ecf.core.IContainer; -import org.eclipse.ecf.core.IContainerFactory; -import org.eclipse.ecf.core.IContainerManager; -import org.eclipse.ecf.core.identity.ID; -import org.eclipse.ecf.core.identity.IDFactory; -import org.eclipse.ecf.core.util.ECFException; -import org.eclipse.equinox.app.IApplication; -import org.eclipse.equinox.app.IApplicationContext; -import org.osgi.util.tracker.ServiceTracker; - -public class TrivialApplication implements IApplication { - - private boolean done = false; - - private ServiceTracker containerManagerTracker; - - public Object start(IApplicationContext context) throws Exception { - try { - IContainerFactory factory = getContainerManager().getContainerFactory(); - // Create instance of trivial container - IContainer container = factory.createContainer("ecf.container.trivial"); - - // Get appropriate container adapter...e.g. IChannelContainerAdapter - // IChannelContainerAdapter containerAdapter = - // (IChannelContainerAdapter) - // container.getAdapter(IChannelContainerAdapter.class); - - // Connect - ID targetID = IDFactory.getDefault().createID( - container.getConnectNamespace(), "myid"); - container.connect(targetID, null); - - synchronized (this) { - while (!done) { - wait(); - } - } - - } catch (ECFException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - return null; - } - - public void stop() { - if (containerManagerTracker != null) { - containerManagerTracker.close(); - containerManagerTracker = null; - } - synchronized (this) { - done = true; - notify(); - } - } - - protected IContainerManager getContainerManager() { - if (containerManagerTracker == null) { - containerManagerTracker = new ServiceTracker( - org.eclipse.ecf.internal.examples.provider.trivial.Activator.getDefault().getContext(), IContainerManager.class.getName(), - null); - containerManagerTracker.open(); - } - return (IContainerManager) containerManagerTracker.getService(); - } - - -} diff --git a/examples/bundles/org.eclipse.ecf.examples.provider.trivial/src/org/eclipse/ecf/examples/provider/trivial/identity/TrivialNamespace.java b/examples/bundles/org.eclipse.ecf.examples.provider.trivial/src/org/eclipse/ecf/examples/provider/trivial/identity/TrivialNamespace.java index 3b7ab1439..907f5436c 100644 --- a/examples/bundles/org.eclipse.ecf.examples.provider.trivial/src/org/eclipse/ecf/examples/provider/trivial/identity/TrivialNamespace.java +++ b/examples/bundles/org.eclipse.ecf.examples.provider.trivial/src/org/eclipse/ecf/examples/provider/trivial/identity/TrivialNamespace.java @@ -21,6 +21,10 @@ public class TrivialNamespace extends Namespace { public static final String SCHEME = "trivial"; public static final String NAME = "ecf.namespace.trivial"; + public TrivialNamespace(String name) { + super(name,null); + } + /* (non-Javadoc) * @see org.eclipse.ecf.core.identity.Namespace#createInstance(java.lang.Object[]) */ diff --git a/examples/bundles/org.eclipse.ecf.examples.provider.trivial/src/org/eclipse/ecf/internal/examples/provider/trivial/Activator.java b/examples/bundles/org.eclipse.ecf.examples.provider.trivial/src/org/eclipse/ecf/internal/examples/provider/trivial/Activator.java index 262938561..d17456b5b 100755 --- a/examples/bundles/org.eclipse.ecf.examples.provider.trivial/src/org/eclipse/ecf/internal/examples/provider/trivial/Activator.java +++ b/examples/bundles/org.eclipse.ecf.examples.provider.trivial/src/org/eclipse/ecf/internal/examples/provider/trivial/Activator.java @@ -1,12 +1,17 @@ package org.eclipse.ecf.internal.examples.provider.trivial; -import org.eclipse.core.runtime.Plugin; +import org.eclipse.core.runtime.IExtensionRegistry; +import org.eclipse.core.runtime.SafeRunner; +import org.eclipse.ecf.core.identity.Namespace; +import org.eclipse.ecf.core.util.ExtensionRegistryRunnable; +import org.eclipse.ecf.examples.provider.trivial.identity.TrivialNamespace; +import org.osgi.framework.BundleActivator; import org.osgi.framework.BundleContext; /** * The activator class controls the plug-in life cycle */ -public class Activator extends Plugin { +public class Activator implements BundleActivator { // The plug-in ID public static final String PLUGIN_ID = "org.eclipse.ecf.internal.examples.provider.trivial"; @@ -27,9 +32,17 @@ public class Activator extends Plugin { * @see org.eclipse.core.runtime.Plugins#start(org.osgi.framework.BundleContext) */ public void start(BundleContext context) throws Exception { - super.start(context); this.context = context; plugin = this; + SafeRunner.run(new ExtensionRegistryRunnable(this.context) { + protected void runWithRegistry(IExtensionRegistry registry) + throws Exception { + // do nothing + } + protected void runWithoutRegistry() throws Exception { + Activator.this.context.registerService(Namespace.class, new TrivialNamespace("ecf.namespace.trivial"), null); + } + }); } /* @@ -38,7 +51,6 @@ public class Activator extends Plugin { */ public void stop(BundleContext context) throws Exception { plugin = null; - super.stop(context); this.context = null; } 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 a4e5f21ff..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 @@ -53,6 +53,8 @@ public class Activator implements BundleActivator { private AdapterManagerTracker adapterManagerTracker; + private ServiceTracker namespacesTracker; + // This is object rather than typed to avoid referencing the // IRegistryChangedListener class directly private Object registryManager; @@ -99,6 +101,28 @@ public class Activator implements BundleActivator { idFactoryServiceRegistration = context.registerService( IIDFactory.class.getName(), IDFactory.getDefault(), null); + 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 { @@ -116,9 +140,41 @@ public class Activator implements BundleActivator { .getConfigurationElements()); break; case IExtensionDelta.REMOVED: - removeNamespaceExtensions(delta[i] + IConfigurationElement[] members = delta[i] .getExtension() - .getConfigurationElements()); + .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; } } @@ -134,39 +190,6 @@ public class Activator implements BundleActivator { return context; } - /** - * Remove extensions for identity namespace extension point - * - * @param members - * the members to remove - */ - 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, - IStatus.ERROR, - "Exception removing namespace", e)); //$NON-NLS-1$ - } - } - } - Bundle getBundle() { if (context == null) return null; @@ -252,8 +275,6 @@ public class Activator implements BundleActivator { * */ public void setupNamespaceExtensionPoint() { - if (context != null) - setupNamespaceServices(); SafeRunner.run(new ExtensionRegistryRunnable(context) { protected void runWithRegistry(IExtensionRegistry registry) throws Exception { @@ -269,34 +290,6 @@ public class Activator implements BundleActivator { }); } - 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 && 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(); - } - } - /* * (non-Javadoc) * |