diff options
Diffstat (limited to '')
6 files changed, 20 insertions, 10 deletions
diff --git a/sca-java-2.x/trunk/modules/extensibility/src/main/java/org/apache/tuscany/sca/core/DefaultExtensionPointRegistry.java b/sca-java-2.x/trunk/modules/extensibility/src/main/java/org/apache/tuscany/sca/core/DefaultExtensionPointRegistry.java index 3ffe893553..57ef069e4f 100644 --- a/sca-java-2.x/trunk/modules/extensibility/src/main/java/org/apache/tuscany/sca/core/DefaultExtensionPointRegistry.java +++ b/sca-java-2.x/trunk/modules/extensibility/src/main/java/org/apache/tuscany/sca/core/DefaultExtensionPointRegistry.java @@ -50,7 +50,7 @@ public class DefaultExtensionPointRegistry implements ExtensionPointRegistry { this.discovery = ServiceDiscovery.getInstance(); } - protected DefaultExtensionPointRegistry(ServiceDiscovery discovery) { + public DefaultExtensionPointRegistry(ServiceDiscovery discovery) { this.discovery = discovery; } diff --git a/sca-java-2.x/trunk/modules/extensibility/src/main/java/org/apache/tuscany/sca/extensibility/ContextClassLoaderServiceDiscoverer.java b/sca-java-2.x/trunk/modules/extensibility/src/main/java/org/apache/tuscany/sca/extensibility/ContextClassLoaderServiceDiscoverer.java index 4e997f4f8b..eec4ff1734 100644 --- a/sca-java-2.x/trunk/modules/extensibility/src/main/java/org/apache/tuscany/sca/extensibility/ContextClassLoaderServiceDiscoverer.java +++ b/sca-java-2.x/trunk/modules/extensibility/src/main/java/org/apache/tuscany/sca/extensibility/ContextClassLoaderServiceDiscoverer.java @@ -115,17 +115,25 @@ public class ContextClassLoaderServiceDiscoverer implements ServiceDiscoverer { this.classLoaderReference = new WeakReference<ClassLoader>(classLoader); } + public ContextClassLoaderServiceDiscoverer(ClassLoader classLoader) { + if (classLoader == null) { + classLoader = Thread.currentThread().getContextClassLoader(); + } + this.classLoaderReference = new WeakReference<ClassLoader>(classLoader); + } + public ClassLoader getContextClassLoader() { //return classLoaderReference.get(); return Thread.currentThread().getContextClassLoader(); } - private List<URL> getResources(final String name) throws IOException { + private Collection<URL> getResources(final String name) throws IOException { try { - return AccessController.doPrivileged(new PrivilegedExceptionAction<List<URL>>() { - public List<URL> run() throws IOException { + return AccessController.doPrivileged(new PrivilegedExceptionAction<Collection<URL>>() { + public Collection<URL> run() throws IOException { List<URL> urls = Collections.list(classLoaderReference.get().getResources(name)); - return urls; + // Eliminate the duplicate URLs (which can be found from child/parent classloaders) + return new HashSet<URL>(urls); } }); } catch (PrivilegedActionException e) { diff --git a/sca-java-2.x/trunk/modules/extensibility/src/main/java/org/apache/tuscany/sca/extensibility/ServiceDiscovery.java b/sca-java-2.x/trunk/modules/extensibility/src/main/java/org/apache/tuscany/sca/extensibility/ServiceDiscovery.java index 00a037b4ed..204d17195b 100644 --- a/sca-java-2.x/trunk/modules/extensibility/src/main/java/org/apache/tuscany/sca/extensibility/ServiceDiscovery.java +++ b/sca-java-2.x/trunk/modules/extensibility/src/main/java/org/apache/tuscany/sca/extensibility/ServiceDiscovery.java @@ -83,7 +83,7 @@ public final class ServiceDiscovery implements ServiceDiscoverer { } } catch (Throwable e) { } - discoverer = new ContextClassLoaderServiceDiscoverer(); + discoverer = new ContextClassLoaderServiceDiscoverer(getClass().getClassLoader()); return discoverer; } diff --git a/sca-java-2.x/trunk/modules/node-api/src/main/java/org/apache/tuscany/sca/node/NodeFactory.java b/sca-java-2.x/trunk/modules/node-api/src/main/java/org/apache/tuscany/sca/node/NodeFactory.java index 22f021d298..4083b4c0b4 100644 --- a/sca-java-2.x/trunk/modules/node-api/src/main/java/org/apache/tuscany/sca/node/NodeFactory.java +++ b/sca-java-2.x/trunk/modules/node-api/src/main/java/org/apache/tuscany/sca/node/NodeFactory.java @@ -472,6 +472,8 @@ public abstract class NodeFactory extends DefaultNodeConfigurationFactory { } public void destroy() { + count = 0; + instance = null; } /** diff --git a/sca-java-2.x/trunk/modules/web-javascript/src/main/java/org/apache/tuscany/sca/web/javascript/DefaultComponentJavaScriptGeneratorExtensionPoint.java b/sca-java-2.x/trunk/modules/web-javascript/src/main/java/org/apache/tuscany/sca/web/javascript/DefaultComponentJavaScriptGeneratorExtensionPoint.java index 51f243ebcf..55326b539e 100644 --- a/sca-java-2.x/trunk/modules/web-javascript/src/main/java/org/apache/tuscany/sca/web/javascript/DefaultComponentJavaScriptGeneratorExtensionPoint.java +++ b/sca-java-2.x/trunk/modules/web-javascript/src/main/java/org/apache/tuscany/sca/web/javascript/DefaultComponentJavaScriptGeneratorExtensionPoint.java @@ -32,7 +32,6 @@ import javax.xml.namespace.QName; import org.apache.tuscany.sca.core.ExtensionPointRegistry; import org.apache.tuscany.sca.core.UtilityExtensionPoint; import org.apache.tuscany.sca.extensibility.ServiceDeclaration; -import org.apache.tuscany.sca.extensibility.ServiceDiscovery; import org.apache.tuscany.sca.monitor.Monitor; import org.apache.tuscany.sca.monitor.MonitorFactory; @@ -127,7 +126,7 @@ public class DefaultComponentJavaScriptGeneratorExtensionPoint implements Compon // Get the proxy factories declarations Collection<ServiceDeclaration> factoryDeclarations = null; try { - factoryDeclarations = ServiceDiscovery.getInstance().getServiceDeclarations(ComponentJavaScriptGenerator.class); + factoryDeclarations = extensionPoints.getServiceDiscovery().getServiceDeclarations(ComponentJavaScriptGenerator.class); } catch (IOException e) { IllegalStateException ie = new IllegalStateException(e); error("IllegalStateException", factoryDeclarations, ie); diff --git a/sca-java-2.x/trunk/modules/web-javascript/src/main/java/org/apache/tuscany/sca/web/javascript/DefaultJavascriptProxyFactoryExtensionPoint.java b/sca-java-2.x/trunk/modules/web-javascript/src/main/java/org/apache/tuscany/sca/web/javascript/DefaultJavascriptProxyFactoryExtensionPoint.java index 60f69615ed..402eb53bb0 100644 --- a/sca-java-2.x/trunk/modules/web-javascript/src/main/java/org/apache/tuscany/sca/web/javascript/DefaultJavascriptProxyFactoryExtensionPoint.java +++ b/sca-java-2.x/trunk/modules/web-javascript/src/main/java/org/apache/tuscany/sca/web/javascript/DefaultJavascriptProxyFactoryExtensionPoint.java @@ -45,10 +45,11 @@ public class DefaultJavascriptProxyFactoryExtensionPoint implements JavascriptPr private final Map<Class<?>, JavascriptProxyFactory> factoriesByType = new HashMap<Class<?>, JavascriptProxyFactory>(); private Monitor monitor = null; - + private ExtensionPointRegistry registry; private boolean loaded = false; public DefaultJavascriptProxyFactoryExtensionPoint(ExtensionPointRegistry extensionPoints) { + this.registry = extensionPoints; UtilityExtensionPoint utilities = extensionPoints.getExtensionPoint(UtilityExtensionPoint.class); MonitorFactory monitorFactory = utilities.getUtility(MonitorFactory.class); if (monitorFactory != null) { @@ -116,7 +117,7 @@ public class DefaultJavascriptProxyFactoryExtensionPoint implements JavascriptPr if (bindingType.isInterface()) { // Dynamically load a factory class declared under META-INF/services try { - Class<?> factoryClass = ServiceDiscovery.getInstance().getServiceDeclaration(bindingType).getClass(); + Class<?> factoryClass = registry.getServiceDiscovery().getServiceDeclaration(bindingType).getClass(); if (factoryClass != null) { try { |