Package org.apache.webbeans.proxy
Class InterceptorDecoratorProxyFactory
- java.lang.Object
-
- org.apache.webbeans.proxy.AbstractProxyFactory
-
- org.apache.webbeans.proxy.InterceptorDecoratorProxyFactory
-
public class InterceptorDecoratorProxyFactory extends AbstractProxyFactory
Generate a dynamic subclass which has exactly 1 delegation point instance which get's set in the Constructor of the proxy. Any non-intercepted or decorated method will get delegated natively, All intercepted and decorated methods will get invoked via an InvocationHandler chain. This factory will create and cache the proxy classes for a given type.
-
-
Field Summary
Fields Modifier and Type Field Description static StringFIELD_INTERCEPTED_METHODSthe name of the field which stores the Method[] of all intercepted methodsstatic StringFIELD_INTERCEPTOR_HANDLERthe name of the field which stores the Interceptor + Decorator stack InterceptorHandlerstatic StringFIELD_PROXIED_INSTANCEthe name of the field which stores the proxied instance-
Fields inherited from class org.apache.webbeans.proxy.AbstractProxyFactory
FIELD_BEAN_PASSIVATION_ID, MAX_CLASSLOAD_TRIES, MODIFIER_VARARGS, unsafe, webBeansContext
-
-
Constructor Summary
Constructors Constructor Description InterceptorDecoratorProxyFactory(WebBeansContext webBeansContext)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidcreateConstructor(org.apache.xbean.asm9.ClassWriter cw, String proxyClassFileName, Class<?> classToProxy, String classFileName, Constructor<?> ignored)Each of our interceptor/decorator proxies has exactly 1 constructor which invokes the super ct + sets the delegation field.protected voidcreateInstanceVariables(org.apache.xbean.asm9.ClassWriter cw, Class<?> classToProxy, String classFileName)generate the bytecode for creating the instance variables of the class<T> Class<T>createProxyClass(jakarta.enterprise.inject.spi.Bean<T> bean, ClassLoader classLoader, Class<T> classToProxy, Method[] interceptedMethods, Method[] nonInterceptedMethods)Create a decorator and interceptor proxy for the given type.<T> Class<T>createProxyClass(InterceptorResolutionService.BeanInterceptorInfo interceptorInfo, jakarta.enterprise.inject.spi.AnnotatedType<T> at, ClassLoader classLoader)<T> TcreateProxyInstance(Class<? extends T> proxyClass, T instance, InterceptorHandler interceptorDecoratorStack)protected voidcreateSerialisation(org.apache.xbean.asm9.ClassWriter cw, String proxyClassFileName, Class<?> classToProxy, String classFileName)generate the bytecode for serialization.protected voiddelegateInterceptedMethods(ClassLoader classLoader, org.apache.xbean.asm9.ClassWriter cw, String proxyClassFileName, Class<?> classToProxy, Method[] interceptedMethods)generate the bytecode for invoking all intercepted methodsprotected voiddelegateNonInterceptedMethods(ClassLoader classLoader, org.apache.xbean.asm9.ClassWriter cw, String proxyClassFileName, Class<?> classToProxy, Method[] noninterceptedMethods)Directly delegate all non intercepted nor decorated methods to the internal instance.<T> Class<T>getCachedProxyClass(jakarta.enterprise.inject.spi.Bean<T> bean)<T> Class<T>getCachedProxyClass(InterceptorResolutionService.BeanInterceptorInfo interceptorInfo, jakarta.enterprise.inject.spi.AnnotatedType<T> at, ClassLoader classLoader)InterceptorHandlergetInterceptorHandler(OwbInterceptorProxy proxyInstance)protected ClassgetMarkerInterface()<T> TunwrapInstance(T proxyInstance)-
Methods inherited from class org.apache.webbeans.proxy.AbstractProxyFactory
createArrayDefinition, createProxyClass, createProxyClass, fixPreservedPackages, generateReturn, getCastType, getPrimitiveMethod, getProxyClassLoader, getReturnInsn, getSignedClassProxyName, getUnusedProxyClassName, getUnusedProxyClassName, getVarInsn, getWrapperType, newInstance, pushIntOntoStack, pushMethodParameterArray, uniqueHash, unproxyableMethod
-
-
-
-
Field Detail
-
FIELD_PROXIED_INSTANCE
public static final String FIELD_PROXIED_INSTANCE
the name of the field which stores the proxied instance- See Also:
- Constant Field Values
-
FIELD_INTERCEPTOR_HANDLER
public static final String FIELD_INTERCEPTOR_HANDLER
the name of the field which stores the Interceptor + Decorator stack InterceptorHandler- See Also:
- Constant Field Values
-
FIELD_INTERCEPTED_METHODS
public static final String FIELD_INTERCEPTED_METHODS
the name of the field which stores the Method[] of all intercepted methods- See Also:
- Constant Field Values
-
-
Constructor Detail
-
InterceptorDecoratorProxyFactory
public InterceptorDecoratorProxyFactory(WebBeansContext webBeansContext)
-
-
Method Detail
-
createProxyInstance
public <T> T createProxyInstance(Class<? extends T> proxyClass, T instance, InterceptorHandler interceptorDecoratorStack) throws ProxyGenerationException
- Throws:
ProxyGenerationException
-
unwrapInstance
public <T> T unwrapInstance(T proxyInstance)
- Returns:
- the internal instance which gets proxied.
-
getInterceptorHandler
public InterceptorHandler getInterceptorHandler(OwbInterceptorProxy proxyInstance)
- Returns:
- the internal instance which gets proxied.
-
createProxyClass
public <T> Class<T> createProxyClass(jakarta.enterprise.inject.spi.Bean<T> bean, ClassLoader classLoader, Class<T> classToProxy, Method[] interceptedMethods, Method[] nonInterceptedMethods) throws ProxyGenerationException
Create a decorator and interceptor proxy for the given type. A single instance of such a proxy class has exactly one single internal instance.
There are 3 different kind of methods:
-
private methods - they do not get proxied at all! If you like to invoke a private method,
then you can use
unwrapInstance(Object)and use reflection on it. - non-proxied methods - all methods which do not have a business interceptor nor decorator will get delegated to the internal instance without invoking any InterceptorHandler nor doing reflection. Just plain java bytecode will get generated!
- proxied methods - all calls to such a proxied method will get forwarded to the InterceptorHandler which got set for this instance.
- Type Parameters:
T-- Parameters:
bean- the bean the proxy serves for. Needed for caching and serialisation.classLoader- to use for creating the classclassToProxy- 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
-
private methods - they do not get proxied at all! If you like to invoke a private method,
then you can use
-
createProxyClass
public <T> Class<T> createProxyClass(InterceptorResolutionService.BeanInterceptorInfo interceptorInfo, jakarta.enterprise.inject.spi.AnnotatedType<T> at, ClassLoader classLoader) throws ProxyGenerationException
- Throws:
ProxyGenerationException
-
getCachedProxyClass
public <T> Class<T> getCachedProxyClass(InterceptorResolutionService.BeanInterceptorInfo interceptorInfo, jakarta.enterprise.inject.spi.AnnotatedType<T> at, ClassLoader classLoader)
-
getCachedProxyClass
public <T> Class<T> getCachedProxyClass(jakarta.enterprise.inject.spi.Bean<T> bean)
-
getMarkerInterface
protected Class getMarkerInterface()
- Specified by:
getMarkerInterfacein classAbstractProxyFactory- Returns:
- the marker interface which should be used for this proxy.
-
createInstanceVariables
protected void createInstanceVariables(org.apache.xbean.asm9.ClassWriter cw, Class<?> classToProxy, String classFileName)Description copied from class:AbstractProxyFactorygenerate the bytecode for creating the instance variables of the class- Specified by:
createInstanceVariablesin classAbstractProxyFactory
-
createSerialisation
protected void createSerialisation(org.apache.xbean.asm9.ClassWriter cw, String proxyClassFileName, Class<?> classToProxy, String classFileName)Description copied from class:AbstractProxyFactorygenerate the bytecode for serialization.- Specified by:
createSerialisationin classAbstractProxyFactory
-
createConstructor
protected void createConstructor(org.apache.xbean.asm9.ClassWriter cw, String proxyClassFileName, Class<?> classToProxy, String classFileName, Constructor<?> ignored) throws ProxyGenerationExceptionEach of our interceptor/decorator proxies has exactly 1 constructor which invokes the super ct + sets the delegation field.- Specified by:
createConstructorin classAbstractProxyFactory- Parameters:
cw-classToProxy-classFileName-- Throws:
ProxyGenerationException
-
delegateNonInterceptedMethods
protected void delegateNonInterceptedMethods(ClassLoader classLoader, org.apache.xbean.asm9.ClassWriter cw, String proxyClassFileName, Class<?> classToProxy, Method[] noninterceptedMethods)
Directly delegate all non intercepted nor decorated methods to the internal instance.- Specified by:
delegateNonInterceptedMethodsin classAbstractProxyFactory- Parameters:
noninterceptedMethods- all methods which are neither intercepted nor decorated
-
delegateInterceptedMethods
protected void delegateInterceptedMethods(ClassLoader classLoader, org.apache.xbean.asm9.ClassWriter cw, String proxyClassFileName, Class<?> classToProxy, Method[] interceptedMethods) throws ProxyGenerationException
Description copied from class:AbstractProxyFactorygenerate the bytecode for invoking all intercepted methods- Specified by:
delegateInterceptedMethodsin classAbstractProxyFactory- Throws:
ProxyGenerationException
-
-