public abstract class InterceptorHandler extends Object implements InvocationHandler, MethodHandler, Serializable
Decorators and Interceptors are configured from BeansDeployer
class via methods defineManagedBean(class) and Those methods further call
defineInterceptor(interceptor class) and defineDecorator(decorator class)
methods. Those methods finally call
WebBeansUtil.defineInterceptor(org.apache.webbeans.component.creation.ManagedBeanCreatorImpl,
javax.enterprise.inject.spi.ProcessInjectionTarget) and
WebBeansUtil.defineDecorator(org.apache.webbeans.component.creation.ManagedBeanCreatorImpl,
javax.enterprise.inject.spi.ProcessInjectionTarget)
methods for actual configuration.
Let's look at the "WebBeansUtil's" methods;
defineInterceptor : This method firstly
creates a "Managed Bean" for the given interceptor with
"WebBeansType.INTERCEPTOR" as a type. After checking some controls, it calls
"WebBeansInterceptorConfig#configureInterceptorClass".
"configureInterceptorClass" method creates a "WebBeansInterceptor" instance
that wraps the given managed bean instance and configuring interceptor's
*Interceptor Binding* annotations. If everything goes well, it adds
interceptor instance into the "BeanManager" interceptor list.
defineDecorator : Exactly doing same thing as "defineInterceptor". If
everything goes well, it adds decorator instance into the "BeanManager"
decorator list.
Currently interceptors and decorators are supported for the "Managed Beans".
OWB delegates calling of "EJB Beans" interceptors to the EJB container. It
does not provide built-in interceptor and decorator support for EJB beans.
Current implementation supports configuration of the interceptors on the
"Managed Beans" with 2 different scenarios, i.e. it supports
"EJB related interceptors ( defined by EJB specification)" and
"JSR-299 related interceptors (defined by interceptor bindings)". Managed
Beans interceptor and decorator stacks are configured after they are
instantiated by the container first time. This method can be found in the
AbstractInjectionTargetBean" class "afterConstructor()" method. Actual
configuration is done by the
(org.apache.webbeans.component.AbstractInjectionTargetBean) and
DefinitionUtil.defineDecoratorStack(org.apache.webbeans.component.AbstractInjectionTargetBean<?>). In
"DefinitionUtil.defineBeanInterceptorStack", firstly it configures
"EJB spec. interceptors" after that configures "JSR-299 spec. interceptors."
In "DefinitionUtil.defineDecoratorStack", it configures
decorator stack. "EJBInterceptorConfig" class is responsible for finding all
interceptors for given managed bean class according to the EJB Specification.
(But as you said, it may not include AroundInvoke/PostConstruct etc.
disablement scenario!). "WebBeansInterceptorConfig" class is responsible for
finding all interceptors for a given managed bean class according to the
"JSR-299, spec." It adds all interceptors into the bean's interceptor stack.
It first adds "EJB" related interceptors, after that adds "JSR-299" related
interceptors. For "JSR-299" related interceptors, it orders the interceptors
according to the "InterceptorComparator". Basically, it puts interceptors in
order according to how they are ordered in a "beans.xml" configuration file.
Similarly, it configures managed bean's decorator stack according to the
decorator resolution rules. Also, it orders decorators according to the
"beans.xml" configuration file that contains decorator declarations.
Invocation is handled by the "InterceptorHandler" class (It has an absurd name, it can be changed to a more meaningful name :)). It works nearly same as what you have explained. First of all, it checks that calling method is a business method of a managed bean or not. After that it filters interceptor stack for calling method (Current design of filtering may not be optimal!). Firstly it adds EJB interceptor to the list and then adds JSR-299 interceptors. After that, it starts to call all interceptors in order. After consuming all interceptors it calls decorators. (as you explained, seems that the logic may not be correct here. Currently, interceptors and decorators are not related with each other. They are called independently).This must be changed!.
WebBeansInterceptorConfig,
WebBeansDecoratorConfig,
WebBeansInterceptor,
WebBeansDecorator,
EJBInterceptorConfig,
Serialized Form| Modifier and Type | Field and Description |
|---|---|
protected OwbBean<?> |
bean
Proxied bean
|
protected Map<Method,List<InterceptorData>> |
interceptedMethodMap
Intercepted methods
|
protected WebBeansContext |
webBeansContext |
| Modifier | Constructor and Description |
|---|---|
protected |
InterceptorHandler(OwbBean<?> bean)
Creates a new handler.
|
| Modifier and Type | Method and Description |
|---|---|
protected abstract Object |
callAroundInvokes(Method interceptedMethod,
Object[] arguments,
List<InterceptorData> stack)
Call around invoke method of the given bean on
calling interceptedMethod.
|
protected BeanManagerImpl |
getBeanManager() |
Object |
invoke(Object instance,
Method method,
Method proceed,
Object[] arguments,
CreationalContextImpl<?> ownerCreationalContext)
Calls decorators and interceptors and actual
bean method.
|
Object |
invoke(Object instance,
Method method,
Object[] arguments,
CreationalContextImpl<?> ownerCreationalContext) |
protected boolean |
isNotInterceptedOrDecoratedMethod(Method method)
This method provides a way to implement a negative cache for methods
which are known to become intercepted or decorated.
|
protected void |
setNotInterceptedOrDecoratedMethod(Method method)
This method will get called after the interceptorStack got evaluated and we
found out that it isnt intercepted nor decorated.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitinvokeprotected OwbBean<?> bean
protected transient volatile Map<Method,List<InterceptorData>> interceptedMethodMap
protected WebBeansContext webBeansContext
protected InterceptorHandler(OwbBean<?> bean)
bean - proxied beanprotected boolean isNotInterceptedOrDecoratedMethod(Method method)
method - which should get invokedtrue if the method is known to not get intercepted,
false we dont know or it gets interceptedsetNotInterceptedOrDecoratedMethod(java.lang.reflect.Method)protected void setNotInterceptedOrDecoratedMethod(Method method)
method - isNotInterceptedOrDecoratedMethod(java.lang.reflect.Method)public Object invoke(Object instance, Method method, Method proceed, Object[] arguments, CreationalContextImpl<?> ownerCreationalContext) throws Exception
instance - actual bean instancemethod - business methodproceed - proceed methodarguments - method argumentsownerCreationalContext - bean creational contextException - for exceptionpublic Object invoke(Object instance, Method method, Object[] arguments, CreationalContextImpl<?> ownerCreationalContext) throws Exception
Exceptionprotected abstract Object callAroundInvokes(Method interceptedMethod, Object[] arguments, List<InterceptorData> stack) throws Exception
interceptedMethod - intercepted bean methodarguments - method actual argumentsstack - interceptor stackException - for any exceptionprotected BeanManagerImpl getBeanManager()
Copyright © 2008-2013 The Apache Software Foundation. All Rights Reserved.