String methodName = method.getName();
if (!isNotInterceptedOrDecoratedMethod &&
!ClassUtil.isObjectMethod(methodName) && bean instanceof InjectionTargetBean<?>)
{
InjectionTargetBean<?> injectionTarget = (InjectionTargetBean<?>) this.bean;
DelegateHandler delegateHandler = null;
InterceptorDataImpl decoratorInterceptorDataImpl = null;
//Check method is business method
if (webBeansContext.getInterceptorUtil().isWebBeansBusinessMethod(method))
{
List<Object> decorators = null;
if (!injectionTarget.getDecoratorStack().isEmpty())
{
Class<?> proxyClass = webBeansContext.getJavassistProxyFactory().getInterceptorProxyClasses().get(bean);
if (proxyClass == null)
{
ProxyFactory delegateFactory = webBeansContext.getJavassistProxyFactory().createProxyFactory(bean);
proxyClass = webBeansContext.getJavassistProxyFactory().getProxyClass(delegateFactory);
webBeansContext.getJavassistProxyFactory().getInterceptorProxyClasses().put(bean, proxyClass);
}
Object delegate = proxyClass.newInstance();
delegateHandler = new DelegateHandler(this.bean);
((ProxyObject)delegate).setHandler(delegateHandler);
// Gets component decorator stack
decorators = WebBeansDecoratorConfig.getDecoratorStack(injectionTarget, instance, delegate, ownerCreationalContext);
//Sets decorator stack of delegate
delegateHandler.setDecorators(decorators);
}
// Run around invoke chain
List<InterceptorData> interceptorStack = injectionTarget.getInterceptorStack();
if (!interceptorStack.isEmpty())
{
if (this.interceptedMethodMap == null)
{
// lazy initialisation, because creating a WeakHashMap is expensive!
this.interceptedMethodMap = new ConcurrentHashMap<Method, List<InterceptorData>>();
}
if (decorators != null)
{
// We have interceptors and decorators, Our delegateHandler will need to be wrapped in an interceptor
WebBeansDecoratorInterceptor lastInterceptor = new WebBeansDecoratorInterceptor(delegateHandler, instance);
decoratorInterceptorDataImpl = new InterceptorDataImpl(true, lastInterceptor, webBeansContext);
decoratorInterceptorDataImpl.setDefinedInInterceptorClass(true);
decoratorInterceptorDataImpl.setAroundInvoke(
webBeansContext.getSecurityService().doPrivilegedGetDeclaredMethod(lastInterceptor.getClass(),
"invokeDecorators",
new Class[] {InvocationContext.class}));
}
List<InterceptorData> interceptorMethods = this.interceptedMethodMap.get(method);
if (interceptorMethods == null)
{
//Holds filtered interceptor stack
List<InterceptorData> filteredInterceptorStack = new ArrayList<InterceptorData>();
for (InterceptorData interceptData : interceptorStack)
{
if (interceptData.getAroundInvoke() !=null)
{
filteredInterceptorStack.add(interceptData);
}
}
// Filter both EJB and WebBeans interceptors
InterceptorUtil interceptorUtil = webBeansContext.getInterceptorUtil();
interceptorUtil.filterCommonInterceptorStackList(filteredInterceptorStack, method);
interceptorUtil.filterOverridenAroundInvokeInterceptor(bean.getBeanClass(), filteredInterceptorStack);
this.interceptedMethodMap.put(method, filteredInterceptorStack);
interceptorMethods = filteredInterceptorStack;
}
if (decoratorInterceptorDataImpl != null)
{
// created an intereceptor to run our decorators, add it to the calculated stack
interceptorMethods = new ArrayList<InterceptorData>(interceptorMethods);
interceptorMethods.add(decoratorInterceptorDataImpl);
}
// Call Around Invokes
if (!interceptorMethods.isEmpty())
{
return callAroundInvokes(method, arguments, interceptorMethods);
}
}
// If there are Decorators, allow the delegate handler to
// manage the stack
if (decorators != null)
{
return delegateHandler.invoke(instance, method, proceed, arguments);
}
}
setNotInterceptedOrDecoratedMethod(method);
}