KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > dynaop > ClassProxyInvocationHandler


1 package dynaop;
2
3 import java.io.NotSerializableException JavaDoc;
4 import java.lang.reflect.Method JavaDoc;
5
6 import net.sf.cglib.MethodInterceptor;
7 import net.sf.cglib.MethodProxy;
8
9 /**
10  * @author Bob Lee (crazybob@crazybob.org)
11  */

12 class ClassProxyInvocationHandler extends ProxyInvocationHandler
13         implements MethodInterceptor {
14
15     ClassProxyInvocationHandler(ProxyType proxyType) {
16         super(proxyType);
17     }
18     
19     /**
20      * Class proxy invocation handler.
21      */

22     public Object JavaDoc intercept(Object JavaDoc proxy, Method JavaDoc method, Object JavaDoc[] arguments,
23             MethodProxy methodProxy) throws Throwable JavaDoc {
24         // handle writeReplace().
25
if (method.getDeclaringClass().equals(
26                 ClassProxyCreator.WriteReplace.class)) {
27             throw new NotSerializableException JavaDoc(
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 JavaDoc unwrap() {
48         return new CglibProxyHandle(getProxy()).unwrap();
49     }
50 }
51
Popular Tags