From cbff648d71b1d70372ddd6ae1f04ac90a12b55e3 Mon Sep 17 00:00:00 2001 From: antelder Date: Tue, 24 Jan 2012 12:29:04 +0000 Subject: Change the JMS binding MessageProcessor discovery to use ServiceDiscovery so that additional processors can be added in OSGi git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1235221 13f79535-47bb-0310-9956-ffa450edef68 --- .../jms/provider/JMSMessageProcessorUtil.java | 30 +++++++--------------- 1 file changed, 9 insertions(+), 21 deletions(-) (limited to 'sca-java-2.x/trunk/modules/binding-jms-runtime/src/main/java') diff --git a/sca-java-2.x/trunk/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/JMSMessageProcessorUtil.java b/sca-java-2.x/trunk/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/JMSMessageProcessorUtil.java index 4b96f23d65..4df8ca2353 100644 --- a/sca-java-2.x/trunk/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/JMSMessageProcessorUtil.java +++ b/sca-java-2.x/trunk/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/JMSMessageProcessorUtil.java @@ -24,6 +24,7 @@ import java.lang.reflect.Constructor; import org.apache.tuscany.sca.binding.jms.JMSBinding; import org.apache.tuscany.sca.binding.jms.JMSBindingException; import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.extensibility.ServiceDeclaration; /** * Utility methods to load JMS message processors. @@ -74,32 +75,19 @@ public class JMSMessageProcessorUtil { // } // private static Object instantiate(ClassLoader cl, String className, JMSBinding binding, ExtensionPointRegistry registry) { - Object instance; - if (cl == null) { - cl = binding.getClass().getClassLoader(); - } - try { - Class clazz; - - try { - clazz = cl.loadClass(className); - } catch (ClassNotFoundException e) { - // MJE 07/12/2010 - for OSGi the default message processor belongs to the same bundle as - // this JMSMessageProcessorUtil itself and so the "correct" classloader to use is the classloader - // for THIS class, and not the binding class (which is a different bundle) - // clazz = binding.getClass().getClassLoader().loadClass(className); - clazz = JMSMessageProcessorUtil.class.getClassLoader().loadClass(className); + for (ServiceDeclaration sd : registry.getServiceDiscovery().getServiceDeclarations(JMSMessageProcessor.class)) { + if (className.equals(sd.getClassName())) { + Class clazz = sd.loadClass(); + Constructor constructor = clazz.getDeclaredConstructor(new Class[] {JMSBinding.class, ExtensionPointRegistry.class}); + return constructor.newInstance(binding, registry); + } + } - - Constructor constructor = clazz.getDeclaredConstructor(new Class[] {JMSBinding.class, ExtensionPointRegistry.class}); - instance = constructor.newInstance(binding, registry); - + throw new JMSBindingException("Class not found: " + className); } catch (Throwable e) { throw new JMSBindingException("Exception instantiating OperationAndDataBinding class", e); } - - return instance; } public static JMSMessageProcessor getRequestMessageProcessor(ExtensionPointRegistry registry, JMSBinding binding) { -- cgit v1.2.3