@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(); }