1 17 package org.apache.servicemix.components.reflection; 18 19 import java.lang.reflect.InvocationHandler ; 20 import java.lang.reflect.Method ; 21 import java.lang.reflect.Proxy ; 22 23 import javax.jbi.JBIException; 24 import javax.jbi.messaging.InOnly; 25 import javax.jbi.messaging.NormalizedMessage; 26 27 import org.apache.commons.logging.Log; 28 import org.apache.commons.logging.LogFactory; 29 import org.apache.servicemix.components.util.ComponentSupport; 30 import org.apache.servicemix.jbi.RuntimeJBIException; 31 32 38 public class ProxyInOnlyBinding extends ComponentSupport implements InvocationHandler { 39 40 private static final Log log = LogFactory.getLog(ProxyInOnlyBinding.class); 41 42 private ClassLoader cl; 43 private Class [] interfaces; 44 45 public void setTarget(Object target) { 46 setTargetType( target.getClass().getClassLoader(), target.getClass().getInterfaces()); 47 } 48 49 private void setTargetType(ClassLoader classLoader, Class [] interfaces) { 50 this.cl = classLoader; 51 this.interfaces = interfaces; 52 } 53 54 public Object createProxy() { 55 return Proxy.newProxyInstance(cl, interfaces, this); 56 } 57 58 public Object invoke(Object proxy, Method method, Object [] args) throws Throwable { 59 if (log.isTraceEnabled()) { 60 log.trace("Invoked: " + method); 61 } 62 try { 63 InOnly messageExchange = getDeliveryChannel().createExchangeFactory().createInOnlyExchange(); 64 NormalizedMessage inMessage = messageExchange.createMessage(); 65 if( proxy != null ) 66 inMessage.setProperty("proxy", proxy); 67 inMessage.setProperty("method", method); 68 if( args!= null ) 69 inMessage.setProperty("args", args); 70 71 messageExchange.setInMessage(inMessage); 72 getDeliveryChannel().send(messageExchange); 73 return null; 74 } 75 catch (JBIException e) { 76 throw new RuntimeJBIException(e); 77 } 78 } 79 } 80 | Popular Tags |