private Object executeInterception(Object self, Method proceedingMethod, Method thisMethod, Object[] args, InterceptionType interceptionType) throws Throwable { List<? extends InterceptorMetadata<?>> interceptorList = interceptionModel.getInterceptors(interceptionType, thisMethod); Collection<InterceptorInvocation<?>> interceptorInvocations = new ArrayList<InterceptorInvocation<?>>(); for (InterceptorMetadata interceptorReference : interceptorList) { interceptorInvocations.add(new InterceptorInvocation(interceptorHandlerInstances.get(interceptorReference), interceptorReference, interceptionType)); } if (targetClassInterceptorMetadata != null && targetClassInterceptorMetadata.getInterceptorMethods(interceptionType) != null && !targetClassInterceptorMetadata.getInterceptorMethods(interceptionType).isEmpty()) { interceptorInvocations.add(new InterceptorInvocation(isProxy() ? targetInstance : self, targetClassInterceptorMetadata, interceptionType)); } SimpleInterceptionChain chain = new SimpleInterceptionChain(interceptorInvocations, interceptionType, isProxy() ? targetInstance : self, isProxy() ? thisMethod : proceedingMethod); return chain.invokeNextInterceptor(invocationContextFactory.newInvocationContext(chain, isProxy() ? targetInstance : self, isProxy() ? thisMethod : proceedingMethod, args)); }
@SuppressWarnings("unchecked") private void handlePostConstruct(ManagedBeanInstance<T> managedBeanInstance) throws Exception { List<InterceptorMetadata<?>> postConstructs = this.mbMetaData.getPostConstructs(); Collection<InterceptorInvocation<?>> interceptorInvocations = new ArrayList<InterceptorInvocation<?>>(postConstructs.size()); for (InterceptorMetadata<?> interceptor : postConstructs) { Object instance = null; if (interceptor.isTargetClass()) { instance = managedBeanInstance.getInstance(); } else { String interceptorClassName = interceptor.getInterceptorClass().getClassName(); instance = managedBeanInstance.getInterceptor(interceptorClassName); } // TODO: Interceptor invocation creation will be simplified in jboss-interceptors project. InterceptorInvocation<?> interceptorInvocation = new InterceptorInvocation(instance, interceptor, InterceptionType.POST_CONSTRUCT); interceptorInvocations.add(interceptorInvocation); } InterceptionChain interceptorChain = new SimpleInterceptionChain(interceptorInvocations, InterceptionType.POST_CONSTRUCT, managedBeanInstance.getInstance(), null); DefaultInvocationContextFactory invocationCtxFactory = new DefaultInvocationContextFactory(); InvocationContext invocationCtx = invocationCtxFactory.newInvocationContext(interceptorChain, managedBeanInstance.getInstance(), null, null); // invoke post-construct invocationCtx.proceed(); }
@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); } // TODO: Interceptor invocation creation should be simplified in jboss-interceptors project. 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); // invoke return invocationCtx.proceed(); }