Class TypeAdapter

java.lang.Object
net.officefloor.compile.impl.adapt.TypeAdapter
All Implemented Interfaces:
InvocationHandler

public class TypeAdapter extends Object implements 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 Details

    • invokeNoExceptionMethod

      public static Object invokeNoExceptionMethod(Object implementation, String methodName, Object[] arguments, Class<?>[] paramTypes, ClassLoader clientClassLoader, ClassLoader implClassLoader)
      Invokes the method expecting no Exception.
      Parameters:
      implementation - Implementation.
      methodName - Name of the method.
      arguments - Arguments for the method.
      paramTypes - Parameter types for the method. May be null.
      clientClassLoader - ClassLoader of the client.
      implClassLoader - ClassLoader of the implementation.
      Returns:
      Return value from the Method invocation.
    • 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 - ClassLoader of the client.
      implClassLoader - ClassLoader of the implementation.
      Returns:
      Return value from the Method invocation.
      Throws:
      Throwable - If fails to invoke the Method.
    • getInterfaces

      public static Class<?>[] getInterfaces(Class<?> clazz)
      Obtains the implementing interfaces the Class.
      Parameters:
      clazz - Class.
      Returns:
      Implementing interfaces.
    • createProxy

      public static Object createProxy(Object implementation, ClassLoader clientClassLoader, ClassLoader implClassLoader, Class<?>... interfaceTypes) throws ClassNotFoundException
      Creates a Proxy.
      Parameters:
      implementation - Implementation behind the Proxy.
      clientClassLoader - ClassLoader for the client.
      implClassLoader - ClassLoader for the implementation.
      interfaceTypes - Interfaces for the Proxy.
      Returns:
      Proxy.
      Throws:
      ClassNotFoundException - If fails to load interface type for Proxy.
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • invoke

      public Object invoke(Object proxy, Method method, Object[] args) throws Throwable
      Specified by:
      invoke in interface InvocationHandler
      Throws:
      Throwable