1 22 package org.jboss.aspects.asynch; 23 24 import java.io.ObjectStreamException ; 25 import java.io.Serializable ; 26 import java.lang.reflect.InvocationHandler ; 27 import java.lang.reflect.Method ; 28 import java.util.HashMap ; 29 import java.util.Map ; 30 31 import org.jboss.aop.ClassInstanceAdvisor; 32 import org.jboss.aop.InstanceAdvisor; 33 import org.jboss.aop.advice.Interceptor; 34 import org.jboss.aop.instrument.Untransformable; 35 import org.jboss.aop.joinpoint.MethodInvocation; 36 import org.jboss.aop.proxy.Proxy; 37 import org.jboss.aop.util.MethodHashing; 38 import org.jboss.util.id.GUID; 39 40 48 public class FutureInvocationHandler extends Proxy implements InvocationHandler , Untransformable, Serializable 49 { 50 private static final long serialVersionUID = -2343948303742422382L; 51 52 private Map methodMap = new HashMap (); 53 54 public FutureInvocationHandler() 55 { 56 super(); 58 } 59 60 public static Object createFutureProxy(GUID guid, ClassLoader loader, Class [] interfaces) throws Exception 61 { 62 FutureInvocationHandler ih = new FutureInvocationHandler(); 63 ih.instanceAdvisor = new ClassInstanceAdvisor(); 64 ih.mixins = null; 65 ih.interfaces = interfaces; 66 ih.guid = guid; 67 return java.lang.reflect.Proxy.newProxyInstance(loader, interfaces, ih); 68 } 69 70 71 public Object invoke(Object proxy, Method method, Object [] args) throws Throwable 72 { 73 if (method.getName().equals("_getInstanceAdvisor")) 74 { 75 return _getInstanceAdvisor(); 76 } 77 else if (method.getName().equals("_setInstanceAdvisor") && 78 method.getParameterTypes().length == 1 && method.getParameterTypes()[0].equals(InstanceAdvisor.class)) 79 { 80 _setInstanceAdvisor((InstanceAdvisor)args[0]); 81 return null; 82 } 83 84 Interceptor[] interceptors = instanceAdvisor.getInterceptors(); 85 long hash = MethodHashing.calculateHash(method); 86 MethodInvocation invocation = new MethodInvocation(interceptors, hash, method, method, null); 87 invocation.setInstanceResolver(instanceAdvisor.getMetaData()); 88 invocation.setArguments(args); 89 return invocation.invokeNext(); 90 } 91 92 93 97 public Object writeReplace() throws ObjectStreamException 98 { 99 return this; 100 } 101 102 public Map getMethodMap() 103 { 104 return methodMap; 106 } 107 108 109 110 } 111 | Popular Tags |