1 22 package org.jboss.aspects.remoting; 23 24 import org.jboss.aop.joinpoint.MethodInvocation; 25 import org.jboss.aop.proxy.ClassProxyFactory; 26 import org.jboss.aop.util.reference.MethodPersistentReference; 27 28 import java.lang.reflect.InvocationTargetException ; 29 import java.lang.reflect.Method ; 30 import java.util.HashMap ; 31 37 public class ForwardingInterceptor implements org.jboss.aop.advice.Interceptor, ClusterConstants 38 { 39 private final Object obj; 40 public ForwardingInterceptor(Object obj) 41 { 42 this.obj = obj; 43 } 44 45 public String getName() { return "ForwardingInterceptor"; } 46 47 public Object invoke(org.jboss.aop.joinpoint.Invocation invocation) throws Throwable 48 { 49 if (invocation instanceof MethodInvocation) 50 { 51 org.jboss.aop.joinpoint.MethodInvocation methodInvocation = (org.jboss.aop.joinpoint.MethodInvocation)invocation; 53 long methodHash = methodInvocation.getMethodHash(); 54 HashMap methodMap = ClassProxyFactory.getMethodMap(obj.getClass()); 55 MethodPersistentReference ref = (MethodPersistentReference)methodMap.get(new Long (methodHash)); 56 Method method = (Method )ref.get(); 57 Object [] args = methodInvocation.getArguments(); 58 try 59 { 60 return method.invoke(obj, args); 61 } 62 catch (InvocationTargetException ex) 63 { 64 throw ex.getTargetException(); 65 } 66 } 67 else 68 { 69 throw new RuntimeException ("field invocations not implemented"); 70 } 71 } 72 } 73 | Popular Tags |