Class 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 one ClassLoader 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 a Proxy.
      static java.lang.Class<?>[] getInterfaces​(java.lang.Class<?> clazz)
      Obtains the implementing interfaces the Class.
      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 no Exception.
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • 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 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 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 the Method.
      • getInterfaces

        public static java.lang.Class<?>[] getInterfaces​(java.lang.Class<?> clazz)
        Obtains the implementing interfaces the Class.
        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 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:
        java.lang.ClassNotFoundException - If fails to load interface type for Proxy.
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.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 interface java.lang.reflect.InvocationHandler
        Throws:
        java.lang.Throwable