@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);
    }
  }
Beispiel #2
0
 public void validateBeans() {
   BootstrapLogger.LOG.validatingBeans();
   for (BeanDeployment beanDeployment : getBeanDeployments()) {
     BeanManagerImpl beanManager = beanDeployment.getBeanManager();
     beanManager.getBeanResolver().clear();
     deployment.getServices().get(Validator.class).validateDeployment(beanManager, beanDeployment);
     beanManager.getServices().get(InjectionTargetService.class).validate();
   }
   getContainer().setState(ContainerState.VALIDATED);
   AfterDeploymentValidationImpl.fire(deploymentManager);
 }
Beispiel #3
0
 /**
  * Right now we only index all session and conversation scoped beans.
  *
  * @return the set of beans the index should be built from
  */
 private Set<Bean<?>> getBeansForBeanIdentifierIndex() {
   Set<Bean<?>> beans = new HashSet<Bean<?>>();
   for (BeanDeployment beanDeployment : getBeanDeployments()) {
     for (Bean<?> bean : beanDeployment.getBeanManager().getBeans()) {
       if (bean.getScope().equals(SessionScoped.class)
           || bean.getScope().equals(ConversationScoped.class)) {
         beans.add(bean);
       }
     }
   }
   return beans;
 }
Beispiel #4
0
 private void flushCaches() {
   deploymentManager.getBeanResolver().clear();
   deploymentManager.getAccessibleLenientObserverNotifier().clear();
   deploymentManager.getGlobalStrictObserverNotifier().clear();
   deploymentManager.getGlobalLenientObserverNotifier().clear();
   deploymentManager.getDecoratorResolver().clear();
   deploymentManager.getInterceptorResolver().clear();
   deploymentManager.getNameBasedResolver().clear();
   for (BeanDeployment beanDeployment : getBeanDeployments()) {
     BeanManagerImpl beanManager = beanDeployment.getBeanManager();
     beanManager.getBeanResolver().clear();
     beanManager.getAccessibleLenientObserverNotifier().clear();
     beanManager.getDecoratorResolver().clear();
     beanManager.getInterceptorResolver().clear();
     beanManager.getNameBasedResolver().clear();
   }
 }
  public ExtensionBeanDeployer deployBeans() {
    ClassTransformer classTransformer =
        Container.instance().deploymentServices().get(ClassTransformer.class);
    for (Extension extension : extensions) {
      @SuppressWarnings("unchecked")
      WeldClass<Extension> clazz =
          (WeldClass<Extension>) classTransformer.loadClass(extension.getClass());

      // Locate the BeanDeployment for this extension
      BeanDeployment beanDeployment =
          DeploymentStructures.getOrCreateBeanDeployment(
              deployment, beanManager, beanDeployments, clazz.getJavaClass());

      ExtensionBean bean = new ExtensionBean(beanDeployment.getBeanManager(), clazz, extension);
      Set<ObserverMethodImpl<?, ?>> observerMethods = new HashSet<ObserverMethodImpl<?, ?>>();
      createObserverMethods(bean, beanDeployment.getBeanManager(), clazz, observerMethods);
      beanDeployment.getBeanManager().addBean(bean);
      for (ObserverMethodImpl<?, ?> observerMethod : observerMethods) {
        observerMethod.initialize();
        beanDeployment.getBeanManager().addObserver(observerMethod);
      }
    }
    return this;
  }
Beispiel #6
0
  public void startInitialization() {
    if (deploymentManager == null) {
      throw BootstrapLogger.LOG.managerNotInitialized();
    }

    Set<BeanDeployment> physicalBeanDeploymentArchives =
        new HashSet<BeanDeployment>(getBeanDeployments());

    ExtensionBeanDeployer extensionBeanDeployer =
        new ExtensionBeanDeployer(deploymentManager, deployment, bdaMapping, contexts);
    extensionBeanDeployer.addExtensions(extensions);
    extensionBeanDeployer.deployBeans();

    installFastProcessAnnotatedTypeResolver(deploymentManager.getServices());

    // Add the Deployment BeanManager Bean to the Deployment BeanManager
    deploymentManager.addBean(new BeanManagerBean(deploymentManager));
    deploymentManager.addBean(new BeanManagerImplBean(deploymentManager));

    // Re-Read the deployment structure, bdaMapping will be the physical
    // structure, and will add in BDAs for any extensions outside a
    // physical BDA
    deploymentVisitor.visit();

    BeforeBeanDiscoveryImpl.fire(deploymentManager, deployment, bdaMapping, contexts);

    // for each physical BDA transform its classes into AnnotatedType instances
    for (BeanDeployment beanDeployment : physicalBeanDeploymentArchives) {
      beanDeployment.createClasses();
    }

    // Re-Read the deployment structure, bdaMapping will be the physical
    // structure, extensions and any classes added using addAnnotatedType
    // outside the physical BDA
    deploymentVisitor.visit();

    for (BeanDeployment beanDeployment : getBeanDeployments()) {
      beanDeployment.createTypes();
    }

    AfterTypeDiscoveryImpl.fire(deploymentManager, deployment, bdaMapping, contexts);

    for (BeanDeployment beanDeployment : getBeanDeployments()) {
      beanDeployment.createEnablement();
    }
  }
Beispiel #7
0
 public BeanManagerImpl getManager(BeanDeploymentArchive beanDeploymentArchive) {
   BeanDeployment beanDeployment = bdaMapping.getBeanDeployment(beanDeploymentArchive);
   return beanDeployment == null ? null : beanDeployment.getBeanManager().getCurrent();
 }
Beispiel #8
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);
        }
      }
    }
  }
Beispiel #9
0
  public void deployBeans() {
    for (BeanDeployment deployment : getBeanDeployments()) {
      deployment.createBeans(environment);
    }
    // we must use separate loops, otherwise cyclic specialization would not work
    for (BeanDeployment deployment : getBeanDeployments()) {
      deployment.getBeanDeployer().processClassBeanAttributes();
      deployment.getBeanDeployer().createProducersAndObservers();
    }
    for (BeanDeployment deployment : getBeanDeployments()) {
      deployment.getBeanDeployer().processProducerAttributes();
      deployment.getBeanDeployer().createNewBeans();
    }

    for (BeanDeployment beanDeployment : getBeanDeployments()) {
      beanDeployment.deploySpecialized(environment);
    }

    // TODO keep a list of new bdas, add them all in, and deploy beans for them, then merge into
    // existing
    for (BeanDeployment beanDeployment : getBeanDeployments()) {
      beanDeployment.deployBeans(environment);
    }

    getContainer().setState(ContainerState.DISCOVERED);

    // Flush caches for BeanManager.getBeans() to be usable in ABD (WELD-1729)
    flushCaches();

    AfterBeanDiscoveryImpl.fire(deploymentManager, deployment, bdaMapping, contexts);

    // Extensions may have registered beans / observers. We need to flush caches.
    flushCaches();

    // If needed, recreate enablement once again - extensions may have registered interceptors,
    // decorators and alternatives
    if (deployment.getServices().getRequired(GlobalEnablementBuilder.class).isDirty()) {
      for (BeanDeployment beanDeployment : getBeanDeployments()) {
        beanDeployment.createEnablement();
      }
    }

    // Re-read the deployment structure, bdaMapping will be the physical
    // structure, extensions, classes, and any beans added using addBean
    // outside the physical structure
    deploymentVisitor.visit();

    for (BeanDeployment beanDeployment : getBeanDeployments()) {
      beanDeployment.getBeanManager().getServices().get(InjectionTargetService.class).initialize();
      beanDeployment.afterBeanDiscovery(environment);
    }
    getContainer().putBeanDeployments(bdaMapping);
    getContainer().setState(ContainerState.DEPLOYED);
  }