1 17 18 package org.apache.geronimo.proxy; 19 20 import java.lang.reflect.InvocationHandler ; 21 import java.lang.reflect.Method ; 22 import java.lang.reflect.Proxy ; 23 24 import org.apache.geronimo.core.service.Invocation; 25 import org.apache.geronimo.core.service.InvocationResult; 26 import org.apache.geronimo.core.service.Interceptor; 27 28 37 public class ProxyContainer extends SimpleRPCContainer implements InvocationHandler { 38 39 public ProxyContainer(Interceptor firstInterceptor) { 40 super(firstInterceptor); 41 } 42 43 46 public Object invoke(Object proxy, Method method, Object [] args) throws Throwable { 47 Invocation invocation = new ProxyInvocation(); 48 ProxyInvocation.putMethod(invocation, method); 49 ProxyInvocation.putArguments(invocation, args); 50 ProxyInvocation.putProxy(invocation, proxy); 51 InvocationResult result = this.invoke(invocation); 52 if( result.isException() ) 53 throw result.getException(); 54 return result.getResult(); 55 } 56 57 public Object createProxy(ClassLoader cl, Class [] interfaces) { 58 return Proxy.newProxyInstance(cl, interfaces, this); 59 } 60 61 public static ProxyContainer getContainer(Object proxy) { 62 if (Proxy.isProxyClass(proxy.getClass())) 63 throw new IllegalArgumentException ("Not a proxy."); 64 return (ProxyContainer) Proxy.getInvocationHandler(proxy); 65 } 66 67 } 68 | Popular Tags |