Class Proxy


  • public class Proxy
    extends java.lang.Object
    Proxy class allows for generating proxy objects for interfaces and/or one class. Both sides are optional. Uses the InvocationHandler from standard Java interface proxy mechanism.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.util.Map<Tuple2<java.lang.ClassLoader,​java.util.Set<java.lang.Class<?>>>,​java.lang.Class<?>> CLASSCACHE  
      static java.util.concurrent.atomic.AtomicInteger COUNTER  
      static java.util.Set<java.lang.String> OBJECTMETHODS  
    • Constructor Summary

      Constructors 
      Constructor Description
      Proxy()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      protected static org.objectweb.asm.tree.MethodNode genrateInvocationCode​(org.objectweb.asm.tree.MethodNode m, java.lang.String classname, java.lang.Class<?> iface, java.lang.ClassLoader loader)
      Generate the code for delegating the call to the invocation handler.
      static java.lang.reflect.InvocationHandler getInvocationHandler​(java.lang.Object proxy)
      Get the invocation handler of a proxy.
      static void main​(java.lang.String[] args)
      Main for testing.
      static java.lang.Object newProxyInstance​(java.lang.ClassLoader loader, java.lang.Class<?>[] ifaces, java.lang.reflect.InvocationHandler handler)
      Generate a proxy for an existing class.
      static java.lang.Object newProxyInstance​(java.lang.ClassLoader loader, java.lang.Class<?> clazz, java.lang.Class<?>[] ifaces, java.lang.reflect.InvocationHandler handler)
      Generate a proxy for an existing class.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • OBJECTMETHODS

        public static final java.util.Set<java.lang.String> OBJECTMETHODS
      • COUNTER

        public static final java.util.concurrent.atomic.AtomicInteger COUNTER
      • CLASSCACHE

        public static final java.util.Map<Tuple2<java.lang.ClassLoader,​java.util.Set<java.lang.Class<?>>>,​java.lang.Class<?>> CLASSCACHE
    • Constructor Detail

      • Proxy

        public Proxy()
    • Method Detail

      • getInvocationHandler

        public static java.lang.reflect.InvocationHandler getInvocationHandler​(java.lang.Object proxy)
        Get the invocation handler of a proxy.
        Parameters:
        proxy -
        Returns:
        The handler
      • newProxyInstance

        public static java.lang.Object newProxyInstance​(java.lang.ClassLoader loader,
                                                        java.lang.Class<?>[] ifaces,
                                                        java.lang.reflect.InvocationHandler handler)
        Generate a proxy for an existing class.
        Parameters:
        loader - The class loader.
        ifaces - The interfaces (may contain one clazz).
        handler - The invocation handler.
        Returns:
        The new proxy extending the clazz and implementing all interfaces.
      • newProxyInstance

        public static java.lang.Object newProxyInstance​(java.lang.ClassLoader loader,
                                                        java.lang.Class<?> clazz,
                                                        java.lang.Class<?>[] ifaces,
                                                        java.lang.reflect.InvocationHandler handler)
        Generate a proxy for an existing class.
        Parameters:
        loader - The class loader.
        clazz - The clazz.
        ifaces - The interfaces.
        handler - The invocation handler.
        Returns:
        The new proxy extending the clazz and implementing all interfaces.
      • genrateInvocationCode

        protected static org.objectweb.asm.tree.MethodNode genrateInvocationCode​(org.objectweb.asm.tree.MethodNode m,
                                                                                 java.lang.String classname,
                                                                                 java.lang.Class<?> iface,
                                                                                 java.lang.ClassLoader loader)
                                                                          throws java.lang.Exception
        Generate the code for delegating the call to the invocation handler.
        Parameters:
        m - The methodnode.
        classname - The class name.
        iface - The interface (null means the class is owner of the method)
        Returns:
        The new method node (or null).
        Throws:
        java.lang.Exception
      • main

        public static void main​(java.lang.String[] args)
                         throws java.lang.Exception
        Main for testing.
        Throws:
        java.lang.Exception