Class 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 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

      • unwrapInstance

        public <T> T unwrapInstance​(T 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:

        1. 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.
        2. 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!
        3. 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 class
        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
      • getCachedProxyClass

        public <T> Class<T> getCachedProxyClass​(jakarta.enterprise.inject.spi.Bean<T> bean)
      • 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:
        delegateNonInterceptedMethods in class AbstractProxyFactory
        Parameters:
        noninterceptedMethods - all methods which are neither intercepted nor decorated