@SuppressWarnings("unchecked")
@Override
public Object invoke(ManagedBeanInstance<T> managedBeanInstance, Method method, Object[] args) throws Throwable
{
Collection<InterceptorMetadata<?>> aroundInvokeInterceptors = this.mbMetaData.getAroundInvokes(method);
Collection<InterceptorInvocation<?>> interceptorInvocations = new ArrayList<InterceptorInvocation<?>>(aroundInvokeInterceptors.size());
for (InterceptorMetadata<?> aroundInvokeInterceptor : aroundInvokeInterceptors)
{
Object instance = null;
if (aroundInvokeInterceptor.isTargetClass())
{
instance = managedBeanInstance.getInstance();
}
else
{
String interceptorClassName = aroundInvokeInterceptor.getInterceptorClass().getClassName();
instance = managedBeanInstance.getInterceptor(interceptorClassName);
}
InterceptorInvocation<?> interceptorInvocation = new InterceptorInvocation(instance, aroundInvokeInterceptor, InterceptionType.AROUND_INVOKE);
interceptorInvocations.add(interceptorInvocation);
}
InterceptionChain interceptorChain = new SimpleInterceptionChain(interceptorInvocations,
InterceptionType.AROUND_INVOKE, managedBeanInstance.getInstance(), method);
DefaultInvocationContextFactory invocationCtxFactory = new DefaultInvocationContextFactory();
InvocationContext invocationCtx = invocationCtxFactory.newInvocationContext(interceptorChain, managedBeanInstance.getInstance(), method, args);
return invocationCtx.proceed();
}