Package org.apache.webbeans.intercept

Examples of org.apache.webbeans.intercept.InterceptorsManager


     * @param interceptorsElement interceptors element
     */
    private void configureInterceptorsElement(Element interceptorsElement, String fileName, ScannerService scanner)
    {
        WebBeansContext webBeansContext = WebBeansContext.getInstance();
        InterceptorsManager manager = webBeansContext.getInterceptorsManager();
        Node node;
        Element child;

        // the interceptors in this beans.xml
        // this gets used to detect multiple definitions of the
        // same interceptor in one beans.xml file.
        Set<Class> interceptorsInFile = new HashSet<Class>();

        NodeList ns = interceptorsElement.getChildNodes();
        for (int i = 0; i < ns.getLength(); i++)
        {
            node = ns.item(i);
            if (!(node instanceof Element))
            {
                continue;
            }
            child = (Element) node;
            Class<?> clazz = null;

            clazz = ClassUtil.getClassFromName(child.getTextContent().trim());

            if (clazz == null)
            {
                throw new WebBeansConfigurationException(createConfigurationFailedMessage() + "Interceptor class : " +
                                                         child.getTextContent().trim() + " not found");
            }
            else
            {
                Annotation[] classAnnotations;
                AnnotatedType<?> annotatedType = webBeansContext.getAnnotatedElementFactory().newAnnotatedType(clazz);

                ProcessAnnotatedTypeImpl<?> processAnnotatedEvent =
                    webBeansContext.getWebBeansUtil().fireProcessAnnotatedTypeEvent(annotatedType);

                // if veto() is called
                if (processAnnotatedEvent.isVeto())
                {
                    return;
                }

                annotatedType = processAnnotatedEvent.getAnnotatedType();

                Set<Annotation> annTypeAnnotations = annotatedType.getAnnotations();
                if (annTypeAnnotations != null)
                {
                    classAnnotations = annTypeAnnotations.toArray(new Annotation[annTypeAnnotations.size()]);
                }
                else
                {
                    classAnnotations = new Annotation[0];
                }

                if (AnnotationUtil.hasAnnotation(classAnnotations, Interceptor.class) &&
                    !webBeansContext.getAnnotationManager().
                            hasInterceptorBindingMetaAnnotation(classAnnotations))
                {
                    throw new WebBeansConfigurationException(createConfigurationFailedMessage() + "Interceptor class : "
                                                             + child.getTextContent().trim()
                                                             + " must have at least one @InterceptorBinding");
                }

                // check if the interceptor got defined twice in this beans.xml
                if (interceptorsInFile.contains(clazz))
                {
                    throw new WebBeansConfigurationException(createConfigurationFailedMessage() + "Interceptor class : "
                                                             + child.getTextContent().trim()
                                                             + " already defined in this beans.xml file!");
                }
                interceptorsInFile.add(clazz);

                boolean isBDAScanningEnabled=(scanner!=null && scanner.isBDABeansXmlScanningEnabled());
                if ((!isBDAScanningEnabled && manager.isInterceptorEnabled(clazz)) ||
                        (isBDAScanningEnabled && !scanner.getBDABeansXmlScanner().addInterceptor(clazz, fileName)))
                {
                    logger.warning( "Interceptor class : " + child.getTextContent().trim() + " is already defined");
                }
                else
                {
                    manager.addNewInterceptor(clazz);
                }
            }

        }

View Full Code Here


    private void configureInterceptorsElement(Element interceptorsElement)
    {
        List<Element> childs = interceptorsElement.elements();
        Iterator<Element> itChilds = childs.iterator();

        InterceptorsManager manager = InterceptorsManager.getInstance();
        while (itChilds.hasNext())
        {
            Element child = itChilds.next();
            Class<?> clazz = XMLUtil.getElementJavaType(child);

            if (clazz == null)
            {
                throw new WebBeansConfigurationException(createConfigurationFailedMessage() + "Interceptor class : " + XMLUtil.getName(child) + " not found");
            }
            else
            {
                if (!AnnotationUtil.isInterceptorBindingMetaAnnotationExist(clazz.getDeclaredAnnotations()))
                {
                    throw new WebBeansConfigurationException(createConfigurationFailedMessage() + "Interceptor class : " + XMLUtil.getName(child) + " must have at least one @InterceptorBindingType");
                }

                if (manager.isInterceptorEnabled(clazz))
                {
                    throw new WebBeansConfigurationException(createConfigurationFailedMessage() + "Interceptor class : " + XMLUtil.getName(child) + " is already defined");
                }

                manager.addNewInterceptor(clazz);
            }

        }

    }
View Full Code Here

        ClassLoader classLoader = startupObject.getAppContext().getClassLoader();

        WebBeansContext webBeansContext = startupObject.getAppContext().getWebBeansContext();
        final AlternativesManager alternativesManager = webBeansContext.getAlternativesManager();
        final DecoratorsManager decoratorsManager = webBeansContext.getDecoratorsManager();
        final InterceptorsManager interceptorsManager = webBeansContext.getInterceptorsManager();

        final HashSet<String> ejbClasses = new HashSet<String>();

        for (EjbJarInfo ejbJar : appInfo.ejbJars) {
            for (EnterpriseBeanInfo bean : ejbJar.enterpriseBeans) {
                ejbClasses.add(bean.ejbClass);
            }
        }

        final AnnotationManager annotationManager = webBeansContext.getAnnotationManager();

        for (EjbJarInfo ejbJar : appInfo.ejbJars) {
            final BeansInfo beans = ejbJar.beans;

            if (beans == null) continue;

            for (String className : beans.interceptors) {
                Class<?> clazz = load(className, classLoader);

                if (clazz != null) {
// TODO: Move check to validation phase
                    if (AnnotationUtil.hasAnnotation(clazz.getDeclaredAnnotations(), Interceptor.class) && !annotationManager.hasInterceptorBindingMetaAnnotation(
                        clazz.getDeclaredAnnotations())) {
                        throw new WebBeansConfigurationException("Interceptor class : " + clazz.getName() + " must have at least one @InterceptorBindingType");
                    }

                    if (interceptorsManager.isInterceptorEnabled(clazz)) {
                        throw new WebBeansConfigurationException("Interceptor class : " + clazz.getName() + " is already defined");
                    }

                    interceptorsManager.addNewInterceptor(clazz);
                    classes.add(clazz);
                } else {
                    throw new WebBeansConfigurationException("Could not load interceptor class: " + className);
                }
            }
View Full Code Here

    private void configureInterceptorsElement(Element interceptorsElement)
    {
        List<Element> childs = interceptorsElement.elements();
        Iterator<Element> itChilds = childs.iterator();

        InterceptorsManager manager = InterceptorsManager.getInstance();
        while (itChilds.hasNext())
        {
            Element child = itChilds.next();
            Class<?> clazz = XMLUtil.getElementJavaType(child);

            if (clazz == null)
            {
                throw new WebBeansConfigurationException(createConfigurationFailedMessage() + "Interceptor class : " + XMLUtil.getName(child) + " not found");
            }
            else
            {
                if (!AnnotationUtil.isInterceptorBindingMetaAnnotationExist(clazz.getDeclaredAnnotations()))
                {
                    throw new WebBeansConfigurationException(createConfigurationFailedMessage() + "Interceptor class : " + XMLUtil.getName(child) + " must have at least one @InterceptorBindingType");
                }

                if (manager.isInterceptorEnabled(clazz))
                {
                    throw new WebBeansConfigurationException(createConfigurationFailedMessage() + "Interceptor class : " + XMLUtil.getName(child) + " is already defined");
                }

                manager.addNewInterceptor(clazz);
            }

        }

    }
View Full Code Here

     *
     * @param interceptorsElement interceptors element
     */
    private void configureInterceptorsElement(Element interceptorsElement)
    {
        InterceptorsManager manager = InterceptorsManager.getInstance();
        Node node;
        Element child;
        NodeList ns = interceptorsElement.getChildNodes();
        for (int i = 0; i < ns.getLength(); i++)
        {
            node = ns.item(i);
            if (!(node instanceof Element))
            {
                continue;
            }
            child = (Element) node;
            Class<?> clazz = null;

            if (this.owbSpecificConfiguration)
            {
                clazz = XMLUtil.getElementJavaType(child);
            }
            else
            {
                clazz = ClassUtil.getClassFromName(child.getTextContent().trim());
            }

            if (clazz == null)
            {
                throw new WebBeansConfigurationException(createConfigurationFailedMessage() + "Interceptor class : " +
                                                         (this.owbSpecificConfiguration ? XMLUtil.getName(child) : child.getTextContent().trim()) + " not found");
            }
            else
            {
                if (AnnotationUtil.hasAnnotation(clazz.getDeclaredAnnotations(), Interceptor.class) &&
                    !AnnotationUtil.hasInterceptorBindingMetaAnnotation(clazz.getDeclaredAnnotations()))
                {
                    throw new WebBeansConfigurationException(createConfigurationFailedMessage() + "Interceptor class : " +
                                                             (this.owbSpecificConfiguration ? XMLUtil.getName(child) : child.getTextContent().trim()) +
                                                             " must have at least one @InterceptorBindingType");
                }

                if (manager.isInterceptorEnabled(clazz))
                {
                    throw new WebBeansConfigurationException(createConfigurationFailedMessage() + "Interceptor class : " +
                                                             (this.owbSpecificConfiguration ? XMLUtil.getName(child) : child.getTextContent().trim()) + " is already defined");
                }

                manager.addNewInterceptor(clazz);
            }

        }

    }
View Full Code Here

    private void configureInterceptorsElement(Element interceptorsElement)
    {
        List<Element> childs = interceptorsElement.elements();
        Iterator<Element> itChilds = childs.iterator();

        InterceptorsManager manager = InterceptorsManager.getInstance();
        while (itChilds.hasNext())
        {
            Element child = itChilds.next();
            Class<?> clazz = null;
           
            if(this.owbSpecificConfiguration)
            {
                clazz = XMLUtil.getElementJavaType(child);
            }
            else
            {
                clazz = ClassUtil.getClassFromName(child.getTextTrim());
            }

            if (clazz == null)
            {
                throw new WebBeansConfigurationException(createConfigurationFailedMessage() + "Interceptor class : " +
                    (this.owbSpecificConfiguration ? XMLUtil.getName(child) : child.getTextTrim()) + " not found");
            }
            else
            {
                if (!AnnotationUtil.hasInterceptorBindingMetaAnnotation(clazz.getDeclaredAnnotations()))
                {
                    throw new WebBeansConfigurationException(createConfigurationFailedMessage() + "Interceptor class : " +
                        (this.owbSpecificConfiguration ? XMLUtil.getName(child) : child.getTextTrim()) + " must have at least one @InterceptorBindingType");
                }

                if (manager.isInterceptorEnabled(clazz))
                {
                    throw new WebBeansConfigurationException(createConfigurationFailedMessage() + "Interceptor class : " +
                        (this.owbSpecificConfiguration ? XMLUtil.getName(child) : child.getTextTrim()) + " is already defined");
                }

                manager.addNewInterceptor(clazz);
            }

        }

    }
View Full Code Here

        }

        final WebBeansContext webBeansContext = startupObject.getWebBeansContext();
        final AlternativesManager alternativesManager = webBeansContext.getAlternativesManager();
        final DecoratorsManager decoratorsManager = webBeansContext.getDecoratorsManager();
        final InterceptorsManager interceptorsManager = webBeansContext.getInterceptorsManager();

        for (final EjbJarInfo ejbJar : appInfo.ejbJars) {
            final BeansInfo beans = ejbJar.beans;

            if (beans == null) {
                continue;
            }

            if (startupObject.isFromWebApp()) { // deploy only the related ejbmodule
                if (!ejbJar.moduleId.equals(startupObject.getWebContext().getId())) {
                    continue;
                }
            } else if (ejbJar.webapp && !appInfo.webAppAlone) {
                continue;
            }

            // fail fast
            final StringBuilder errors = new StringBuilder("You can't define multiple times the same class in beans.xml: ");
            if (addErrors(errors, "alternative classes", beans.duplicatedAlternativeClasses)
                || addErrors(errors, "alternative stereotypes", beans.duplicatedAlternativeStereotypes)
                || addErrors(errors, "decorators", beans.duplicatedDecorators)
                || addErrors(errors, "interceptors", beans.duplicatedInterceptors)) {
                throw new WebBeansConfigurationException(errors.toString());
            }
            // no more need of errors so clear them
            beans.duplicatedAlternativeStereotypes.clear();
            beans.duplicatedAlternativeClasses.clear();
            beans.duplicatedDecorators.clear();
            beans.duplicatedInterceptors.clear();

            for (final String className : beans.interceptors) {
                final Class<?> clazz = load(PropertyPlaceHolderHelper.simpleValue(className), classLoader);

                if (clazz != null) {
                    if (!interceptorsManager.isInterceptorClassEnabled(clazz)) {
                        interceptorsManager.addEnabledInterceptorClass(clazz);
                        classes.add(clazz);
                    } /* else { don't do it, check is done when we know the beans.xml path --> org.apache.openejb.config.DeploymentLoader.addBeansXmls
                        throw new WebBeansConfigurationException("Interceptor class : " + clazz.getName() + " is already defined");
                    }*/
                } else if (shouldThrowCouldNotLoadException(startupObject)) {
View Full Code Here

        }

        final WebBeansContext webBeansContext = startupObject.getWebBeansContext();
        final AlternativesManager alternativesManager = webBeansContext.getAlternativesManager();
        final DecoratorsManager decoratorsManager = webBeansContext.getDecoratorsManager();
        final InterceptorsManager interceptorsManager = webBeansContext.getInterceptorsManager();

        // "manual" extension to avoid to add it through SPI mecanism
        classes.addAll(asList(TRANSACTIONAL_INTERCEPTORS));
        for (final Class<?> interceptor : TRANSACTIONAL_INTERCEPTORS) {
            interceptorsManager.addEnabledInterceptorClass(interceptor);
        }

        // TODO: this shouldn't be needed with OWB 2, see org.apache.openejb.cdi.OptimizedLoaderService.loadExtensions() too
        classes.add(BValInterceptor.class);
        interceptorsManager.addEnabledInterceptorClass(BValInterceptor.class);

        // app beans
        for (final EjbJarInfo ejbJar : appInfo.ejbJars) {
            final BeansInfo beans = ejbJar.beans;

            if (beans == null) {
                continue;
            }

            if (startupObject.isFromWebApp()) { // deploy only the related ejbmodule
                if (!ejbJar.moduleId.equals(startupObject.getWebContext().getId())) {
                    continue;
                }
            } else if (ejbJar.webapp && !appInfo.webAppAlone) {
                continue;
            }

            // fail fast
            final StringBuilder errors = new StringBuilder("You can't define multiple times the same class in beans.xml: ");
            if (addErrors(errors, "alternative classes", beans.duplicatedAlternativeClasses)
                || addErrors(errors, "alternative stereotypes", beans.duplicatedAlternativeStereotypes)
                || addErrors(errors, "decorators", beans.duplicatedDecorators)
                || addErrors(errors, "interceptors", beans.duplicatedInterceptors)) {
                throw new WebBeansConfigurationException(errors.toString());
            }
            // no more need of errors so clear them
            beans.duplicatedAlternativeStereotypes.clear();
            beans.duplicatedAlternativeClasses.clear();
            beans.duplicatedDecorators.clear();
            beans.duplicatedInterceptors.clear();

            for (final String className : beans.interceptors) {
                final Class<?> clazz = load(PropertyPlaceHolderHelper.simpleValue(className), classLoader);

                if (clazz != null) {
                    if (!interceptorsManager.isInterceptorClassEnabled(clazz)) {
                        interceptorsManager.addEnabledInterceptorClass(clazz);
                        classes.add(clazz);
                    } /* else { don't do it, check is done when we know the beans.xml path --> org.apache.openejb.config.DeploymentLoader.addBeansXmls
                        throw new WebBeansConfigurationException("Interceptor class : " + clazz.getName() + " is already defined");
                    }*/
                } else if (shouldThrowCouldNotLoadException(startupObject)) {
View Full Code Here

     * @param interceptorsElement interceptors element
     */
    private void configureInterceptorsElement(Element interceptorsElement, String fileName, ScannerService scanner)
    {
        WebBeansContext webBeansContext = WebBeansContext.getInstance();
        InterceptorsManager manager = webBeansContext.getInterceptorsManager();
        Node node;
        Element child;

        // the interceptors in this beans.xml
        // this gets used to detect multiple definitions of the
        // same interceptor in one beans.xml file.
        Set<Class> interceptorsInFile = new HashSet<Class>();

        NodeList ns = interceptorsElement.getChildNodes();
        for (int i = 0; i < ns.getLength(); i++)
        {
            node = ns.item(i);
            if (!(node instanceof Element))
            {
                continue;
            }
            child = (Element) node;
            Class<?> clazz = null;

            clazz = ClassUtil.getClassFromName(child.getTextContent().trim());

            if (clazz == null)
            {
                throw new WebBeansConfigurationException(createConfigurationFailedMessage() + "Interceptor class : " +
                                                         child.getTextContent().trim() + " not found");
            }
            else
            {
                Annotation[] classAnnotations;
                AnnotatedType<?> annotatedType = webBeansContext.getAnnotatedElementFactory().newAnnotatedType(clazz);

                ProcessAnnotatedTypeImpl<?> processAnnotatedEvent =
                    webBeansContext.getWebBeansUtil().fireProcessAnnotatedTypeEvent(annotatedType);

                // if veto() is called
                if (processAnnotatedEvent.isVeto())
                {
                    return;
                }

                annotatedType = processAnnotatedEvent.getAnnotatedType();

                Set<Annotation> annTypeAnnotations = annotatedType.getAnnotations();
                if (annTypeAnnotations != null)
                {
                    classAnnotations = annTypeAnnotations.toArray(new Annotation[annTypeAnnotations.size()]);
                }
                else
                {
                    classAnnotations = new Annotation[0];
                }

                if (AnnotationUtil.hasAnnotation(classAnnotations, Interceptor.class) &&
                    !webBeansContext.getAnnotationManager().
                            hasInterceptorBindingMetaAnnotation(classAnnotations))
                {
                    throw new WebBeansConfigurationException(createConfigurationFailedMessage() + "Interceptor class : "
                                                             + child.getTextContent().trim()
                                                             + " must have at least one @InterceptorBinding");
                }

                // check if the interceptor got defined twice in this beans.xml
                if (interceptorsInFile.contains(clazz))
                {
                    throw new WebBeansConfigurationException(createConfigurationFailedMessage() + "Interceptor class : "
                                                             + child.getTextContent().trim()
                                                             + " already defined in this beans.xml file!");
                }
                interceptorsInFile.add(clazz);

                boolean isBDAScanningEnabled=(scanner!=null && scanner.isBDABeansXmlScanningEnabled());
                if ((!isBDAScanningEnabled && manager.isInterceptorClassEnabled(clazz)) ||
                        (isBDAScanningEnabled && !scanner.getBDABeansXmlScanner().addInterceptor(clazz, fileName)))
                {
                    logger.warning( "Interceptor class : " + child.getTextContent().trim() + " is already defined");
                }
                else
                {
                    manager.addEnabledInterceptorClass(clazz);
                }
            }

        }

View Full Code Here

     * @param interceptorsElement interceptors element
     */
    private void configureInterceptorsElement(Element interceptorsElement, String fileName, ScannerService scanner)
    {
        WebBeansContext webBeansContext = WebBeansContext.getInstance();
        InterceptorsManager manager = webBeansContext.getInterceptorsManager();
        Node node;
        Element child;

        // the interceptors in this beans.xml
        // this gets used to detect multiple definitions of the
        // same interceptor in one beans.xml file.
        Set<Class> interceptorsInFile = new HashSet<Class>();

        NodeList ns = interceptorsElement.getChildNodes();
        for (int i = 0; i < ns.getLength(); i++)
        {
            node = ns.item(i);
            if (!(node instanceof Element))
            {
                continue;
            }
            child = (Element) node;
            Class<?> clazz = null;

            clazz = ClassUtil.getClassFromName(child.getTextContent().trim());

            if (clazz == null)
            {
                throw new WebBeansConfigurationException(createConfigurationFailedMessage() + "Interceptor class : " +
                                                         child.getTextContent().trim() + " not found");
            }
            else
            {
                Annotation[] classAnnotations;
                AnnotatedType<?> annotatedType = webBeansContext.getAnnotatedElementFactory().newAnnotatedType(clazz);

                ProcessAnnotatedTypeImpl<?> processAnnotatedEvent =
                    webBeansContext.getWebBeansUtil().fireProcessAnnotatedTypeEvent(annotatedType);

                // if veto() is called
                if (processAnnotatedEvent.isVeto())
                {
                    return;
                }

                annotatedType = processAnnotatedEvent.getAnnotatedType();

                Set<Annotation> annTypeAnnotations = annotatedType.getAnnotations();
                if (annTypeAnnotations != null)
                {
                    classAnnotations = annTypeAnnotations.toArray(new Annotation[annTypeAnnotations.size()]);
                }
                else
                {
                    classAnnotations = new Annotation[0];
                }

                if (AnnotationUtil.hasAnnotation(classAnnotations, Interceptor.class) &&
                    !webBeansContext.getAnnotationManager().
                            hasInterceptorBindingMetaAnnotation(classAnnotations))
                {
                    throw new WebBeansConfigurationException(createConfigurationFailedMessage() + "Interceptor class : "
                                                             + child.getTextContent().trim()
                                                             + " must have at least one @InterceptorBinding");
                }

                // check if the interceptor got defined twice in this beans.xml
                if (interceptorsInFile.contains(clazz))
                {
                    throw new WebBeansConfigurationException(createConfigurationFailedMessage() + "Interceptor class : "
                                                             + child.getTextContent().trim()
                                                             + " already defined in this beans.xml file!");
                }
                interceptorsInFile.add(clazz);

                boolean isBDAScanningEnabled=(scanner!=null && scanner.isBDABeansXmlScanningEnabled());
                if ((!isBDAScanningEnabled && manager.isInterceptorEnabled(clazz)) ||
                        (isBDAScanningEnabled && !scanner.getBDABeansXmlScanner().addInterceptor(clazz, fileName)))
                {
                    logger.warn( "Interceptor class : " + child.getTextContent().trim() + " is already defined");
                }
                else
                {
                    manager.addNewInterceptor(clazz);
                }
            }

        }

View Full Code Here

TOP

Related Classes of org.apache.webbeans.intercept.InterceptorsManager

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.