Class CodegenProxyCreator


  • public class CodegenProxyCreator
    extends java.lang.Object
    Generate a proxy with a specified base class.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.lang.String className  
      private static java.util.Properties debugProps  
      private static java.util.Properties emptyProps  
      private java.util.List<org.glassfish.pfl.dynamic.codegen.spi.Type> interfaces  
      private java.util.List<org.glassfish.pfl.dynamic.codegen.spi.MethodInfo> methods  
      private static org.glassfish.pfl.dynamic.codegen.spi.Type objectArrayType  
      private org.glassfish.pfl.dynamic.codegen.spi.Type superClass  
    • Constructor Summary

      Constructors 
      Constructor Description
      CodegenProxyCreator​(java.lang.String className, java.lang.Class sc, java.lang.Class[] interfaces, java.lang.reflect.Method[] methods)  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method Description
      java.lang.Class<?> create​(java.lang.Class<?> anchorClass, boolean debug, java.io.PrintStream ps)
      Construct a generator for a proxy class that implements the given interfaces and extends superClass.
      java.lang.Class<?> create​(java.security.ProtectionDomain pd, java.lang.ClassLoader cl, boolean debug, java.io.PrintStream ps)
      private static void createMethod​(int mnum, org.glassfish.pfl.dynamic.codegen.spi.MethodInfo method)  
      • Methods inherited from class java.lang.Object

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

      • className

        private java.lang.String className
      • superClass

        private org.glassfish.pfl.dynamic.codegen.spi.Type superClass
      • interfaces

        private java.util.List<org.glassfish.pfl.dynamic.codegen.spi.Type> interfaces
      • methods

        private java.util.List<org.glassfish.pfl.dynamic.codegen.spi.MethodInfo> methods
      • debugProps

        private static final java.util.Properties debugProps
      • emptyProps

        private static final java.util.Properties emptyProps
      • objectArrayType

        private static final org.glassfish.pfl.dynamic.codegen.spi.Type objectArrayType
    • Constructor Detail

      • CodegenProxyCreator

        public CodegenProxyCreator​(java.lang.String className,
                                   java.lang.Class sc,
                                   java.lang.Class[] interfaces,
                                   java.lang.reflect.Method[] methods)
    • Method Detail

      • create

        @Deprecated
        public java.lang.Class<?> create​(java.security.ProtectionDomain pd,
                                         java.lang.ClassLoader cl,
                                         boolean debug,
                                         java.io.PrintStream ps)
        Construct a generator for a proxy class that implements the given interfaces and extends superClass. superClass must satisfy the following requirements:
        1. It must have an accessible no args constructor
        2. It must have a method satisfying the signature Object invoke( int methodNumber, Object[] args ) throws Throwable
        3. The invoke method described above must be accessible to the generated class (generally either public or protected.

        Each method in methods is implemented by a method that:

        1. Creates an array sized to hold the args
        2. Wraps args of primitive type in the appropriate wrapper.
        3. Copies each arg or wrapper arg into the array.
        4. Calls invoke with a method number corresponding to the index of the method in methods. Note that the invoke implementation must use the same method array to figure out which method has been invoked.
        5. Return the result (if any), extracting values from wrappers as needed to handle a return value of a primitive type.

        Note that the generated methods ignore exceptions. It is assumed that the invoke method may throw any desired exception.

        Parameters:
        pd - the protection domain of the generated class
        cl - the classloader in which to generate the class
        debug - if true, generate debug messages
        ps - a PrintStream to which the debug messages should be written
        Returns:
        Generator for class
      • create

        public java.lang.Class<?> create​(java.lang.Class<?> anchorClass,
                                         boolean debug,
                                         java.io.PrintStream ps)
        Construct a generator for a proxy class that implements the given interfaces and extends superClass. superClass must satisfy the following requirements:
        1. It must have an accessible no args constructor
        2. It must have a method satisfying the signature Object invoke( int methodNumber, Object[] args ) throws Throwable
        3. The invoke method described above must be accessible to the generated class (generally either public or protected.

        Each method in methods is implemented by a method that:

        1. Creates an array sized to hold the args
        2. Wraps args of primitive type in the appropriate wrapper.
        3. Copies each arg or wrapper arg into the array.
        4. Calls invoke with a method number corresponding to the index of the method in methods. Note that the invoke implementation must use the same method array to figure out which method has been invoked.
        5. Return the result (if any), extracting values from wrappers as needed to handle a return value of a primitive type.

        Note that the generated methods ignore exceptions. It is assumed that the invoke method may throw any desired exception.

        Parameters:
        anchorClass - a class in whose classloader the new class should be generated
        debug - if true, generate debug messages
        ps - a PrintStream to which the debug messages should be written
        Returns:
        Generator for class
        Since:
        4.2.1
      • createMethod

        private static void createMethod​(int mnum,
                                         org.glassfish.pfl.dynamic.codegen.spi.MethodInfo method)