Ejemplo n.º 1
0
 /**
  * Validate an RIBean. This includes validating whether two beans specialize the same bean
  *
  * @param bean the bean to validate
  * @param beanManager the current manager
  * @param specializedBeans the existing specialized beans
  */
 private void validateRIBean(
     RIBean<?> bean, BeanManagerImpl beanManager, Collection<RIBean<?>> specializedBeans) {
   validateBean(bean, beanManager);
   if (!(bean instanceof NewManagedBean<?>) && !(bean instanceof NewSessionBean<?>)) {
     RIBean<?> abstractBean = bean;
     if (abstractBean.isSpecializing()) {
       if (specializedBeans.contains(abstractBean.getSpecializedBean())) {
         throw new InconsistentSpecializationException(BEAN_SPECIALIZED_TOO_MANY_TIMES, bean);
       }
       specializedBeans.add(abstractBean.getSpecializedBean());
     }
     if ((bean instanceof AbstractClassBean<?>)) {
       AbstractClassBean<?> classBean = (AbstractClassBean<?>) bean;
       if (classBean.hasDecorators()) {
         validateDecorators(beanManager, classBean);
       }
       // validate CDI-defined interceptors
       if (classBean.hasInterceptors()) {
         validateInterceptors(beanManager, classBean);
       }
     }
     // for each producer method validate its disposer method
     if (bean instanceof ProducerMethod<?, ?>
         && ((ProducerMethod<?, ?>) bean).getDisposalMethod() != null) {
       DisposalMethod<?, ?> disposalMethod = ((ProducerMethod<?, ?>) bean).getDisposalMethod();
       for (InjectionPoint ip : disposalMethod.getInjectionPoints()) {
         // pass the producer bean instead of the disposal method bean
         validateInjectionPoint(ip, bean, beanManager);
       }
     }
   }
 }
Ejemplo n.º 2
0
  public void endInitialization() {

    final BeanIdentifierIndex index =
        deploymentManager.getServices().get(BeanIdentifierIndex.class);
    if (index != null) {
      // Build a special index of bean identifiers
      index.build(getBeansForBeanIdentifierIndex());
    }

    // TODO rebuild the manager accessibility graph if the bdas have changed
    // Register the managers so external requests can handle them
    // clear the TypeSafeResolvers, so data that is only used at startup
    // is not kept around using up memory
    flushCaches();
    deploymentManager.getServices().cleanupAfterBoot();
    deploymentManager.cleanupAfterBoot();
    for (BeanDeployment beanDeployment : getBeanDeployments()) {
      BeanManagerImpl beanManager = beanDeployment.getBeanManager();
      beanManager.getInterceptorMetadataReader().cleanAfterBoot();
      beanManager.getServices().cleanupAfterBoot();
      beanManager.cleanupAfterBoot();
      // clean up beans
      for (Bean<?> bean : beanManager.getBeans()) {
        if (bean instanceof RIBean<?>) {
          RIBean<?> riBean = (RIBean<?>) bean;
          riBean.cleanupAfterBoot();
        }
      }
      // clean up decorators
      for (Decorator<?> decorator : beanManager.getDecorators()) {
        if (decorator instanceof DecoratorImpl<?>) {
          Reflections.<DecoratorImpl<?>>cast(decorator).cleanupAfterBoot();
        }
      }
      // clean up interceptors
      for (Interceptor<?> interceptor : beanManager.getInterceptors()) {
        if (interceptor instanceof InterceptorImpl<?>) {
          Reflections.<InterceptorImpl<?>>cast(interceptor).cleanupAfterBoot();
        }
      }
    }
    for (BeanDeployment beanDeployment : getBeanDeployments()) {
      beanDeployment.getBeanDeployer().cleanup();
    }
    // feed BeanDeploymentModule registry
    final BeanDeploymentModules modules =
        deploymentManager.getServices().get(BeanDeploymentModules.class);
    if (modules != null) {
      modules.processBeanDeployments(getBeanDeployments());
      BootstrapLogger.LOG.debugv("EE modules: {0}", modules);
    }

    getContainer().setState(ContainerState.INITIALIZED);

    if (modules != null) {
      // fire @Initialized(ApplicationScoped.class) for non-web modules
      // web modules are handled by HttpContextLifecycle
      for (BeanDeploymentModule module : modules) {
        if (!module.isWebModule()) {
          module.fireEvent(
              Object.class, ContextEvent.APPLICATION_INITIALIZED, InitializedLiteral.APPLICATION);
        }
      }
    }
  }