KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openejb > util > proxy > ProxyFactory


1 /**
2  * Redistribution and use of this software and associated documentation
3  * ("Software"), with or without modification, are permitted provided
4  * that the following conditions are met:
5  *
6  * 1. Redistributions of source code must retain copyright
7  * statements and notices. Redistributions must also contain a
8  * copy of this document.
9  *
10  * 2. Redistributions in binary form must reproduce the
11  * above copyright notice, this list of conditions and the
12  * following disclaimer in the documentation and/or other
13  * materials provided with the distribution.
14  *
15  * 3. The name "Exolab" must not be used to endorse or promote
16  * products derived from this Software without prior written
17  * permission of Exoffice Technologies. For written permission,
18  * please contact info@exolab.org.
19  *
20  * 4. Products derived from this Software may not be called "Exolab"
21  * nor may "Exolab" appear in their names without prior written
22  * permission of Exoffice Technologies. Exolab is a registered
23  * trademark of Exoffice Technologies.
24  *
25  * 5. Due credit should be given to the Exolab Project
26  * (http://www.exolab.org/).
27  *
28  * THIS SOFTWARE IS PROVIDED BY EXOFFICE TECHNOLOGIES AND CONTRIBUTORS
29  * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
30  * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
31  * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
32  * EXOFFICE TECHNOLOGIES OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
33  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
34  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
35  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
36  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
37  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
38  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
39  * OF THE POSSIBILITY OF SUCH DAMAGE.
40  *
41  * Copyright 1999 (C) Exoffice Technologies Inc. All Rights Reserved.
42  *
43  * $Id: ProxyFactory.java 1096 2004-03-26 21:41:16Z dblevins $
44  */

45 package org.openejb.util.proxy;
46
47 /**
48  * EXAMPLE USAGE
49  *
50  *
51  * ProxyManager.getProxyClass( Customer.class );
52  *
53  *
54  *
55  * CUSTOMER INTERFACE
56  *
57  * public interface Customer extends javax.ejb.EJBObject {
58  *
59  * public boolean setAddress(String street, int x, short y) throws RemoteException;
60  *
61  *
62  *
63  * GENERATED PROXY CLASS
64  *
65  * public class CustomerProxy extends Proxy implements java.io.Serializable,Customer{
66  *
67  * protected static transient java.lang.reflect.Method [] methodMap = new java.lang.reflect.Method[6];
68  *
69  * protected CustomerProxy(){}
70  *
71  * ...// EJBObject methods
72  *
73  * public boolean setAddress( java.lang.String parm0,int parm1,short parm2) throws java.rmi.RemoteException{
74  * // obtain method
75  * java.lang.reflect.Method method = methodMap[5];
76  * if(method == null){
77  * try{
78  * method=Customer.class.getMethod("setAddress",new Class [] { java.lang.String.class,int.class,short.class});
79  * methodMap[5] = method;
80  * }catch(NoSuchMethodException nsme){ throw new RuntimeException();}
81  * }
82  * // package arguments
83  * Object [] args = new Object[3];
84  * args[0] = parm0;
85  * args[1] = new java.lang.Integer(parm1);
86  * args[2] = new java.lang.Short(parm2);
87  *
88  * try{
89  * java.lang.Boolean retval = (java.lang.Boolean)handler.invoke(this,method,args);
90  * return retval.booleanValue( );
91  * }catch(Throwable t){
92  * // rethrow exceptions
93  * if(t instanceof java.rmi.RemoteException)
94  * throw (java.rmi.RemoteException)t;
95  * if(t instanceof RuntimeException)
96  * throw (RuntimeException)t;
97  * else
98  * throw (Error)t;
99  * }
100  * }
101  *
102  * @author David Blevins
103  * @author Richard Monson-Haefel
104  * @author Aaron Mulder (ammulder@alumni.princeton.edu)
105  */

106
107 import java.util.Properties JavaDoc;
108
109 import org.openejb.OpenEJBException;
110
111 public interface ProxyFactory {
112
113     public void init(Properties JavaDoc props) throws OpenEJBException;
114
115     /**
116      * Returns the invocation handler for the specified proxy instance.
117      */

118     public InvocationHandler getInvocationHandler(Object JavaDoc proxy) throws IllegalArgumentException JavaDoc;
119
120     /**
121      * Sets the invocation handler for the specified proxy instance.
122      */

123     public Object JavaDoc setInvocationHandler(Object JavaDoc proxy, InvocationHandler handler) throws IllegalArgumentException JavaDoc;
124
125     /**
126      * Returns the java.lang.Class object for a proxy class given a class loader and an array of interfaces.
127      */

128     public Class JavaDoc getProxyClass(Class JavaDoc interfce) throws IllegalArgumentException JavaDoc;
129
130     /**
131      * Returns the java.lang.Class object for a proxy class given a class loader and an array of interfaces.
132      */

133     public Class JavaDoc getProxyClass(Class JavaDoc[] interfaces) throws IllegalArgumentException JavaDoc;
134
135     /*
136      * Returns true if and only if the specified class was dynamically generated to be a proxy class using the getProxyClass method or the newProxyInstance method.
137      */

138     public boolean isProxyClass(Class JavaDoc cl);
139
140     /*
141      * Returns an instance of a proxy class for the specified interface that dispatches method invocations to
142      * the specified invocation handler.
143      */

144     public Object JavaDoc newProxyInstance(Class JavaDoc interfce, InvocationHandler h) throws IllegalArgumentException JavaDoc;
145
146     /*
147      * Returns an instance of a proxy class for the specified interface that dispatches method invocations to
148      * the specified invocation handler.
149      */

150     public Object JavaDoc newProxyInstance(Class JavaDoc[] interfaces, InvocationHandler h) throws IllegalArgumentException JavaDoc;
151
152     /**
153     * Returns a new proxy instance from the specified proxy class. The
154     * interface(s) implemented by the proxy instance are determined by
155     * the proxy class. The class name may or may not be meaningful,
156     * depending on the implementation.
157     * @throws java.lang.IllegalArgumentException
158     * Occurs when the specified class is not a proxy class.
159     */

160     public Object JavaDoc newProxyInstance(Class JavaDoc proxyClass) throws IllegalArgumentException JavaDoc;
161 }
162
163
Popular Tags