KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > portal > common > util > ProxyInfo


1 /*****************************************
2  * *
3  * JBoss Portal: The OpenSource Portal *
4  * *
5  * Distributable under LGPL license. *
6  * See terms of license at gnu.org. *
7  * *
8  *****************************************/

9 package org.jboss.portal.common.util;
10
11 import java.lang.reflect.Constructor JavaDoc;
12 import java.lang.reflect.InvocationHandler JavaDoc;
13 import java.lang.reflect.InvocationTargetException JavaDoc;
14 import java.lang.reflect.Method JavaDoc;
15
16 /**
17  * Encapsulate info about a proxy and provide a way to instantiate it.
18  *
19  * @author <a HREF="mailto:julien@jboss.org">Julien Viet</a>
20  * @version $Revision: 1.2 $
21  */

22 public class ProxyInfo
23 {
24
25    private static final Class JavaDoc[] EMPTY_SIGNATURE = new Class JavaDoc[0];
26    private static final Class JavaDoc[] EQUALS_SIGNATURE = new Class JavaDoc[]{Object JavaDoc.class};
27    private static final Class JavaDoc[] INVOCATION_HANDLER_SIGNATURE = new Class JavaDoc[]{InvocationHandler JavaDoc.class};
28
29    /** The proxy constructor. */
30    private final Constructor JavaDoc ctor;
31
32    /** The proxy toString method. */
33    private final Method JavaDoc toString;
34
35    /** The proxy hashCode method. */
36    private final Method JavaDoc hashCode;
37
38    /** The proxy equals method. */
39    private final Method JavaDoc equals;
40
41    public ProxyInfo(Class JavaDoc clazz) throws Exception JavaDoc
42    {
43       this.ctor = clazz.getConstructor(INVOCATION_HANDLER_SIGNATURE);
44
45       //
46
toString = Object JavaDoc.class.getMethod("toString", EMPTY_SIGNATURE);
47       hashCode = Object JavaDoc.class.getMethod("hashCode", EMPTY_SIGNATURE);
48       equals = Object JavaDoc.class.getMethod("equals", EQUALS_SIGNATURE);
49    }
50
51    /**
52     * Instantiate a proxy.
53     *
54     * @param handler the invocation handler
55     * @return the proxy
56     */

57    public Object JavaDoc instantiate(InvocationHandler JavaDoc handler) throws IllegalAccessException JavaDoc, InvocationTargetException JavaDoc, InstantiationException JavaDoc
58    {
59       return ctor.newInstance(new Object JavaDoc[]{handler});
60    }
61
62    public Method JavaDoc getToString()
63    {
64       return toString;
65    }
66
67    public Method JavaDoc getHashCode()
68    {
69       return hashCode;
70    }
71
72    public Method JavaDoc getEquals()
73    {
74       return equals;
75    }
76 }
77
Popular Tags