@Override public void init(final Object object) { if (!(object instanceof StartupObject)) { return; } 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(); final AnnotationManager annotationManager = webBeansContext.getAnnotationManager(); 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) { // 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.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.addStereoTypeAlternative(clazz, null, null); 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.addClazzAlternative(clazz, null, null); 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 Iterator<String> it = beans.managedClasses.iterator(); while (it.hasNext()) { process(classLoader, it, startupObject, comparator, scl, filterByClassLoader); } final Collection<String> otherClasses = ADDITIONAL_CLASSES.get(); if (otherClasses != null) { final Iterator<String> it2 = otherClasses.iterator(); while (it2.hasNext()) { process(classLoader, it2, startupObject, comparator, scl, filterByClassLoader); } } if (startupObject.getBeanContexts() != null) { // ensure ejbs are in managed beans otherwise they will not be deployed in CDI for (final BeanContext bc : startupObject.getBeanContexts()) { final String name = bc.getBeanClass().getName(); if (BeanContext.Comp.class.getName().equals(name)) { continue; } final Class<?> load = load(name, classLoader); if (load != null && !classes.contains(load)) { classes.add(load); } } } addContainerCdiClasses(classLoader, appInfo, ejbJar); } }