public BeanDeployment( BeanDeploymentArchive beanDeploymentArchive, BeanManagerImpl deploymentManager, ServiceRegistry deploymentServices, Collection<ContextHolder<? extends Context>> contexts) { this.beanDeploymentArchive = beanDeploymentArchive; EjbDescriptors ejbDescriptors = new EjbDescriptors(); beanDeploymentArchive.getServices().add(EjbDescriptors.class, ejbDescriptors); if (beanDeploymentArchive.getServices().get(ResourceLoader.class) == null) { beanDeploymentArchive.getServices().add(ResourceLoader.class, DefaultResourceLoader.INSTANCE); } ServiceRegistry services = new SimpleServiceRegistry(); services.addAll(deploymentServices.entrySet()); services.addAll(beanDeploymentArchive.getServices().entrySet()); services.add( EJBApiAbstraction.class, new EJBApiAbstraction(beanDeploymentArchive.getServices().get(ResourceLoader.class))); services.add( JsfApiAbstraction.class, new JsfApiAbstraction(beanDeploymentArchive.getServices().get(ResourceLoader.class))); services.add( PersistenceApiAbstraction.class, new PersistenceApiAbstraction( beanDeploymentArchive.getServices().get(ResourceLoader.class))); services.add( WSApiAbstraction.class, new WSApiAbstraction(beanDeploymentArchive.getServices().get(ResourceLoader.class))); this.beanManager = BeanManagerImpl.newManager( deploymentManager, beanDeploymentArchive.getId(), services, Enabled.of( beanDeploymentArchive.getBeansXml(), beanDeploymentArchive.getServices().get(ResourceLoader.class))); log.debug( ENABLED_ALTERNATIVES, this.beanManager, beanManager.getEnabled().getAlternativeClasses(), beanManager.getEnabled().getAlternativeStereotypes()); log.debug(ENABLED_DECORATORS, this.beanManager, beanManager.getEnabled().getDecorators()); log.debug(ENABLED_INTERCEPTORS, this.beanManager, beanManager.getEnabled().getInterceptors()); if (beanManager.getServices().contains(EjbServices.class)) { // Must populate EJB cache first, as we need it to detect whether a // bean is an EJB! ejbDescriptors.addAll(beanDeploymentArchive.getEjbs()); } beanDeployer = new BeanDeployer(beanManager, ejbDescriptors); // Must at the Manager bean straight away, as it can be injected during startup! beanManager.addBean(new BeanManagerBean(beanManager)); this.contexts = contexts; }
private static boolean isInjectionPointSatisfied( InjectionPoint ij, Set<?> resolvedBeans, BeanManagerImpl beanManager) { if (ij.getBean() instanceof Decorator<?>) { if (beanManager.getEnabled().getDecorator(ij.getBean().getBeanClass()) != null) { return resolvedBeans.size() > 0; } else { return true; } } else { return resolvedBeans.size() > 0; } }
private void validateEnabledAlternatives(BeanManagerImpl beanManager) { for (Metadata<Class<? extends Annotation>> stereotype : beanManager.getEnabled().getAlternativeStereotypes()) { if (!beanManager.isStereotype(stereotype.getValue())) { throw new DeploymentException(ALTERNATIVE_STEREOTYPE_NOT_STEREOTYPE, stereotype); } if (!isAlternative(beanManager, stereotype.getValue())) { throw new DeploymentException(ALTERNATIVE_STEREOTYPE_NOT_ANNOTATED, stereotype); } } for (Metadata<Class<?>> clazz : beanManager.getEnabled().getAlternativeClasses()) { if (clazz.getValue().isAnnotation() || clazz.getValue().isInterface()) { throw new DeploymentException(ALTERNATIVE_BEAN_CLASS_NOT_CLASS, clazz); } WeldClass<?> weldClass = Container.instance().services().get(ClassTransformer.class).loadClass(clazz.getValue()); if (!weldClass.isAnnotationPresent(Alternative.class)) { throw new DeploymentException(ALTERNATIVE_BEAN_CLASS_NOT_ANNOTATED, clazz); } } }
private void validateEnabledInterceptorClasses(BeanManagerImpl beanManager) { Set<Class<?>> interceptorBeanClasses = new HashSet<Class<?>>(); for (Interceptor<?> interceptor : beanManager.getAccessibleInterceptors()) { interceptorBeanClasses.add(interceptor.getBeanClass()); } for (Metadata<Class<?>> enabledInterceptorClass : beanManager.getEnabled().getInterceptors()) { if (!interceptorBeanClasses.contains(enabledInterceptorClass.getValue())) { throw new DeploymentException( INTERCEPTOR_NOT_ANNOTATED_OR_REGISTERED, enabledInterceptorClass); } } }
private void validateEnabledDecoratorClasses(BeanManagerImpl beanManager) { // TODO Move building this list to the boot or sth Set<Class<?>> decoratorBeanClasses = new HashSet<Class<?>>(); for (Decorator<?> bean : beanManager.getAccessibleDecorators()) { decoratorBeanClasses.add(bean.getBeanClass()); } for (Metadata<Class<?>> clazz : beanManager.getEnabled().getDecorators()) { if (!decoratorBeanClasses.contains(clazz.getValue())) { throw new DeploymentException( DECORATOR_CLASS_NOT_BEAN_CLASS_OF_DECORATOR, clazz, decoratorBeanClasses); } } }