diff options
author | jsdelfino <jsdelfino@13f79535-47bb-0310-9956-ffa450edef68> | 2008-10-29 00:23:03 +0000 |
---|---|---|
committer | jsdelfino <jsdelfino@13f79535-47bb-0310-9956-ffa450edef68> | 2008-10-29 00:23:03 +0000 |
commit | 5426c4171f7b1d71c8418d285495165020be808f (patch) | |
tree | bfca2495de022ff464ac6c87fbcaf6e7308deb95 /branches/sca-equinox/modules/extensibility/src/main | |
parent | 27f56f3694bd23af2812a78a2ca737d6d7544516 (diff) |
Fixed algorithm used to discover and instantiate factories as it wouldn't work with abstract factories like WSDLFactory for example. Removed unused methods.
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@708744 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'branches/sca-equinox/modules/extensibility/src/main')
2 files changed, 31 insertions, 37 deletions
diff --git a/branches/sca-equinox/modules/extensibility/src/main/java/org/apache/tuscany/sca/core/DefaultFactoryExtensionPoint.java b/branches/sca-equinox/modules/extensibility/src/main/java/org/apache/tuscany/sca/core/DefaultFactoryExtensionPoint.java index f5041866ee..cd7bb504c9 100644 --- a/branches/sca-equinox/modules/extensibility/src/main/java/org/apache/tuscany/sca/core/DefaultFactoryExtensionPoint.java +++ b/branches/sca-equinox/modules/extensibility/src/main/java/org/apache/tuscany/sca/core/DefaultFactoryExtensionPoint.java @@ -85,14 +85,6 @@ public class DefaultFactoryExtensionPoint implements FactoryExtensionPoint { } } - private ClassLoader getContextClassLoader() { - return AccessController.doPrivileged(new PrivilegedAction<ClassLoader>() { - public ClassLoader run() { - return Thread.currentThread().getContextClassLoader(); - } - }); - } - private ClassLoader setContextClassLoader(final ClassLoader classLoader) { return AccessController.doPrivileged(new PrivilegedAction<ClassLoader>() { public ClassLoader run() { @@ -119,30 +111,18 @@ public class DefaultFactoryExtensionPoint implements FactoryExtensionPoint { if (factoryDeclaration != null) { Class<?> factoryClass = factoryDeclaration.loadClass(); try { - if (!factoryInterface.isInterface() && Modifier.isAbstract(factoryInterface.getModifiers())) { - try { - Method newInstanceMethod = factoryInterface.getDeclaredMethod("newInstance"); - ClassLoader tccl = setContextClassLoader(factoryClass.getClassLoader()); - try { - factory = newInstanceMethod.invoke(null); - factories.put(factoryInterface, factory); - return factoryInterface.cast(factory); - } finally { - setContextClassLoader(tccl); - } - } catch (NoSuchMethodException e) { - // Ignore - } - } + // Default empty constructor Constructor<?> constructor = factoryClass.getConstructor(); factory = constructor.newInstance(); } catch (NoSuchMethodException e) { try { + // Constructor taking the model factory extension point Constructor<?> constructor = factoryClass.getConstructor(FactoryExtensionPoint.class); factory = constructor.newInstance(this); } catch (NoSuchMethodException e1) { + // Constructor taking the extension point registry Constructor<?> constructor = factoryClass.getConstructor(ExtensionPointRegistry.class); factory = constructor.newInstance(extensionPointRegistry); @@ -151,12 +131,39 @@ public class DefaultFactoryExtensionPoint implements FactoryExtensionPoint { // Cache the loaded factory factories.put(factoryInterface, factory); + + return factoryInterface.cast(factory); + + } else { + + // If the input interface is an abstract class + if (!factoryInterface.isInterface() && Modifier.isAbstract(factoryInterface.getModifiers())) { + Method newInstanceMethod = factoryInterface.getDeclaredMethod("newInstance"); + ClassLoader tccl = setContextClassLoader(factoryInterface.getClassLoader()); + try { + + // Create a new instance + factory = newInstanceMethod.invoke(null); + + // Cache the factory + factories.put(factoryInterface, factory); + + return factoryInterface.cast(factory); + } finally { + setContextClassLoader(tccl); + } + } else { + + // Sorry no factory found + return null; + } } } catch (Exception e) { throw new IllegalArgumentException(e); } + } else { + return factoryInterface.cast(factory); } - return factoryInterface.cast(factory); } } diff --git a/branches/sca-equinox/modules/extensibility/src/main/java/org/apache/tuscany/sca/extensibility/ServiceDiscovery.java b/branches/sca-equinox/modules/extensibility/src/main/java/org/apache/tuscany/sca/extensibility/ServiceDiscovery.java index 70532452b2..84e7b0e3b5 100644 --- a/branches/sca-equinox/modules/extensibility/src/main/java/org/apache/tuscany/sca/extensibility/ServiceDiscovery.java +++ b/branches/sca-equinox/modules/extensibility/src/main/java/org/apache/tuscany/sca/extensibility/ServiceDiscovery.java @@ -85,17 +85,4 @@ public class ServiceDiscovery implements ServiceDiscoverer { return service; } - public Object newFactoryClassInstance(String name) { - try { - ServiceDeclaration declaration = getFirstServiceDeclaration(name); - if (declaration == null) { - return null; - } - Class<?> factoryClass = declaration.loadClass(); - return factoryClass.newInstance(); - } catch (Exception e) { - throw new IllegalArgumentException(e); - } - } - } |