Package org.apache.webbeans.proxy
Class AbstractProxyFactory
java.lang.Object
org.apache.webbeans.proxy.AbstractProxyFactory
- Direct Known Subclasses:
InterceptorDecoratorProxyFactory,NormalScopeProxyFactory,SubclassProxyFactory
Base class for all OWB Proxy factories
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringThe name of the field which stores the passivationID of the Bean this proxy serves.static final intstatic final intThis is needed as the Modifier#VARARGS is not (yet) public.protected final Unsafeprotected WebBeansContext -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected 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<?>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) For method lists that omit JVM bridges (usualClassUtil.getNonPrivateMethods(Class, boolean)).protected booleanunproxyableMethodExceptBridge(Method delegatedMethod) Methods that must not be proxied (excluding theMethod.isBridge()rule).
-
Field Details
-
MAX_CLASSLOAD_TRIES
public static final int MAX_CLASSLOAD_TRIES- See Also:
-
MODIFIER_VARARGS
public static final int MODIFIER_VARARGSThis 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:
-
unsafe
-
webBeansContext
-
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:
-
-
Constructor Details
-
AbstractProxyFactory
-
-
Method Details
-
getProxyClassLoader
-
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
-
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) -
uniqueHash
-
getSignedClassProxyName
-
fixPreservedPackages
-
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
-
unproxyableMethodExceptBridge
Methods that must not be proxied (excluding theMethod.isBridge()rule). When a caller usesClassUtil.getNonPrivateMethods(Class, boolean, boolean)withincludeJvmBridgeMethods == true, use this for filtering — notunproxyableMethod(java.lang.reflect.Method), which also skips all bridge methods for the common case whereClassUtil.getNonPrivateMethods(Class, boolean)omits them. -
unproxyableMethod
For method lists that omit JVM bridges (usualClassUtil.getNonPrivateMethods(Class, boolean)). -
getWrapperType
- Returns:
- the wrapper type for a primitive, e.g. java.lang.Integer for int
-
getVarInsn
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
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
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
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
-
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 usesize- Size of the array to createtype- Type of array to create- Throws:
ProxyGenerationException
-
getUnusedProxyClassName(ClassLoader, String, Method[], Method[]).