Class TypeAdapter
java.lang.Object
net.officefloor.compile.impl.adapt.TypeAdapter
- All Implemented Interfaces:
InvocationHandler
InvocationHandler to enable type compatibility between interface
loaded in one ClassLoader and implementation in another. This is
overcomes the assignable issues while still allowing invocation (via
reflection internally).- Author:
- Daniel Sagenschneider
-
Method Summary
Modifier and TypeMethodDescriptionstatic ObjectcreateProxy(Object implementation, ClassLoader clientClassLoader, ClassLoader implClassLoader, Class<?>... interfaceTypes) Creates aProxy.static Class<?>[]getInterfaces(Class<?> clazz) Obtains the implementing interfaces theClass.static ObjectinvokeMethod(Object implementation, String methodName, Object[] arguments, Class<?>[] paramTypes, ClassLoader clientClassLoader, ClassLoader implClassLoader) Invokes the implementing method.static ObjectinvokeNoExceptionMethod(Object implementation, String methodName, Object[] arguments, Class<?>[] paramTypes, ClassLoader clientClassLoader, ClassLoader implClassLoader) Invokes the method expecting noException.toString()
-
Method Details
-
invokeNoExceptionMethod
public static Object invokeNoExceptionMethod(Object implementation, String methodName, Object[] arguments, Class<?>[] paramTypes, ClassLoader clientClassLoader, 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 Object invokeMethod(Object implementation, String methodName, Object[] arguments, Class<?>[] paramTypes, ClassLoader clientClassLoader, ClassLoader implClassLoader) throws 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-ClassLoaderof the client.implClassLoader-ClassLoaderof the implementation.- Returns:
- Return value from the
Methodinvocation. - Throws:
Throwable- If fails to invoke theMethod.
-
getInterfaces
Obtains the implementing interfaces theClass.- Parameters:
clazz-Class.- Returns:
- Implementing interfaces.
-
createProxy
public static Object createProxy(Object implementation, ClassLoader clientClassLoader, ClassLoader implClassLoader, Class<?>... interfaceTypes) throws ClassNotFoundException Creates aProxy.- Parameters:
implementation- Implementation behind theProxy.clientClassLoader-ClassLoaderfor the client.implClassLoader-ClassLoaderfor the implementation.interfaceTypes- Interfaces for theProxy.- Returns:
Proxy.- Throws:
ClassNotFoundException- If fails to load interface type forProxy.
-
toString
-
invoke
- Specified by:
invokein interfaceInvocationHandler- Throws:
Throwable
-