Class TypeAdapter
- java.lang.Object
-
- net.officefloor.compile.impl.adapt.TypeAdapter
-
- All Implemented Interfaces:
java.lang.reflect.InvocationHandler
public class TypeAdapter extends java.lang.Object implements java.lang.reflect.InvocationHandler
InvocationHandler
to enable type compatibility between interface loaded in oneClassLoader
and implementation in another. This is overcomes the assignable issues while still allowing invocation (via reflection internally).- Author:
- Daniel Sagenschneider
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static java.lang.Object
createProxy(java.lang.Object implementation, java.lang.ClassLoader clientClassLoader, java.lang.ClassLoader implClassLoader, java.lang.Class<?>... interfaceTypes)
Creates aProxy
.static java.lang.Class<?>[]
getInterfaces(java.lang.Class<?> clazz)
Obtains the implementing interfaces theClass
.java.lang.Object
invoke(java.lang.Object proxy, java.lang.reflect.Method method, java.lang.Object[] args)
static java.lang.Object
invokeMethod(java.lang.Object implementation, java.lang.String methodName, java.lang.Object[] arguments, java.lang.Class<?>[] paramTypes, java.lang.ClassLoader clientClassLoader, java.lang.ClassLoader implClassLoader)
Invokes the implementing method.static java.lang.Object
invokeNoExceptionMethod(java.lang.Object implementation, java.lang.String methodName, java.lang.Object[] arguments, java.lang.Class<?>[] paramTypes, java.lang.ClassLoader clientClassLoader, java.lang.ClassLoader implClassLoader)
Invokes the method expecting noException
.java.lang.String
toString()
-
-
-
Method Detail
-
invokeNoExceptionMethod
public static java.lang.Object invokeNoExceptionMethod(java.lang.Object implementation, java.lang.String methodName, java.lang.Object[] arguments, java.lang.Class<?>[] paramTypes, java.lang.ClassLoader clientClassLoader, java.lang.ClassLoader implClassLoader)
Invokes the method expecting noException
.- Parameters:
implementation
- Implementation.methodName
- Name of the method.arguments
- Arguments for the method.paramTypes
- Parameter types for the method. May benull
.clientClassLoader
-ClassLoader
of the client.implClassLoader
-ClassLoader
of the implementation.- Returns:
- Return value from the
Method
invocation.
-
invokeMethod
public static java.lang.Object invokeMethod(java.lang.Object implementation, java.lang.String methodName, java.lang.Object[] arguments, java.lang.Class<?>[] paramTypes, java.lang.ClassLoader clientClassLoader, java.lang.ClassLoader implClassLoader) throws java.lang.Throwable
Invokes the implementing method.- Parameters:
implementation
- Implementation.methodName
- Name of the method.arguments
- Arguments for the method.paramTypes
- Parameter types for the method.clientClassLoader
-ClassLoader
of the client.implClassLoader
-ClassLoader
of the implementation.- Returns:
- Return value from the
Method
invocation. - Throws:
java.lang.Throwable
- If fails to invoke theMethod
.
-
getInterfaces
public static java.lang.Class<?>[] getInterfaces(java.lang.Class<?> clazz)
Obtains the implementing interfaces theClass
.- Parameters:
clazz
-Class
.- Returns:
- Implementing interfaces.
-
createProxy
public static java.lang.Object createProxy(java.lang.Object implementation, java.lang.ClassLoader clientClassLoader, java.lang.ClassLoader implClassLoader, java.lang.Class<?>... interfaceTypes) throws java.lang.ClassNotFoundException
Creates aProxy
.- Parameters:
implementation
- Implementation behind theProxy
.clientClassLoader
-ClassLoader
for the client.implClassLoader
-ClassLoader
for the implementation.interfaceTypes
- Interfaces for theProxy
.- Returns:
Proxy
.- Throws:
java.lang.ClassNotFoundException
- If fails to load interface type forProxy
.
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
invoke
public java.lang.Object invoke(java.lang.Object proxy, java.lang.reflect.Method method, java.lang.Object[] args) throws java.lang.Throwable
- Specified by:
invoke
in interfacejava.lang.reflect.InvocationHandler
- Throws:
java.lang.Throwable
-
-