Package org.apache.webbeans.decorator

Examples of org.apache.webbeans.decorator.DelegateHandler


                ProxyFactory delegateFactory = webBeansContext.getJavassistProxyFactory().createProxyFactory(bean);
                proxyClass = webBeansContext.getJavassistProxyFactory().getProxyClass(delegateFactory);
                webBeansContext.getJavassistProxyFactory().getInterceptorProxyClasses().put(bean, proxyClass);
            }
            Object delegate = proxyClass.newInstance();
            DelegateHandler newDelegateHandler = new DelegateHandler(bean);
            ((ProxyObject)delegate).setHandler(newDelegateHandler);

            // Gets component decorator stack
            List<Object> decorators = WebBeansDecoratorConfig.getDecoratorStack(injectionTarget, instance, delegate, ownerCreationalContext);
            //Sets decorator stack of delegate
            newDelegateHandler.setDecorators(decorators);
            decoratorDelegateHandler = newDelegateHandler;
        }
    }
View Full Code Here


    {
        Object rv = null;
        BaseEjbBean<?> injectionTarget = this.contextual;
        InterceptorDataImpl decoratorInterceptorDataImpl = null;
        List<Object> decorators = null;
        DelegateHandler delegateHandler = null;
        List<Decorator<?>> decoratorStack = injectionTarget.getDecoratorStack();
        List<InterceptorData> interceptorStack = injectionTarget.getInterceptorStack();


        if (logger.isLoggable(Level.FINE))
        {
            logger.log(Level.FINE, "Decorator stack for target {0}", decoratorStack);
            logger.log(Level.FINE, "Interceptor stack {0}", interceptorStack);
        }
                   
        if (decoratorStack.size() > 0 )
        {   
            if (logger.isLoggable(Level.FINE))
            {
                logger.fine("Obtaining a delegate");
            }
            Class<?> proxyClass = webBeansContext.getJavassistProxyFactory().getInterceptorProxyClasses().get(injectionTarget);
            if (proxyClass == null)
            {
                JavassistProxyFactory proxyFactory = webBeansContext.getJavassistProxyFactory();
                ProxyFactory delegateFactory = proxyFactory.createProxyFactory(injectionTarget);
                proxyClass = proxyFactory.getProxyClass(delegateFactory);
                proxyFactory.getInterceptorProxyClasses().put(injectionTarget, proxyClass);
            }
            Object delegate = proxyClass.newInstance();
            delegateHandler = new DelegateHandler(this.contextual, ejbContext);
            ((ProxyObject)delegate).setHandler(delegateHandler);
    
            // Gets component decorator stack
            decorators = WebBeansDecoratorConfig.getDecoratorStack(injectionTarget, instance, delegate,
                                                                   (CreationalContextImpl<?>)this.cc);         
           
            //Sets decorator stack of delegate
            delegateHandler.setDecorators(decorators);
        }
       
        if (interceptorStack.size() == 0)
        {  
            if (decoratorStack.size() == 0)
            {
                rv = ejbContext.proceed();
            }
            else
            {
                // We only have decorators, so run the decorator stack directly without interceptors.
                // The delegate handler knows about the ejbContext.proceed()
                rv = delegateHandler.invoke(instance, method, null, arguments);   
            }
        }
        else
        {
            // We have at least one interceptor.  Our delegateHandler will need to be wrapped in an interceptor.
View Full Code Here

                ProxyFactory delegateFactory = webBeansContext.getJavassistProxyFactory().createProxyFactory(bean);
                proxyClass = webBeansContext.getJavassistProxyFactory().getProxyClass(delegateFactory);
                webBeansContext.getJavassistProxyFactory().getInterceptorProxyClasses().put((InjectionTargetBean<?>) bean, proxyClass);
            }
            Object delegate = proxyClass.newInstance();
            DelegateHandler delegateHandler = new DelegateHandler(bean, ejbContext);
            ((ProxyObject) delegate).setHandler(delegateHandler);

            // Gets component decorator stack
            List<Object> decorators = WebBeansDecoratorConfig.getDecoratorStack(bean, instance, delegate, (CreationalContextImpl<?>) context);
            //Sets decorator stack of delegate
            delegateHandler.setDecorators(decorators);

            return delegateHandler.invoke(instance, ejbContext.getMethod(), null, ejbContext.getParameters());
        } else {
            return ejbContext.proceed();
        }
    }
View Full Code Here

            }
           
            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           
View Full Code Here

        BaseEjbBean<?> injectionTarget = this.contextual;
        InterceptorDataImpl decoratorInterceptorDataImpl = null;
       
               
        List<Object> decorators = null;
        DelegateHandler delegateHandler = null;
        List<Decorator<?>> decoratorStack = injectionTarget.getDecoratorStack();
        List<InterceptorData> interceptorStack = injectionTarget.getInterceptorStack();


        if (logger.wblWillLogDebug())
        {
            logger.debug("Decorator stack for target {0}", decoratorStack);
            logger.debug("Interceptor stack {0}", interceptorStack);
        }
                   
        if (decoratorStack.size() > 0 )
        {   
            if (logger.wblWillLogDebug())
            {
                logger.debug("Obtaining a delegate");
            }
            Class<?> proxyClass = JavassistProxyFactory.getInstance().getInterceptorProxyClasses().get(injectionTarget);
            if (proxyClass == null)
            {
                ProxyFactory delegateFactory = JavassistProxyFactory.getInstance().createProxyFactory(injectionTarget);
                proxyClass = JavassistProxyFactory.getInstance().getProxyClass(delegateFactory);
                JavassistProxyFactory.getInstance().getInterceptorProxyClasses().put(injectionTarget, proxyClass);
            }
            Object delegate = proxyClass.newInstance();
            delegateHandler = new DelegateHandler(this.contextual, ejbContext);
            ((ProxyObject)delegate).setHandler(delegateHandler);
    
            // Gets component decorator stack
            decorators = WebBeansDecoratorConfig.getDecoratorStack(injectionTarget, instance, delegate,
                                                                   (CreationalContextImpl<?>)this.cc);         
           
            //Sets decorator stack of delegate
            delegateHandler.setDecorators(decorators);
        }
       
        if (interceptorStack.size() == 0)
        {  
            if (decoratorStack.size() == 0)
            {
                rv = ejbContext.proceed();
            }
            else
            {
                // We only have decorators, so run the decorator stack directly without interceptors.
                // The delegate handler knows about the ejbContext.proceed()
                rv = delegateHandler.invoke(instance, method, null, arguments);   
            }
        }
        else
        {
            // We have at least one interceptor.  Our delegateHandler will need to be wrapped in an interceptor.
View Full Code Here

            }
           
            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.getInterceptorProxyClasses().get(bean);
                        if (proxyClass == null)
                        {
                            ProxyFactory delegateFactory = JavassistProxyFactory.createProxyFactory(bean);
                            proxyClass = JavassistProxyFactory.getProxyClass(delegateFactory);
                            JavassistProxyFactory.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 (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);
       
                            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           
View Full Code Here

        if (InterceptorUtil.isWebBeansBusinessMethod(method) &&
                EjbUtility.isBusinessMethod(method, threadLocal.get()))
        {

            List<Object> decorators = null;
            DelegateHandler delegateHandler = null;
            logger.debug("Decorator stack for target {0}", injectionTarget.getDecoratorStack());

            if (injectionTarget.getDecoratorStack().size() > 0)
            {
                Class<?> proxyClass = JavassistProxyFactory.getInterceptorProxyClasses().get(injectionTarget);
                if (proxyClass == null)
                {
                    ProxyFactory delegateFactory = JavassistProxyFactory.createProxyFactory(injectionTarget);
                    proxyClass = JavassistProxyFactory.getProxyClass(delegateFactory);
                    JavassistProxyFactory.getInterceptorProxyClasses().put(injectionTarget, proxyClass);
                }
                Object delegate = proxyClass.newInstance();
                delegateHandler = new DelegateHandler(threadLocal.get(),ejbContext);
                ((ProxyObject)delegate).setHandler(delegateHandler);

                // Gets component decorator stack
                decorators = WebBeansDecoratorConfig.getDecoratorStack(injectionTarget, instance, delegate,
                                                                       (CreationalContextImpl<?>)threadLocalCreationalContext.get());                       
                //Sets decorator stack of delegate
                delegateHandler.setDecorators(decorators);
               
            }

            // Run around invoke chain
            List<InterceptorData> interceptorStack = injectionTarget.getInterceptorStack();
            if (interceptorStack.size() > 0)
            {
                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);

                    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))
                {
                     rv.INTERCEPTOR_OR_DECORATOR_CALL = true;
                     rv.RETURN_VALUE = InterceptorUtil.callAroundInvokes(threadLocal.get(), instance, (CreationalContextImpl<?>)threadLocalCreationalContext.get(), method,
                            arguments, InterceptorUtil.getInterceptorMethods(filteredInterceptorStack, InterceptorType.AROUND_INVOKE), ejbContext);
                    
                     return rv;
                }
               
            }
           
            // If there are Decorators, allow the delegate handler to
            // manage the stack
            if (decorators != null)
            {
                rv.INTERCEPTOR_OR_DECORATOR_CALL = true;
                rv.RETURN_VALUE = delegateHandler.invoke(instance, method, null, arguments);
                return rv;
            }
        }   
       
        rv.INTERCEPTOR_OR_DECORATOR_CALL = false;
View Full Code Here

                // toString is supported but no other object method names!!!
                if ((!ClassUtil.isObjectMethod(method.getName()) || method.getName().equals("toString")) && InterceptorUtil.isWebBeansBusinessMethod(method))
                {

                    DelegateHandler delegateHandler = null;
                    List<Object> decorators = null;

                    if (injectionTarget.getDecoratorStack().size() > 0)
                    {
                        // TODO move this part into JavassistProxyFactory
                        Class<?> proxyClass = interceptorProxyClasses.get(bean);
                        if (proxyClass == null)
                        {
                            ProxyFactory delegateFactory = JavassistProxyFactory.createProxyFactory(bean);
                            proxyClass = JavassistProxyFactory.getProxyClass(delegateFactory);
                            interceptorProxyClasses.put(bean, proxyClass);
                        }
                        Object delegate = proxyClass.newInstance();
                        delegateHandler = new DelegateHandler();
                        ((ProxyObject)delegate).setHandler(delegateHandler);

                        // Gets component decorator stack
                        decorators = WebBeansDecoratorConfig.getDecoratorStack(injectionTarget, instance, delegate, ownerCreationalContext);

                        delegateHandler.setDecorators(decorators);
                    }

                    // Run around invoke chain
                    List<InterceptorData> stack = injectionTarget.getInterceptorStack();

                    List<InterceptorData> temp = new ArrayList<InterceptorData>(stack);

                    // Filter both EJB and WebBeans interceptors
                    filterCommonInterceptorStackList(temp, method, ownerCreationalContext);

                    // If there are both interceptors and decorators, add hook
                    // point to the end of the interceptor stack.
                    if (decorators != null && temp.size() > 0)
                    {
                        WebBeansDecoratorInterceptor lastInterceptor = new WebBeansDecoratorInterceptor(delegateHandler, instance);
                        InterceptorDataImpl data = new InterceptorDataImpl(true);
                        data.setInterceptorInstance(lastInterceptor);
                        data.setAroundInvoke(lastInterceptor.getClass().getDeclaredMethods()[0]);
                        temp.add(data);
                    }

                    // Call Around Invokes
                    if (WebBeansUtil.isContainsInterceptorMethod(temp, InterceptorType.AROUND_INVOKE))
                    {
                        return callAroundInvokes(method, arguments, WebBeansUtil.getInterceptorMethods(temp, 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 (!method.isAccessible())
View Full Code Here

                                                              InjectionTargetBean<?> injectionTarget)
            throws Exception
    {
        if (decoratorDelegateHandler == null)
        {
            final DelegateHandler newDelegateHandler = new DelegateHandler(bean);
            final ProxyFactory proxyFactory = webBeansContext.getProxyFactory();

            final Object delegate = proxyFactory.createDecoratorDelegate(bean, newDelegateHandler);

            // Gets component decorator stack
            List<Object> decorators = WebBeansDecoratorConfig.getDecoratorStack(injectionTarget, instance, delegate, ownerCreationalContext);
            //Sets decorator stack of delegate
            newDelegateHandler.setDecorators(decorators);
            decoratorDelegateHandler = newDelegateHandler;
        }
    }
View Full Code Here

    {
        Object rv = null;
        BaseEjbBean<?> injectionTarget = this.contextual;
        InterceptorDataImpl decoratorInterceptorDataImpl = null;
        List<Object> decorators = null;
        DelegateHandler delegateHandler = null;
        List<Decorator<?>> decoratorStack = injectionTarget.getDecoratorStack();
        List<InterceptorData> interceptorStack = injectionTarget.getInterceptorStack();


        if (logger.isLoggable(Level.FINE))
        {
            logger.log(Level.FINE, "Decorator stack for target {0}", decoratorStack);
            logger.log(Level.FINE, "Interceptor stack {0}", interceptorStack);
        }
                   
        if (decoratorStack.size() > 0 )
        {   
            if (logger.isLoggable(Level.FINE))
            {
                logger.fine("Obtaining a delegate");
            }

            delegateHandler = new DelegateHandler(this.contextual, ejbContext);

            final Object delegate =
                webBeansContext.getProxyFactory().createDecoratorDelegate(injectionTarget, delegateHandler);
            // Gets component decorator stack
            decorators = WebBeansDecoratorConfig.getDecoratorStack(injectionTarget, instance, delegate,
                                                                   (CreationalContextImpl<?>)this.cc);         
           
            //Sets decorator stack of delegate
            delegateHandler.setDecorators(decorators);
        }
       
        if (interceptorStack.size() == 0)
        {  
            if (decoratorStack.size() == 0)
            {
                rv = ejbContext.proceed();
            }
            else
            {
                // We only have decorators, so run the decorator stack directly without interceptors.
                // The delegate handler knows about the ejbContext.proceed()
                rv = delegateHandler.invoke(instance, method, null, arguments);   
            }
        }
        else
        {
            // We have at least one interceptor.  Our delegateHandler will need to be wrapped in an interceptor.
View Full Code Here

TOP

Related Classes of org.apache.webbeans.decorator.DelegateHandler

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.