summaryrefslogtreecommitdiffstats
path: root/java/sca/modules/extensibility-equinox/src
diff options
context:
space:
mode:
authorjsdelfino <jsdelfino@13f79535-47bb-0310-9956-ffa450edef68>2008-09-08 03:16:34 +0000
committerjsdelfino <jsdelfino@13f79535-47bb-0310-9956-ffa450edef68>2008-09-08 03:16:34 +0000
commitfe56d619a6e9c5a5a3ed26d61591fd4fb89b4c1f (patch)
treebc63c578f6509d4cf488da99415de6bf091e577b /java/sca/modules/extensibility-equinox/src
parentd6293beb6665b69b91241907d4e735f7d2cc0f26 (diff)
Simplified a bit the service discovery implementation. Some code cleanup in node-launcher-equinox. Started to remove dependencies on a particular setting of the Thread Context ClassLoader.
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@692989 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'java/sca/modules/extensibility-equinox/src')
-rw-r--r--java/sca/modules/extensibility-equinox/src/main/java/org/apache/tuscany/sca/extensibility/equinox/EquinoxServiceDiscoverer.java111
-rw-r--r--java/sca/modules/extensibility-equinox/src/main/java/org/apache/tuscany/sca/extensibility/equinox/EquinoxServiceDiscoveryActivator.java1
2 files changed, 3 insertions, 109 deletions
diff --git a/java/sca/modules/extensibility-equinox/src/main/java/org/apache/tuscany/sca/extensibility/equinox/EquinoxServiceDiscoverer.java b/java/sca/modules/extensibility-equinox/src/main/java/org/apache/tuscany/sca/extensibility/equinox/EquinoxServiceDiscoverer.java
index a07a6ed810..19e212f355 100644
--- a/java/sca/modules/extensibility-equinox/src/main/java/org/apache/tuscany/sca/extensibility/equinox/EquinoxServiceDiscoverer.java
+++ b/java/sca/modules/extensibility-equinox/src/main/java/org/apache/tuscany/sca/extensibility/equinox/EquinoxServiceDiscoverer.java
@@ -28,8 +28,6 @@ import java.security.AccessController;
import java.security.PrivilegedAction;
import java.security.PrivilegedActionException;
import java.security.PrivilegedExceptionAction;
-import java.util.Collections;
-import java.util.Enumeration;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
@@ -44,19 +42,17 @@ import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
/**
- * The ServiceDiscoverer that find META-INF/services/... in installed bundles
+ * A ServiceDiscoverer that find META-INF/services/... in installed bundles
*
* @version $Rev: $ $Date: $
*/
public class EquinoxServiceDiscoverer implements ServiceDiscoverer {
private static final Logger logger = Logger.getLogger(EquinoxServiceDiscoverer.class.getName());
+
private BundleContext context;
- private ClassLoader classLoader;
public EquinoxServiceDiscoverer(BundleContext context) {
this.context = context;
- // http://wiki.eclipse.org/index.php/Context_Class_Loader_Enhancements
- this.classLoader = new ClassLoaderImpl();
}
public static class ServiceDeclarationImpl implements ServiceDeclaration {
@@ -118,87 +114,6 @@ public class EquinoxServiceDiscoverer implements ServiceDiscoverer {
}
- private final static ClassLoader getTCCL() {
- return AccessController.doPrivileged(new PrivilegedAction<ClassLoader>() {
- public ClassLoader run() {
- return Thread.currentThread().getContextClassLoader();
- }
- });
- }
-
- public class ClassLoaderImpl extends ClassLoader {
- private ClassLoader delegate;
-
- public ClassLoaderImpl() {
- super(EquinoxServiceDiscoverer.class.getClassLoader());
- this.delegate = getTCCL();
- }
-
- @Override
- protected Class<?> findClass(String name) throws ClassNotFoundException {
- return delegate.loadClass(name);
- }
-
- /**
- * Open a back-door to expose the META-INF/services resources
- */
- @Override
- protected URL findResource(String name) {
- int index = name.lastIndexOf('/');
- if (index == -1) {
- return null;
- }
- String path = name.substring(0, index);
- if (path.startsWith("/")) {
- path = path.substring(1);
- }
-
- if (!path.startsWith("META-INF/services")) {
- return null;
- }
-
- for (Bundle bundle : context.getBundles()) {
- URL url = bundle.getEntry(name);
- if (url != null) {
- return url;
- }
- }
-
- return null;
- }
-
- /**
- * Open a back-door to expose the META-INF/services resources
- */
- @Override
- protected Enumeration<URL> findResources(String name) throws IOException {
- int index = name.lastIndexOf('/');
- if (index == -1) {
- return null;
- }
- String path = name.substring(0, index);
- String file = name.substring(index + 1);
- if (path.startsWith("/")) {
- path = path.substring(1);
- }
-
- if (!path.startsWith("META-INF/services")) {
- return null;
- }
-
- Set<URL> urlSet = new HashSet<URL>();
-
- for (Bundle bundle : context.getBundles()) {
- Enumeration<URL> urls = bundle.findEntries(path, file, false);
- if (urls != null) {
- urlSet.addAll(Collections.list(urls));
- }
- }
- return Collections.enumeration(urlSet);
- }
-
- }
-
private static String toString(Bundle b) {
StringBuffer sb = new StringBuffer();
sb.append(b.getBundleId()).append(" ").append(b.getSymbolicName());
@@ -232,7 +147,7 @@ public class EquinoxServiceDiscoverer implements ServiceDiscoverer {
* @param declaration
* @return a map of attributes
*/
- protected static Map<String, String> parseServiceDeclaration(String declaration) {
+ private static Map<String, String> parseServiceDeclaration(String declaration) {
Map<String, String> attributes = new HashMap<String, String>();
int index = declaration.indexOf(';');
if (index != -1) {
@@ -260,20 +175,13 @@ public class EquinoxServiceDiscoverer implements ServiceDiscoverer {
return attributes;
}
- @SuppressWarnings("unchecked")
public Set<ServiceDeclaration> discover(String serviceName, boolean firstOnly) {
boolean debug = logger.isLoggable(Level.FINE);
Set<ServiceDeclaration> descriptors = new HashSet<ServiceDeclaration>();
serviceName = "META-INF/services/" + serviceName;
- // int index = serviceName.lastIndexOf('/');
- // String path = serviceName.substring(0, index);
- // String file = serviceName.substring(index + 1);
-
for (Bundle bundle : context.getBundles()) {
- // Enumeration<URL> urls = bundle.findEntries(path, file, false);
- // Enumeration<URL> urls = bundle.findEntries(path, file, false); // This is expensive
final URL url = bundle.getEntry(serviceName);
if (url == null) {
continue;
@@ -338,19 +246,6 @@ public class EquinoxServiceDiscoverer implements ServiceDiscoverer {
}
}
return descriptors;
-
- }
-
- /**
- * This class loader can be set as the thread context class loader for non-OSGi code
- * @return
- */
- public ClassLoader getContextClassLoader() {
- return classLoader;
- }
-
- public <T> T getContext() {
- return (T)context;
}
}
diff --git a/java/sca/modules/extensibility-equinox/src/main/java/org/apache/tuscany/sca/extensibility/equinox/EquinoxServiceDiscoveryActivator.java b/java/sca/modules/extensibility-equinox/src/main/java/org/apache/tuscany/sca/extensibility/equinox/EquinoxServiceDiscoveryActivator.java
index 0bd1c37113..1cb1d09f8d 100644
--- a/java/sca/modules/extensibility-equinox/src/main/java/org/apache/tuscany/sca/extensibility/equinox/EquinoxServiceDiscoveryActivator.java
+++ b/java/sca/modules/extensibility-equinox/src/main/java/org/apache/tuscany/sca/extensibility/equinox/EquinoxServiceDiscoveryActivator.java
@@ -38,7 +38,6 @@ public class EquinoxServiceDiscoveryActivator implements BundleActivator {
EquinoxServiceDiscoverer discoverer = new EquinoxServiceDiscoverer(context);
ServiceDiscovery.getInstance().setServiceDiscoverer(discoverer);
logger.info("Installed service discovery");
- Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
}
public void stop(BundleContext context) throws Exception {