Class AbstractProxyFactory

    • Field Detail

      • MODIFIER_VARARGS

        public static final int MODIFIER_VARARGS
        This is needed as the Modifier#VARARGS is not (yet) public. Note that the bitcode is the same as Modifier#TRANSIENT. But 'varargs' is only for methods, whereas 'transient' is only for fields.
        See Also:
        Constant Field Values
      • unsafe

        protected final Unsafe unsafe
      • FIELD_BEAN_PASSIVATION_ID

        public static final String FIELD_BEAN_PASSIVATION_ID
        The name of the field which stores the passivationID of the Bean this proxy serves. This is needed in case the proxy gets de-serialized back into a JVM which didn't have this bean loaded yet.
        See Also:
        Constant Field Values
    • Constructor Detail

      • AbstractProxyFactory

        protected AbstractProxyFactory​(WebBeansContext webBeansContext)
    • Method Detail

      • getProxyClassLoader

        protected ClassLoader getProxyClassLoader​(Class<?> beanClass)
      • getMarkerInterface

        protected abstract Class<?> getMarkerInterface()
        Returns:
        the marker interface which should be used for this proxy.
      • createInstanceVariables

        protected abstract void createInstanceVariables​(org.apache.xbean.asm9.ClassWriter cw,
                                                        Class<?> classToProxy,
                                                        String classFileName)
        generate the bytecode for creating the instance variables of the class
      • createSerialisation

        protected abstract void createSerialisation​(org.apache.xbean.asm9.ClassWriter cw,
                                                    String proxyClassFileName,
                                                    Class<?> classToProxy,
                                                    String classFileName)
        generate the bytecode for serialization.
      • createConstructor

        protected abstract void createConstructor​(org.apache.xbean.asm9.ClassWriter cw,
                                                  String proxyClassFileName,
                                                  Class<?> classToProxy,
                                                  String classFileName,
                                                  Constructor<?> injectConstructor)
                                           throws ProxyGenerationException
        Each of our interceptor/decorator proxies has exactly 1 constructor which invokes the super ct + sets the delegation field.
        Parameters:
        cw -
        classToProxy -
        classFileName -
        Throws:
        ProxyGenerationException
      • getUnusedProxyClassName

        protected String getUnusedProxyClassName​(ClassLoader classLoader,
                                                 String proxyClassName,
                                                 Method[] proxiedMethods,
                                                 Method[] notProxiedMethods)
      • uniqueHash

        protected String uniqueHash​(Method[] proxiedMethods,
                                    Method[] notProxiedMethods)
      • getSignedClassProxyName

        protected <T> String getSignedClassProxyName​(Class<T> classToProxy)
      • fixPreservedPackages

        protected String fixPreservedPackages​(String proxyClassName)
      • createProxyClass

        protected <T> Class<T> createProxyClass​(ClassLoader classLoader,
                                                String proxyClassName,
                                                Class<T> classToProxy,
                                                Method[] interceptedMethods,
                                                Method[] nonInterceptedMethods,
                                                Constructor<T> constructor)
                                         throws ProxyGenerationException
        Type Parameters:
        T -
        Parameters:
        classLoader - to use for creating the class in
        classToProxy - the class for which a subclass will get generated
        interceptedMethods - the list of intercepted or decorated business methods.
        nonInterceptedMethods - all methods which are not intercepted nor decorated and shall get delegated directly
        Returns:
        the proxy class
        Throws:
        ProxyGenerationException
      • newInstance

        protected <T> T newInstance​(Class<? extends T> proxyClass)
      • unproxyableMethod

        protected boolean unproxyableMethod​(Method delegatedMethod)
      • getWrapperType

        protected String getWrapperType​(Class<?> type)
        Returns:
        the wrapper type for a primitive, e.g. java.lang.Integer for int
      • getVarInsn

        protected int getVarInsn​(Class<?> type)
        Returns the appropriate bytecode instruction to load a value from a variable to the stack
        Parameters:
        type - Type to load
        Returns:
        Bytecode instruction to use
      • pushIntOntoStack

        protected void pushIntOntoStack​(org.apache.xbean.asm9.MethodVisitor mv,
                                        int i)
        Invokes the most appropriate bytecode instruction to put a number on the stack
        Parameters:
        mv -
        i -
      • getReturnInsn

        protected int getReturnInsn​(Class<?> type)
        Gets the appropriate bytecode instruction for RETURN, according to what type we need to return
        Parameters:
        type - Type the needs to be returned
        Returns:
        The matching bytecode instruction
      • getCastType

        protected String getCastType​(Class<?> returnType)
        Gets the string to use for CHECKCAST instruction, returning the correct value for any type, including primitives and arrays
        Parameters:
        returnType - The type to cast to with CHECKCAST
        Returns:
        CHECKCAST parameter
      • getPrimitiveMethod

        protected String getPrimitiveMethod​(Class<?> type)
        Returns the name of the Java method to call to get the primitive value from an Object - e.g. intValue for java.lang.Integer
        Parameters:
        type - Type whose primitive method we want to lookup
        Returns:
        The name of the method to use
      • generateReturn

        protected void generateReturn​(org.apache.xbean.asm9.MethodVisitor mv,
                                      Method delegatedMethod)
      • pushMethodParameterArray

        protected void pushMethodParameterArray​(org.apache.xbean.asm9.MethodVisitor mv,
                                                Class<?>[] parameterTypes)
        Create an Object[] parameter which contains all the parameters of the currently invoked method and store this array for use in the call stack.
        Parameters:
        mv -
        parameterTypes -
      • createArrayDefinition

        protected void createArrayDefinition​(org.apache.xbean.asm9.MethodVisitor mv,
                                             int size,
                                             Class<?> type)
                                      throws ProxyGenerationException
        pushes an array of the specified size to the method visitor. The generated bytecode will leave the new array at the top of the stack.
        Parameters:
        mv - MethodVisitor to use
        size - Size of the array to create
        type - Type of array to create
        Throws:
        ProxyGenerationException