Package org.jboss.weld.interceptor.proxy

Examples of org.jboss.weld.interceptor.proxy.SimpleInterceptionChain


                 * The AroundConstruct interceptor method can access the constructed instance using InvocationContext.getTarget
                 * method after the InvocationContext.proceed completes.
                 */
                final AtomicReference<T> target = new AtomicReference<T>();

                SimpleInterceptionChain chain = new SimpleInterceptionChain(model.getConstructorInvocationInterceptors(), interceptionContext, InterceptionType.AROUND_CONSTRUCT) {
                    @Override
                    protected Object interceptorChainCompleted(InvocationContext invocationCtx) throws Exception {
                        // all the interceptors were invoked, call the constructor now
                        T instance = handle.proceed(invocationCtx.getParameters(), invocationCtx.getContextData());
                        target.set(instance);
                        return null;
                    }
                };

                InterceptorInvocationContext invocationCtx = new InterceptorInvocationContext(chain, constructor.getJavaMember(), parameters, data, model.getMemberInterceptorBindings(getConstructor())) {
                    @Override
                    public Object getTarget() {
                        return target.get();
                    }
                };

                // WELD-1742 Associate bean constructor interceptor bindings
                invocationCtx.getContextData().put(InterceptorMethodHandler.INTERCEPTOR_BINDINGS_KEY, model.getMemberInterceptorBindings(getConstructor()));

                try {
                    chain.invokeNextInterceptor(invocationCtx);
                } catch (RuntimeException e) {
                    throw e;
                } catch (Throwable e) {
                    throw new WeldException(e);
                }
View Full Code Here


        final org.jboss.weld.interceptor.spi.model.InterceptionType interceptionType = org.jboss.weld.interceptor.spi.model.InterceptionType.valueOf(type.name());
        final InterceptorInvocation invocation = interceptorMetadata.getInterceptorInvocation(instance, interceptionType);

        try {
            if (ctx instanceof InterceptorInvocationContext || invocation.getInterceptorMethodInvocations().size() < 2) {
                return new SimpleInterceptionChain(invocation).invokeNextInterceptor(ctx);
            } else {
                /*
                 * Calling Interceptor.intercept() may result in multiple interceptor method invocations (provided the interceptor class
                 * interceptor methods on superclasses). This requires cooperation with InvocationContext.
                 *
                 * If the InvocationContext used is our InterceptorInvocationContext or if there is no more than 1 InterceptorMethodInvocation
                 * then no special treatment is required. Otherwise, we use a wrapper InvocationTarget for the purpose of executing the chain of
                 * interceptor methods of this interceptor.
                 */
                final InterceptionChain chain = new SimpleInterceptionChain(invocation) {
                    @Override
                    protected Object interceptorChainCompleted(InvocationContext context) throws Exception {
                        return ctx.proceed(); // done with the inner chain, let the outer chain proceed
                    }
                };
                return chain.invokeNextInterceptor(new ForwardingInvocationContext() {
                    @Override
                    protected InvocationContext delegate() {
                        return ctx;
                    }

                    @Override
                    public Object proceed() throws Exception {
                        return chain.invokeNextInterceptor(this);
                    }
                });
            }
        } catch (RuntimeException e) {
            throw e;
View Full Code Here

TOP

Related Classes of org.jboss.weld.interceptor.proxy.SimpleInterceptionChain

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.