1 22 package org.jboss.aspects.versioned; 23 24 import org.jboss.aop.Advised; 25 import org.jboss.aop.ClassAdvisor; 26 import org.jboss.aop.joinpoint.MethodInvocation; 27 import org.jboss.aop.proxy.ClassProxyFactory; 28 import org.jboss.aop.util.reference.MethodPersistentReference; 29 30 import java.lang.reflect.InvocationTargetException ; 31 import java.lang.reflect.Method ; 32 import java.util.HashMap ; 33 39 public class VersionedObjectForwardingInterceptor implements org.jboss.aop.advice.Interceptor 40 { 41 public VersionedObjectForwardingInterceptor() 42 { 43 } 44 45 public String getName() { return "VersionedObjectForwardingInterceptor"; } 46 47 public Object invoke(org.jboss.aop.joinpoint.Invocation invocation) throws Throwable 48 { 49 Object target = invocation.getTargetObject(); 50 if (target instanceof Advised) 51 { 52 ClassAdvisor advisor = (ClassAdvisor)((Advised)target)._getAdvisor(); 53 return advisor.invoke(invocation); 56 } 57 else 58 { 59 if (invocation instanceof MethodInvocation) 60 { 61 org.jboss.aop.joinpoint.MethodInvocation methodInvocation = (org.jboss.aop.joinpoint.MethodInvocation)invocation; 63 long methodHash = methodInvocation.getMethodHash(); 64 HashMap methodMap = ClassProxyFactory.getMethodMap(target.getClass()); 65 MethodPersistentReference ref = (MethodPersistentReference)methodMap.get(new Long (methodHash)); 66 Method method = (Method )ref.get(); 67 Object [] args = methodInvocation.getArguments(); 68 try 69 { 70 return method.invoke(target, args); 71 } 72 catch (InvocationTargetException ex) 73 { 74 throw ex.getTargetException(); 75 } 76 } 77 else 78 { 79 throw new RuntimeException ("should only be METHOD invocations on a non-advised target object: " + invocation.getClass().getName()); 80 } 81 } 82 } 83 } 84 | Popular Tags |