}
else if (bean instanceof InjectionTargetBean<?>)
{
InjectionTargetBean<?> injectionTarget = (InjectionTargetBean<?>) this.bean;
DelegateHandler delegateHandler = null;
InterceptorDataImpl decoratorInterceptorDataImpl = null;
//Check method is business method
if (InterceptorUtil.isWebBeansBusinessMethod(method))
{
List<Object> decorators = null;
if (injectionTarget.getDecoratorStack().size() > 0)
{
Class<?> proxyClass = JavassistProxyFactory.getInstance().getInterceptorProxyClasses().get(bean);
if (proxyClass == null)
{
ProxyFactory delegateFactory = JavassistProxyFactory.getInstance().createProxyFactory(bean);
proxyClass = JavassistProxyFactory.getInstance().getProxyClass(delegateFactory);
JavassistProxyFactory.getInstance().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.size() > 0)
{
if (this.interceptedMethodMap == null)
{
// lazy initialisation, because creating a WeakHashMap is expensive!
this.interceptedMethodMap = new WeakHashMap<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);
decoratorInterceptorDataImpl.setDefinedInInterceptorClass(true);
decoratorInterceptorDataImpl.setAroundInvoke(SecurityUtil.doPrivilegedGetDeclaredMethods(lastInterceptor.getClass())[0]);
}
if (this.interceptedMethodMap.get(method) == null)
{
//Holds filtered interceptor stack
List<InterceptorData> filteredInterceptorStack = new ArrayList<InterceptorData>(interceptorStack);
// Filter both EJB and WebBeans interceptors
InterceptorUtil.filterCommonInterceptorStackList(filteredInterceptorStack, method);
InterceptorUtil.filterOverridenAroundInvokeInterceptor(bean.getBeanClass(), filteredInterceptorStack);
this.interceptedMethodMap.put(method, filteredInterceptorStack);
}
List<InterceptorData> filteredInterceptorStack = new ArrayList<InterceptorData>(this.interceptedMethodMap.get(method));
if (decoratorInterceptorDataImpl != null)
{
// created an intereceptor to run our decorators, add it to the calculated stack
filteredInterceptorStack.add(decoratorInterceptorDataImpl);
}
// Call Around Invokes
if (WebBeansUtil.isContainsInterceptorMethod(filteredInterceptorStack, InterceptorType.AROUND_INVOKE))
{
return callAroundInvokes(method, arguments, InterceptorUtil.getInterceptorMethods(filteredInterceptorStack,
InterceptorType.AROUND_INVOKE));
}
}
// If there are Decorators, allow the delegate handler to
// manage the stack
if (decorators != null)
{
return delegateHandler.invoke(instance, method, proceed, arguments);
}
}
}
//If here call actual method