org.apache.webbeans.proxy
Class AbstractProxyFactory

java.lang.Object
  extended by org.apache.webbeans.proxy.AbstractProxyFactory
Direct Known Subclasses:
InterceptorDecoratorProxyFactory, NormalScopeProxyFactory, SubclassProxyFactory

public abstract class AbstractProxyFactory
extends Object

Base class for all OWB Proxy factories


Field Summary
static String FIELD_BEAN_PASSIVATION_ID
          The name of the field which stores the passivationID of the Bean this proxy serves.
static int MAX_CLASSLOAD_TRIES
           
static int MODIFIER_VARARGS
          This is needed as the Modifier#VARARGS is not (yet) public.
protected  WebBeansContext webBeansContext
           
 
Constructor Summary
protected AbstractProxyFactory(WebBeansContext webBeansContext)
           
 
Method Summary
protected  void createArrayDefinition(org.apache.xbean.asm5.MethodVisitor mv, int size, Class<?> type)
          pushes an array of the specified size to the method visitor.
protected abstract  void createConstructor(org.apache.xbean.asm5.ClassWriter cw, String proxyClassFileName, Class<?> classToProxy, String classFileName, Constructor<?> injectConstructor)
          Each of our interceptor/decorator proxies has exactly 1 constructor which invokes the super ct + sets the delegation field.
protected abstract  void createInstanceVariables(org.apache.xbean.asm5.ClassWriter cw, Class<?> classToProxy, String classFileName)
          generate the bytecode for creating the instance variables of the class
protected
<T> Class<T>
createProxyClass(ClassLoader classLoader, String proxyClassName, Class<T> classToProxy, Method[] interceptedMethods, Method[] nonInterceptedMethods)
           
protected
<T> Class<T>
createProxyClass(ClassLoader classLoader, String proxyClassName, Class<T> classToProxy, Method[] interceptedMethods, Method[] nonInterceptedMethods, Constructor<T> constructor)
           
protected abstract  void createSerialisation(org.apache.xbean.asm5.ClassWriter cw, String proxyClassFileName, Class<?> classToProxy, String classFileName)
          generate the bytecode for serialization.
protected abstract  void delegateInterceptedMethods(ClassLoader classLoader, org.apache.xbean.asm5.ClassWriter cw, String proxyClassFileName, Class<?> classToProxy, Method[] interceptedMethods)
          generate the bytecode for invoking all intercepted methods
protected abstract  void delegateNonInterceptedMethods(ClassLoader classLoader, org.apache.xbean.asm5.ClassWriter cw, String proxyClassFileName, Class<?> classToProxy, Method[] noninterceptedMethods)
          generate the bytecode for invoking all non-intercepted methods
protected  String fixPreservedPackages(String proxyClassName)
           
protected  void generateReturn(org.apache.xbean.asm5.MethodVisitor mv, Method delegatedMethod)
           
protected  String getCastType(Class<?> returnType)
          Gets the string to use for CHECKCAST instruction, returning the correct value for any type, including primitives and arrays
protected abstract  Class getMarkerInterface()
           
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
protected  ClassLoader getProxyClassLoader(Class<?> beanClass)
           
protected  int getReturnInsn(Class<?> type)
          Gets the appropriate bytecode instruction for RETURN, according to what type we need to return
protected  String getUnusedProxyClassName(ClassLoader classLoader, String proxyClassName)
          Detect a free classname based on the given one
protected  int getVarInsn(Class<?> type)
          Returns the appropriate bytecode instruction to load a value from a variable to the stack
protected  String getWrapperType(Class<?> type)
           
protected  void pushIntOntoStack(org.apache.xbean.asm5.MethodVisitor mv, int i)
          Invokes the most appropriate bytecode instruction to put a number on the stack
protected  void pushMethodParameterArray(org.apache.xbean.asm5.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.
protected  boolean unproxyableMethod(Method delegatedMethod)
           
protected
<T> T
unsafeNewInstance(Class<T> clazz)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MAX_CLASSLOAD_TRIES

public static final int MAX_CLASSLOAD_TRIES
See Also:
Constant Field Values

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

webBeansContext

protected WebBeansContext webBeansContext

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.asm5.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.asm5.ClassWriter cw,
                                            String proxyClassFileName,
                                            Class<?> classToProxy,
                                            String classFileName)
generate the bytecode for serialization.


createConstructor

protected abstract void createConstructor(org.apache.xbean.asm5.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

delegateInterceptedMethods

protected abstract void delegateInterceptedMethods(ClassLoader classLoader,
                                                   org.apache.xbean.asm5.ClassWriter cw,
                                                   String proxyClassFileName,
                                                   Class<?> classToProxy,
                                                   Method[] interceptedMethods)
                                            throws ProxyGenerationException
generate the bytecode for invoking all intercepted methods

Throws:
ProxyGenerationException

delegateNonInterceptedMethods

protected abstract void delegateNonInterceptedMethods(ClassLoader classLoader,
                                                      org.apache.xbean.asm5.ClassWriter cw,
                                                      String proxyClassFileName,
                                                      Class<?> classToProxy,
                                                      Method[] noninterceptedMethods)
                                               throws ProxyGenerationException
generate the bytecode for invoking all non-intercepted methods

Throws:
ProxyGenerationException

getUnusedProxyClassName

protected String getUnusedProxyClassName(ClassLoader classLoader,
                                         String proxyClassName)
Detect a free classname based on the given one

Parameters:
proxyClassName -
Returns:

fixPreservedPackages

protected String fixPreservedPackages(String proxyClassName)

createProxyClass

protected <T> Class<T> createProxyClass(ClassLoader classLoader,
                                        String proxyClassName,
                                        Class<T> classToProxy,
                                        Method[] interceptedMethods,
                                        Method[] nonInterceptedMethods)
                             throws ProxyGenerationException
Throws:
ProxyGenerationException

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

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.asm5.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.asm5.MethodVisitor mv,
                              Method delegatedMethod)

unsafeNewInstance

protected <T> T unsafeNewInstance(Class<T> clazz)

pushMethodParameterArray

protected void pushMethodParameterArray(org.apache.xbean.asm5.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.asm5.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


Copyright © 2008–2015 The Apache Software Foundation. All rights reserved.