Package org.apache.openejb.util.classloader

Examples of org.apache.openejb.util.classloader.ClassLoaderComparator


        }

        final StartupObject startupObject = (StartupObject) object;
        final AppInfo appInfo = startupObject.getAppInfo();
        final ClassLoader classLoader = startupObject.getClassLoader();
        final ClassLoaderComparator comparator;
        if (classLoader instanceof ClassLoaderComparator) {
            comparator = (ClassLoaderComparator) classLoader;
        } else {
            comparator = new DefaultClassLoaderComparator(classLoader);
        }
View Full Code Here


        }

        final StartupObject startupObject = (StartupObject) object;
        final AppInfo appInfo = startupObject.getAppInfo();
        final ClassLoader classLoader = startupObject.getClassLoader();
        final ClassLoaderComparator comparator;
        if (classLoader instanceof ClassLoaderComparator) {
            comparator = (ClassLoaderComparator) classLoader;
        } else {
            comparator = new DefaultClassLoaderComparator(classLoader);
        }
View Full Code Here

        }

        final StartupObject startupObject = StartupObject.class.cast(object);
        final AppInfo appInfo = startupObject.getAppInfo();
        final ClassLoader classLoader = startupObject.getClassLoader();
        final ClassLoaderComparator comparator;
        if (classLoader instanceof ClassLoaderComparator) {
            comparator = (ClassLoaderComparator) classLoader;
        } else {
            comparator = new DefaultClassLoaderComparator(classLoader);
        }

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

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

            if (beans == null || "false".equalsIgnoreCase(ejbJar.properties.getProperty("openejb.cdi.activated"))) {
                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 must not declare the same class multiple times in the 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)) {
                    throw new WebBeansConfigurationException("Could not load interceptor class: " + className);
                }
            }

            for (final String className : beans.decorators) {
                final Class<?> clazz = load(PropertyPlaceHolderHelper.simpleValue(className), classLoader);
                if (clazz != null) {
                    if (!decoratorsManager.isDecoratorEnabled(clazz)) {
                        decoratorsManager.addEnabledDecorator(clazz);
                        classes.add(clazz);
                    } // same than interceptors regarding throw new WebBeansConfigurationException("Decorator class : " + clazz.getName() + " is already defined");
                } else if (shouldThrowCouldNotLoadException(startupObject)) {
                    throw new WebBeansConfigurationException("Could not load decorator class: " + className);
                }
            }


            for (final String className : beans.alternativeStereotypes) {
                final Class<?> clazz = load(PropertyPlaceHolderHelper.simpleValue(className), classLoader);
                if (clazz != null) {
                    alternativesManager.addXmlStereoTypeAlternative(clazz);
                    classes.add(clazz);
                } else if (shouldThrowCouldNotLoadException(startupObject)) {
                    throw new WebBeansConfigurationException("Could not load alternativeStereotype class: " + className);
                }
            }

            for (final String className : beans.alternativeClasses) {
                final Class<?> clazz = load(PropertyPlaceHolderHelper.simpleValue(className), classLoader);
                if (clazz != null) {
                    alternativesManager.addXmlClazzAlternative(clazz);
                    classes.add(clazz);
                } else if (shouldThrowCouldNotLoadException(startupObject)) {
                    throw new WebBeansConfigurationException("Could not load alternative class: " + className);
                }
            }

            // here for ears we need to skip classes in the parent classloader
            final ClassLoader scl = ClassLoader.getSystemClassLoader();
            final boolean filterByClassLoader = "true".equals(SystemInstance.get().getProperty(OPENEJB_CDI_FILTER_CLASSLOADER, "true"));

            final BeanArchiveService beanArchiveService = webBeansContext.getBeanArchiveService();
            final boolean openejb = OpenEJBBeanInfoService.class.isInstance(beanArchiveService);

            for (final BeansInfo.BDAInfo next : beans.bdas) {
                final BeanArchiveService.BeanArchiveInformation information;
                if (openejb) {
                    final OpenEJBBeanInfoService beanInfoService = OpenEJBBeanInfoService.class.cast(beanArchiveService);
                    information = beanInfoService.createBeanArchiveInformation(beans, classLoader, next.discoveryMode == null? "ALL" : next.discoveryMode); // this fallback is 100% for tests, TODO: get rid of it (AppComposer)
                    // TODO: log a warn is discoveryModes.get(key) == null
                    try {
                        beanInfoService.getBeanArchiveInfo().put(next.uri == null ? null : next.uri.toURL(), information);
                    } catch (final MalformedURLException e) {
                        throw new IllegalStateException(e);
                    }
                } else {
                    try {
                        information = beanArchiveService.getBeanArchiveInformation(next.uri.toURL());
                    } catch (MalformedURLException e) {
                        throw new IllegalStateException(e);
                    }
                }

                final boolean scanModeAnnotated = BeanArchiveService.BeanDiscoveryMode.ANNOTATED.equals(information.getBeanDiscoveryMode());
                final boolean noScan = BeanArchiveService.BeanDiscoveryMode.NONE.equals(information.getBeanDiscoveryMode());
                final boolean isNotEarWebApp = startupObject.getWebContext() == null;

                if (!noScan) {
                    for (final String name : next.managedClasses) {
                        if (information.isClassExcluded(name)) {
                            continue;
                        }

                        final Class clazz = load(name, classLoader);
                        if (clazz == null) {
                            continue;
                        }

                        if (scanModeAnnotated) {
                            if (isBean(clazz)) {
                                classes.add(clazz);
                                if (beans.startupClasses.contains(name)) {
                                    startupClasses.add(clazz);
                                }
                            }
                        } else {
                            final ClassLoader loader = clazz.getClassLoader();
                            if (!filterByClassLoader || comparator.isSame(loader) || (loader.equals(scl) && isNotEarWebApp)) {
                                classes.add(clazz);
                                if (beans.startupClasses.contains(name)) {
                                    startupClasses.add(clazz);
                                }
                            }
View Full Code Here

        }

        final StartupObject startupObject = (StartupObject) object;
        final AppInfo appInfo = startupObject.getAppInfo();
        final ClassLoader classLoader = startupObject.getClassLoader();
        final ClassLoaderComparator comparator;
        if (classLoader instanceof  ClassLoaderComparator) {
            comparator = (ClassLoaderComparator) classLoader;
        } else {
            comparator = new DefaultClassLoaderComparator(classLoader);
        }
View Full Code Here

        }

        final StartupObject startupObject = (StartupObject) object;
        final AppInfo appInfo = startupObject.getAppInfo();
        final ClassLoader classLoader = startupObject.getClassLoader();
        final ClassLoaderComparator comparator;
        if (classLoader instanceof ClassLoaderComparator) {
            comparator = (ClassLoaderComparator) classLoader;
        } else {
            comparator = new DefaultClassLoaderComparator(classLoader);
        }

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

        // 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)) {
                    throw new WebBeansConfigurationException("Could not load interceptor class: " + className);
                }
            }

            for (final String className : beans.decorators) {
                final Class<?> clazz = load(PropertyPlaceHolderHelper.simpleValue(className), classLoader);
                if (clazz != null) {
                    if (!decoratorsManager.isDecoratorEnabled(clazz)) {
                        decoratorsManager.addEnabledDecorator(clazz);
                        classes.add(clazz);
                    } // same than interceptors regarding throw new WebBeansConfigurationException("Decorator class : " + clazz.getName() + " is already defined");
                } else if (shouldThrowCouldNotLoadException(startupObject)) {
                    throw new WebBeansConfigurationException("Could not load decorator class: " + className);
                }
            }


            for (final String className : beans.alternativeStereotypes) {
                final Class<?> clazz = load(PropertyPlaceHolderHelper.simpleValue(className), classLoader);
                if (clazz != null) {
                    alternativesManager.addXmlStereoTypeAlternative(clazz);
                    classes.add(clazz);
                } else if (shouldThrowCouldNotLoadException(startupObject)) {
                    throw new WebBeansConfigurationException("Could not load alternativeStereotype class: " + className);
                }
            }

            for (final String className : beans.alternativeClasses) {
                final Class<?> clazz = load(PropertyPlaceHolderHelper.simpleValue(className), classLoader);
                if (clazz != null) {
                    alternativesManager.addXmlClazzAlternative(clazz);
                    classes.add(clazz);
                } else if (shouldThrowCouldNotLoadException(startupObject)) {
                    throw new WebBeansConfigurationException("Could not load alternative class: " + className);
                }
            }

            // here for ears we need to skip classes in the parent classloader
            final ClassLoader scl = ClassLoader.getSystemClassLoader();
            final boolean filterByClassLoader = "true".equals(SystemInstance.get().getProperty(OPENEJB_CDI_FILTER_CLASSLOADER, "true"));

            final BeanArchiveService beanArchiveService = webBeansContext.getBeanArchiveService();
            final boolean openejb = OpenEJBBeanInfoService.class.isInstance(beanArchiveService);

            for (final BeansInfo.BDAInfo next : beans.bdas) {
                final BeanArchiveService.BeanArchiveInformation information;
                if (openejb) {
                    final OpenEJBBeanInfoService beanInfoService = OpenEJBBeanInfoService.class.cast(beanArchiveService);
                    information = beanInfoService.createBeanArchiveInformation(beans, classLoader, next.discoveryMode == null? "ALL" : next.discoveryMode); // this fallback is 100% for tests, TODO: get rid of it (AppComposer)
                    // TODO: log a warn is discoveryModes.get(key) == null
                    try {
                        beanInfoService.getBeanArchiveInfo().put(next.uri == null ? null : next.uri.toURL(), information);
                    } catch (final MalformedURLException e) {
                        throw new IllegalStateException(e);
                    }
                } else {
                    try {
                        information = beanArchiveService.getBeanArchiveInformation(next.uri.toURL());
                    } catch (MalformedURLException e) {
                        throw new IllegalStateException(e);
                    }
                }

                final boolean scanModeAnnotated = BeanArchiveService.BeanDiscoveryMode.ANNOTATED.equals(information.getBeanDiscoveryMode());
                final boolean noScan = BeanArchiveService.BeanDiscoveryMode.NONE.equals(information.getBeanDiscoveryMode());
                final boolean isNotEarWebApp = startupObject.getWebContext() == null;

                if (!noScan) {
                    for (final String name : next.managedClasses) {
                        if (information.isClassExcluded(name)) {
                            continue;
                        }

                        final Class clazz = load(name, classLoader);
                        if (clazz == null) {
                            continue;
                        }

                        if (scanModeAnnotated) {
                            if (isBean(clazz)) {
                                classes.add(clazz);
                                if (beans.startupClasses.contains(name)) {
                                    startupClasses.add(clazz);
                                }
                            }
                        } else {
                            final ClassLoader loader = clazz.getClassLoader();
                            if (!filterByClassLoader || comparator.isSame(loader) || loader.equals(scl) && isNotEarWebApp) {
                                classes.add(clazz);
                                if (beans.startupClasses.contains(name)) {
                                    startupClasses.add(clazz);
                                }
                            }
View Full Code Here

            return;
        }
        StartupObject startupObject = (StartupObject) object;
        AppInfo appInfo = startupObject.getAppInfo();
        ClassLoader classLoader = startupObject.getClassLoader();
        final ClassLoaderComparator comparator;
        if (classLoader instanceof  ClassLoaderComparator) {
            comparator = (ClassLoaderComparator) classLoader;
        } else {
            comparator = new DefaultClassLoaderComparator(classLoader);
        }
View Full Code Here

            return;
        }
        StartupObject startupObject = (StartupObject) object;
        AppInfo appInfo = startupObject.getAppInfo();
        ClassLoader classLoader = startupObject.getClassLoader();
        final ClassLoaderComparator comparator;
        if (classLoader instanceof  ClassLoaderComparator) {
            comparator = (ClassLoaderComparator) classLoader;
        } else {
            comparator = new DefaultClassLoaderComparator(classLoader);
        }

        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;

            // 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 (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)) {
                        interceptorsManager.addNewInterceptor(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 {
                    throw new WebBeansConfigurationException("Could not load interceptor class: " + className);
                }
            }

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

                if (clazz != null) {
                    if (!decoratorsManager.isDecoratorEnabled(clazz)) {
                        decoratorsManager.addNewDecorator(clazz);
                        classes.add(clazz);
                    } // same than interceptors regarding throw new WebBeansConfigurationException("Decorator class : " + clazz.getName() + " is already defined");
                } else {
                    throw new WebBeansConfigurationException("Could not load decorator class: " + className);
                }
            }


            for (String className : beans.alternativeStereotypes) {
                Class<?> clazz = load(className, classLoader);
                if (clazz != null) {
                    alternativesManager.addStereoTypeAlternative(clazz, null, null);
                    classes.add(clazz);
                } else {
                    throw new WebBeansConfigurationException("Could not load alternativeStereotype class: " + className);
                }
            }

            for (String className : beans.alternativeClasses) {
                Class<?> clazz = load(className, classLoader);
                if (clazz != null) {
                    alternativesManager.addClazzAlternative(clazz, null, null);
                    classes.add(clazz);
                } else {
                    throw new WebBeansConfigurationException("Could not load alternative class: " + className);
                }
            }

            // here for ears we need to skip classes in the parent classloader
            final ClassLoader scl = ClassLoader.getSystemClassLoader();
            final boolean filterByClassLoader = "true".equals(SystemInstance.get().getProperty(OPENEJB_CDI_FILTER_CLASSLOADER, "true"));
            for (String className : beans.managedClasses) {
                if (ejbClasses.contains(className)) continue;
                final Class clazz = load(className, classLoader);
                if (clazz == null) {
                    continue;
                }

                final ClassLoader cl = clazz.getClassLoader();
                // 1. this classloader is the good one
                // 2. the classloader is the appclassloader one and we are in the ear parent
                if (!filterByClassLoader
                        || comparator.isSame(cl) || (cl.equals(scl) && startupObject.getWebContext() == null)) {
                    classes.add(clazz);
                }
            }
        }

View Full Code Here

            return;
        }
        StartupObject startupObject = (StartupObject) object;
        AppInfo appInfo = startupObject.getAppInfo();
        ClassLoader classLoader = startupObject.getClassLoader();
        final ClassLoaderComparator comparator;
        if (classLoader instanceof  ClassLoaderComparator) {
            comparator = (ClassLoaderComparator) classLoader;
        } else {
            comparator = new DefaultClassLoaderComparator(classLoader);
        }
View Full Code Here

TOP

Related Classes of org.apache.openejb.util.classloader.ClassLoaderComparator

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.