Package org.apache.webbeans.proxy
Class AbstractProxyFactory
- java.lang.Object
-
- 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
Fields Modifier and Type Field Description static StringFIELD_BEAN_PASSIVATION_IDThe name of the field which stores the passivationID of the Bean this proxy serves.static intMAX_CLASSLOAD_TRIESstatic intMODIFIER_VARARGSThis is needed as the Modifier#VARARGS is not (yet) public.protected Unsafeunsafeprotected WebBeansContextwebBeansContext
-
Constructor Summary
Constructors Modifier Constructor Description protectedAbstractProxyFactory(WebBeansContext webBeansContext)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Deprecated Methods Modifier and Type Method Description protected voidcreateArrayDefinition(org.apache.xbean.asm9.MethodVisitor mv, int size, Class<?> type)pushes an array of the specified size to the method visitor.protected abstract voidcreateConstructor(org.apache.xbean.asm9.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 voidcreateInstanceVariables(org.apache.xbean.asm9.ClassWriter cw, Class<?> classToProxy, String classFileName)generate the bytecode for creating the instance variables of the classprotected <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 voidcreateSerialisation(org.apache.xbean.asm9.ClassWriter cw, String proxyClassFileName, Class<?> classToProxy, String classFileName)generate the bytecode for serialization.protected abstract voiddelegateInterceptedMethods(ClassLoader classLoader, org.apache.xbean.asm9.ClassWriter cw, String proxyClassFileName, Class<?> classToProxy, Method[] interceptedMethods)generate the bytecode for invoking all intercepted methodsprotected abstract voiddelegateNonInterceptedMethods(ClassLoader classLoader, org.apache.xbean.asm9.ClassWriter cw, String proxyClassFileName, Class<?> classToProxy, Method[] noninterceptedMethods)generate the bytecode for invoking all non-intercepted methodsprotected StringfixPreservedPackages(String proxyClassName)protected voidgenerateReturn(org.apache.xbean.asm9.MethodVisitor mv, Method delegatedMethod)protected StringgetCastType(Class<?> returnType)Gets the string to use for CHECKCAST instruction, returning the correct value for any type, including primitives and arraysprotected abstract Class<?>getMarkerInterface()protected StringgetPrimitiveMethod(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.Integerprotected ClassLoadergetProxyClassLoader(Class<?> beanClass)protected intgetReturnInsn(Class<?> type)Gets the appropriate bytecode instruction for RETURN, according to what type we need to returnprotected <T> StringgetSignedClassProxyName(Class<T> classToProxy)protected StringgetUnusedProxyClassName(ClassLoader classLoader, String proxyClassName)Deprecated.protected StringgetUnusedProxyClassName(ClassLoader classLoader, String proxyClassName, Method[] proxiedMethods, Method[] notProxiedMethods)protected intgetVarInsn(Class<?> type)Returns the appropriate bytecode instruction to load a value from a variable to the stackprotected StringgetWrapperType(Class<?> type)protected <T> TnewInstance(Class<? extends T> proxyClass)protected voidpushIntOntoStack(org.apache.xbean.asm9.MethodVisitor mv, int i)Invokes the most appropriate bytecode instruction to put a number on the stackprotected voidpushMethodParameterArray(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.protected StringuniqueHash(Method[] proxiedMethods, Method[] notProxiedMethods)protected booleanunproxyableMethod(Method delegatedMethod)
-
-
-
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
-
unsafe
protected final Unsafe unsafe
-
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.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 ProxyGenerationExceptionEach 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.asm9.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.asm9.ClassWriter cw, String proxyClassFileName, Class<?> classToProxy, Method[] noninterceptedMethods) throws ProxyGenerationException
generate the bytecode for invoking all non-intercepted methods- Throws:
ProxyGenerationException
-
getUnusedProxyClassName
@Deprecated protected String getUnusedProxyClassName(ClassLoader classLoader, String proxyClassName)
Deprecated.Detect a free classname based on the given one- Parameters:
proxyClassName-- Returns:
-
getUnusedProxyClassName
protected String getUnusedProxyClassName(ClassLoader classLoader, String proxyClassName, Method[] proxiedMethods, Method[] notProxiedMethods)
-
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 inclassToProxy- the class for which a subclass will get generatedinterceptedMethods- 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 ProxyGenerationExceptionpushes 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 usesize- Size of the array to createtype- Type of array to create- Throws:
ProxyGenerationException
-
-