1 package dynaop; 2 3 import java.io.NotSerializableException ; 4 import java.lang.reflect.Method ; 5 6 import net.sf.cglib.MethodInterceptor; 7 import net.sf.cglib.MethodProxy; 8 9 12 class ClassProxyInvocationHandler extends ProxyInvocationHandler 13 implements MethodInterceptor { 14 15 ClassProxyInvocationHandler(ProxyType proxyType) { 16 super(proxyType); 17 } 18 19 22 public Object intercept(Object proxy, Method method, Object [] arguments, 23 MethodProxy methodProxy) throws Throwable { 24 if (method.getDeclaringClass().equals( 26 ClassProxyCreator.WriteReplace.class)) { 27 throw new NotSerializableException ( 28 "Due to a limitation in " 29 + "object serialization, class proxies are not directly " 30 + "serializable. " 31 + "Please write the handle to the stream instead " 32 + "(ProxyContext.getHandle()). Parent class: " 33 + proxy.getClass().getSuperclass().getName()); 34 } 35 36 return invoke(proxy, methodProxy, method, arguments); 37 } 38 39 public boolean isClassProxy() { 40 return true; 41 } 42 43 protected Handle createHandle() { 44 return new CglibProxyHandle(getProxy()); 45 } 46 47 public Object unwrap() { 48 return new CglibProxyHandle(getProxy()).unwrap(); 49 } 50 } 51 | Popular Tags |