Exemplo n.º 1
0
  @Override
  protected void storeSyntheticAnnotatedType(
      BeanDeployment deployment, AnnotatedType<?> type, String id) {
    SlimAnnotatedType<?> annotatedType =
        transformer.getUnbackedAnnotatedType(type, getBeanManager().getId(), id);
    Extension extension = getReceiver();
    SlimAnnotatedTypeContext<?> annotatedTypeContext =
        SlimAnnotatedTypeContext.of(annotatedType, extension);

    ProcessAnnotatedTypeImpl<?> event =
        events.fireProcessAnnotatedType(getBeanManager(), annotatedTypeContext);
    if (event == null) {
      deployment.getBeanDeployer().getEnvironment().addAnnotatedType(annotatedTypeContext);
      store.put(annotatedType);
    } else if (event.isVeto()) {
      return;
    } else {
      annotatedType = event.getResultingAnnotatedType();
      deployment
          .getBeanDeployer()
          .getEnvironment()
          .addSyntheticAnnotatedType(annotatedType, extension);
      store.put(annotatedType);
    }
  }
  protected <T> void processBeanRegistration(
      BeanRegistration registration, GlobalEnablementBuilder globalEnablementBuilder) {
    Bean<?> bean = registration.getBean();
    BeanManagerImpl beanManager = registration.getBeanManager();
    if (beanManager == null) {
      // Get the bean manager for beans added via ABD#addBean()
      beanManager = getOrCreateBeanDeployment(bean.getBeanClass()).getBeanManager();
    } else {
      // Also validate the bean produced by a builder
      ExternalBeanAttributesFactory.validateBeanAttributes(bean, getBeanManager());
      validateBean(bean);
    }

    // Custom beans (alternatives, interceptors, decorators) may also implement
    // javax.enterprise.inject.spi.Prioritized
    Integer priority = (bean instanceof Prioritized) ? ((Prioritized) bean).getPriority() : null;

    if (bean instanceof Interceptor<?>) {
      beanManager.addInterceptor((Interceptor<?>) bean);
      if (priority != null) {
        globalEnablementBuilder.addInterceptor(bean.getBeanClass(), priority);
      }
    } else if (bean instanceof Decorator<?>) {
      beanManager.addDecorator(CustomDecoratorWrapper.of((Decorator<?>) bean, beanManager));
      if (priority != null) {
        globalEnablementBuilder.addDecorator(bean.getBeanClass(), priority);
      }
    } else {
      beanManager.addBean(bean);
      if (priority != null && bean.isAlternative()) {
        globalEnablementBuilder.addAlternative(bean.getBeanClass(), priority);
      }
    }
    containerLifecycleEvents.fireProcessBean(beanManager, bean, registration.getExtension());
  }
 private void processAdditionalObserver(ObserverMethod<?> observer) {
   validateObserverMethod(observer, getBeanManager(), null);
   BeanManagerImpl manager = getOrCreateBeanDeployment(observer.getBeanClass()).getBeanManager();
   if (Observers.isObserverMethodEnabled(observer, manager)) {
     ObserverMethod<?> processedObserver =
         containerLifecycleEvents.fireProcessObserverMethod(manager, observer);
     if (processedObserver != null) {
       manager.addObserver(processedObserver);
     }
   }
 }