diff options
author | rfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68> | 2009-05-20 19:12:20 +0000 |
---|---|---|
committer | rfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68> | 2009-05-20 19:12:20 +0000 |
commit | af939977016abf2ca84a0fe8b1a418dffa7c0f58 (patch) | |
tree | 4e28d35b7d3887b645c5fc116e54d0ab7f5ac066 /java/sca/modules | |
parent | 12bcceffb26ab805a7b0686daf21dbfb7f5a12be (diff) |
Make sure the bundle is started when a service is registered
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@776808 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'java/sca/modules')
-rw-r--r-- | java/sca/modules/extensibility-equinox/src/main/java/org/apache/tuscany/sca/extensibility/equinox/OSGiExtensionPointRegistry.java | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/java/sca/modules/extensibility-equinox/src/main/java/org/apache/tuscany/sca/extensibility/equinox/OSGiExtensionPointRegistry.java b/java/sca/modules/extensibility-equinox/src/main/java/org/apache/tuscany/sca/extensibility/equinox/OSGiExtensionPointRegistry.java index 07bf4dc18e..a84268cc69 100644 --- a/java/sca/modules/extensibility-equinox/src/main/java/org/apache/tuscany/sca/extensibility/equinox/OSGiExtensionPointRegistry.java +++ b/java/sca/modules/extensibility-equinox/src/main/java/org/apache/tuscany/sca/extensibility/equinox/OSGiExtensionPointRegistry.java @@ -20,12 +20,15 @@ package org.apache.tuscany.sca.extensibility.equinox;
import java.util.Dictionary;
+import java.util.Hashtable;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry;
import org.apache.tuscany.sca.extensibility.ServiceDeclaration;
+import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
+import org.osgi.framework.BundleException;
import org.osgi.framework.ServiceReference;
import org.osgi.framework.ServiceRegistration;
@@ -67,9 +70,22 @@ public class OSGiExtensionPointRegistry extends DefaultExtensionPointRegistry { if (declaration instanceof EquinoxServiceDiscoverer.ServiceDeclarationImpl) {
EquinoxServiceDiscoverer.ServiceDeclarationImpl declarationImpl =
(EquinoxServiceDiscoverer.ServiceDeclarationImpl)declaration;
- context = declarationImpl.getBundle().getBundleContext();
+ Bundle bundle = declarationImpl.getBundle();
+ /**
+ * If this bundle is not in the STARTING, ACTIVE, or STOPPING states or this bundle
+ * is a fragment bundle, then this bundle has no valid BundleContext. This method will
+ * return null if this bundle has no valid BundleContext
+ */
+ if ((bundle.getState() & (Bundle.ACTIVE | Bundle.STARTING)) == 0) {
+ try {
+ bundle.start();
+ } catch (BundleException e) {
+ throw new IllegalStateException(e);
+ }
+ }
+ context = bundle.getBundleContext();
}
- Dictionary<Object, Object> props = new java.util.Hashtable<Object, Object>();
+ Dictionary<Object, Object> props = new Hashtable<Object, Object>();
ServiceRegistration registration = context.registerService(i.getName(), extensionPoint, props);
services.put(i, registration);
}
|