org.openejb.util.proxy
Class DynamicProxyFactory
java.lang.Object
|
+--org.openejb.util.proxy.DynamicProxyFactory
- All Implemented Interfaces:
- ProxyFactory
- public class DynamicProxyFactory
- extends java.lang.Object
- implements ProxyFactory
EXAMPLE USAGE
ProxyManager.getProxyClass( Customer.class );
CUSTOMER INTERFACE
public interface Customer extends javax.ejb.EJBObject {
public boolean setAddress(String street, int x, short y) throws RemoteException;
GENERATED PROXY CLASS
public class CustomerProxy extends Proxy implements java.io.Serializable,Customer{
protected static transient java.lang.reflect.Method [] methodMap = new java.lang.reflect.Method[6];
protected CustomerProxy(){}
...// EJBObject methods
public boolean setAddress( java.lang.String parm0,int parm1,short parm2) throws java.rmi.RemoteException{
// obtain method
java.lang.reflect.Method method = methodMap[5];
if(method == null){
try{
method=Customer.class.getMethod("setAddress",new Class [] { java.lang.String.class,int.class,short.class});
methodMap[5] = method;
}catch(NoSuchMethodException nsme){ throw new RuntimeException();}
}
// package arguments
Object [] args = new Object[3];
args[0] = parm0;
args[1] = new java.lang.Integer(parm1);
args[2] = new java.lang.Short(parm2);
try{
java.lang.Boolean retval = (java.lang.Boolean)handler.invoke(this,method,args);
return retval.booleanValue( );
}catch(Throwable t){
// rethrow exceptions
if(t instanceof java.rmi.RemoteException)
throw (java.rmi.RemoteException)t;
if(t instanceof RuntimeException)
throw (RuntimeException)t;
else
throw (Error)t;
}
}
Method Summary |
byte[] |
generateProxyByteCode(java.lang.String proxyClassName)
|
InvocationHandler |
getInvocationHandler(java.lang.Object proxy)
Returns the invocation handler for the specified proxy instance. |
java.lang.Class |
getProxyClass(java.lang.Class interfce)
Returns the java.lang.Class object for a proxy class given a class loader and an array of interfaces. |
java.lang.Class |
getProxyClass(java.lang.Class[] interfaces)
Returns the java.lang.Class object for a proxy class given a class loader and an array of interfaces. |
void |
init(java.util.Properties props)
|
java.lang.String |
intfcNameToProxyName(java.lang.String interfaceName)
|
boolean |
isProxyClass(java.lang.Class cl)
|
java.lang.Object |
newProxyInstance(java.lang.Class proxyClass)
Returns a new proxy instance from the specified proxy class. |
java.lang.Object |
newProxyInstance(java.lang.Class[] interfaces,
InvocationHandler h)
|
java.lang.Object |
newProxyInstance(java.lang.Class interfce,
InvocationHandler h)
|
protected java.lang.String |
primitiveWrapper(java.lang.Class primitiveClass)
|
java.lang.String |
proxyNameToIntfcName(java.lang.String proxyName)
|
java.lang.Object |
setInvocationHandler(java.lang.Object proxy,
InvocationHandler handler)
Sets the invocation handler for the specified proxy instance and
returns the handler that was previously associated with the proxy instance. |
protected void |
writeDeligationLogic(java.lang.StringBuffer sourceCode,
java.lang.Class intrface,
java.lang.reflect.Method method,
int nextMethodIndex)
|
protected int |
writeMethods(java.lang.StringBuffer sourceCode,
java.lang.Class intrface,
int nextMethodIndex)
|
Methods inherited from class java.lang.Object |
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
loader
public static final ProxyClassLoader loader
DELETE_DEFINITIONS
public boolean DELETE_DEFINITIONS
DynamicProxyFactory
public DynamicProxyFactory()
init
public void init(java.util.Properties props)
throws OpenEJBException
- Specified by:
init
in interface ProxyFactory
getInvocationHandler
public InvocationHandler getInvocationHandler(java.lang.Object proxy)
throws java.lang.IllegalArgumentException
- Returns the invocation handler for the specified proxy instance.
- Specified by:
getInvocationHandler
in interface ProxyFactory
setInvocationHandler
public java.lang.Object setInvocationHandler(java.lang.Object proxy,
InvocationHandler handler)
throws java.lang.IllegalArgumentException
- Sets the invocation handler for the specified proxy instance and
returns the handler that was previously associated with the proxy instance.
- Specified by:
setInvocationHandler
in interface ProxyFactory
getProxyClass
public java.lang.Class getProxyClass(java.lang.Class interfce)
throws java.lang.IllegalArgumentException
- Returns the java.lang.Class object for a proxy class given a class loader and an array of interfaces.
- Specified by:
getProxyClass
in interface ProxyFactory
getProxyClass
public java.lang.Class getProxyClass(java.lang.Class[] interfaces)
throws java.lang.IllegalArgumentException
- Returns the java.lang.Class object for a proxy class given a class loader and an array of interfaces.
- Specified by:
getProxyClass
in interface ProxyFactory
isProxyClass
public boolean isProxyClass(java.lang.Class cl)
- Specified by:
isProxyClass
in interface ProxyFactory
newProxyInstance
public java.lang.Object newProxyInstance(java.lang.Class proxyClass)
throws java.lang.IllegalArgumentException
- Returns a new proxy instance from the specified proxy class. The
interface(s) implemented by the proxy instance are determined by
the proxy class.
- Specified by:
newProxyInstance
in interface ProxyFactory
- Throws:
java.lang.IllegalArgumentException
- Occurs when the specified class is not a proxy class.
newProxyInstance
public java.lang.Object newProxyInstance(java.lang.Class[] interfaces,
InvocationHandler h)
throws java.lang.IllegalArgumentException
- Specified by:
newProxyInstance
in interface ProxyFactory
newProxyInstance
public java.lang.Object newProxyInstance(java.lang.Class interfce,
InvocationHandler h)
throws java.lang.IllegalArgumentException
- Specified by:
newProxyInstance
in interface ProxyFactory
proxyNameToIntfcName
public java.lang.String proxyNameToIntfcName(java.lang.String proxyName)
intfcNameToProxyName
public java.lang.String intfcNameToProxyName(java.lang.String interfaceName)
writeMethods
protected int writeMethods(java.lang.StringBuffer sourceCode,
java.lang.Class intrface,
int nextMethodIndex)
- Parameters:
sourceCode
- intrface
- nextMethodIndex
-
writeDeligationLogic
protected void writeDeligationLogic(java.lang.StringBuffer sourceCode,
java.lang.Class intrface,
java.lang.reflect.Method method,
int nextMethodIndex)
- Parameters:
sourceCode
- intrface
- method
- nextMethodIndex
-
primitiveWrapper
protected java.lang.String primitiveWrapper(java.lang.Class primitiveClass)
- Parameters:
primitiveClass
- - Returns:
-
generateProxyByteCode
public byte[] generateProxyByteCode(java.lang.String proxyClassName)
throws java.lang.IllegalAccessException
- Parameters:
outputPath
- className
- sourceCode
- - Throws:
java.lang.IllegalAccessException
-