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.InvocationHandlerInvocationHandlerto enable type compatibility between interface loaded in oneClassLoaderand 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.ObjectcreateProxy(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.Objectinvoke(java.lang.Object proxy, java.lang.reflect.Method method, java.lang.Object[] args)static java.lang.ObjectinvokeMethod(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.ObjectinvokeNoExceptionMethod(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.StringtoString()
-
-
-
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-ClassLoaderof the client.implClassLoader-ClassLoaderof the implementation.- Returns:
- Return value from the
Methodinvocation.
-
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.ThrowableInvokes the implementing method.- Parameters:
implementation- Implementation.methodName- Name of the method.arguments- Arguments for the method.paramTypes- Parameter types for the method.clientClassLoader-ClassLoaderof the client.implClassLoader-ClassLoaderof the implementation.- Returns:
- Return value from the
Methodinvocation. - 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.ClassNotFoundExceptionCreates aProxy.- Parameters:
implementation- Implementation behind theProxy.clientClassLoader-ClassLoaderfor the client.implClassLoader-ClassLoaderfor 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:
toStringin 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:
invokein interfacejava.lang.reflect.InvocationHandler- Throws:
java.lang.Throwable
-
-