@Override
 public void setAnnotatedType(AnnotatedType<X> type) {
   if (configurator != null) {
     throw BootstrapLogger.LOG.configuratorAndSetMethodBothCalled(
         ProcessAnnotatedType.class.getSimpleName(), getReceiver());
   }
   checkWithinObserverNotification();
   if (type == null) {
     throw BootstrapLogger.LOG.annotationTypeNull(this);
   }
   replaceAnnotatedType(type);
   annotatedTypeSet = true;
   BootstrapLogger.LOG.setAnnotatedTypeCalled(getReceiver(), annotatedType, type);
 }
Ejemplo n.º 2
0
 protected static void verifyServices(
     ServiceRegistry services, Set<Class<? extends Service>> requiredServices, Object target) {
   for (Class<? extends Service> serviceType : requiredServices) {
     if (!services.contains(serviceType)) {
       throw BootstrapLogger.LOG.unspecifiedRequiredService(serviceType.getName(), target);
     }
   }
 }
 private void replaceAnnotatedType(AnnotatedType<X> type) {
   if (!this.originalAnnotatedType.getJavaClass().equals(type.getJavaClass())) {
     throw BootstrapLogger.LOG.annotatedTypeJavaClassMismatch(
         this.annotatedType.getJavaClass(), type.getJavaClass());
   }
   AnnotatedTypeValidator.validateAnnotatedType(type);
   this.annotatedType = type;
 }
 @Override
 public void addObserverMethod(ObserverMethod<?> observerMethod) {
   checkWithinObserverNotification();
   Preconditions.checkArgumentNotNull(observerMethod, "observerMethod");
   validateObserverMethod(observerMethod, getBeanManager(), null);
   additionalObservers.add(observerMethod);
   BootstrapLogger.LOG.addObserverMethodCalled(getReceiver(), observerMethod);
 }
Ejemplo n.º 5
0
 private void checkApiVersion() {
   if (Bean.class.getInterfaces().length == 1) {
     // this means Bean only extends Contextual - since CDI 1.1 Bean also extends BeanAttributes
     // CDI 1.0 API is detected on classpath - since that would result in obscure exception later,
     // we
     // throw an appropriate exception right now
     throw BootstrapLogger.LOG.cdiApiVersionMismatch();
   }
 }
 @Override
 public void addBean(Bean<?> bean) {
   checkWithinObserverNotification();
   Preconditions.checkArgumentNotNull(bean, "bean");
   ExternalBeanAttributesFactory.validateBeanAttributes(bean, getBeanManager());
   validateBean(bean);
   additionalBeans.add(BeanRegistration.of(bean, getReceiver()));
   BootstrapLogger.LOG.addBeanCalled(getReceiver(), bean);
 }
Ejemplo n.º 7
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);
 }
 @Override
 public AnnotatedTypeConfigurator<X> configureAnnotatedType() {
   if (annotatedTypeSet) {
     throw BootstrapLogger.LOG.configuratorAndSetMethodBothCalled(
         ProcessAnnotatedType.class.getSimpleName(), getReceiver());
   }
   checkWithinObserverNotification();
   if (configurator == null) {
     configurator = new AnnotatedTypeConfiguratorImpl<>(annotatedType);
   }
   return configurator;
 }
Ejemplo n.º 9
0
 // needs to be resolved once extension beans are deployed
 private void installFastProcessAnnotatedTypeResolver(ServiceRegistry services) {
   ClassFileServices classFileServices = services.get(ClassFileServices.class);
   if (classFileServices != null) {
     final GlobalObserverNotifierService observers =
         services.get(GlobalObserverNotifierService.class);
     try {
       final FastProcessAnnotatedTypeResolver resolver =
           new FastProcessAnnotatedTypeResolver(observers.getAllObserverMethods());
       services.add(FastProcessAnnotatedTypeResolver.class, resolver);
     } catch (UnsupportedObserverMethodException e) {
       BootstrapLogger.LOG.notUsingFastResolver(e.getObserver());
       return;
     }
   }
 }
Ejemplo n.º 10
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();
    }
  }
Ejemplo n.º 11
0
 @Override
 public void addContext(Context context) {
   checkWithinObserverNotification();
   Preconditions.checkArgumentNotNull(context, "context");
   Class<? extends Annotation> scope = context.getScope();
   if (scope == null) {
     throw ContextLogger.LOG.contextHasNullScope(context);
   }
   if (!getBeanManager().isScope(scope)) {
     MetadataLogger.LOG.contextGetScopeIsNotAScope(scope, context);
   }
   if (scope == ApplicationScoped.class || scope == Dependent.class) {
     throw ContextLogger.LOG.cannotRegisterContext(scope, context);
   }
   getBeanManager().addContext(context);
   BootstrapLogger.LOG.addContext(getReceiver(), context);
 }
Ejemplo n.º 12
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);
        }
      }
    }
  }
Ejemplo n.º 13
0
  public WeldRuntime startContainer(
      String contextId, Environment environment, Deployment deployment) {
    if (deployment == null) {
      throw BootstrapLogger.LOG.deploymentRequired();
    }

    checkApiVersion();

    final ServiceRegistry registry = deployment.getServices();

    // initiate part of registry in order to allow access to WeldConfiguration
    new AdditionalServiceLoader(deployment).loadAdditionalServices(registry);

    // Resource Loader has to be loaded prior to WeldConfiguration
    if (!registry.contains(ResourceLoader.class)) {
      registry.add(ResourceLoader.class, DefaultResourceLoader.INSTANCE);
    }

    WeldConfiguration configuration = new WeldConfiguration(registry, deployment);
    registry.add(WeldConfiguration.class, configuration);

    String finalContextId =
        BeanDeployments.getFinalId(
            contextId,
            registry.get(WeldConfiguration.class).getStringProperty(ROLLING_UPGRADES_ID_DELIMITER));
    this.contextId = finalContextId;
    this.deployment = deployment;
    this.environment = environment;

    if (this.extensions == null) {
      setExtensions(deployment.getExtensions());
    }
    // Add extension to register built-in components
    this.extensions.add(MetadataImpl.from(new WeldExtension()));

    // Add Weld extensions
    String vetoTypeRegex =
        configuration.getStringProperty(
            ConfigurationKey.VETO_TYPES_WITHOUT_BEAN_DEFINING_ANNOTATION);
    if (!vetoTypeRegex.isEmpty()) {
      this.extensions.add(MetadataImpl.from(new WeldVetoExtension(vetoTypeRegex)));
    }

    // Finish the rest of registry init, setupInitialServices() requires already changed
    // finalContextId
    setupInitialServices();
    registry.addAll(initialServices.entrySet());

    if (!registry.contains(ProxyServices.class)) {
      registry.add(ProxyServices.class, new SimpleProxyServices());
    }
    if (!registry.contains(SecurityServices.class)) {
      registry.add(SecurityServices.class, NoopSecurityServices.INSTANCE);
    }

    addImplementationServices(registry);

    verifyServices(registry, environment.getRequiredDeploymentServices(), contextId);
    if (!registry.contains(TransactionServices.class)) {
      BootstrapLogger.LOG.jtaUnavailable();
    }

    this.deploymentManager = BeanManagerImpl.newRootManager(finalContextId, "deployment", registry);

    Container.initialize(
        finalContextId,
        deploymentManager,
        ServiceRegistries.unmodifiableServiceRegistry(deployment.getServices()));
    getContainer().setState(ContainerState.STARTING);

    this.contexts = createContexts(registry);

    this.bdaMapping = new BeanDeploymentArchiveMapping();
    this.deploymentVisitor =
        new DeploymentVisitor(deploymentManager, environment, deployment, contexts, bdaMapping);

    if (deployment instanceof CDI11Deployment) {
      registry.add(
          BeanManagerLookupService.class,
          new BeanManagerLookupService(
              (CDI11Deployment) deployment, bdaMapping.getBdaToBeanManagerMap()));
    } else {
      BootstrapLogger.LOG.legacyDeploymentMetadataProvided();
    }

    // Read the deployment structure, bdaMapping will be the physical structure
    // as caused by the presence of beans.xml
    deploymentVisitor.visit();

    return new WeldRuntime(finalContextId, deploymentManager, bdaMapping.getBdaToBeanManagerMap());
  }
Ejemplo n.º 14
0
 @Override
 public void addAnnotatedType(AnnotatedType<?> type, String id) {
   checkWithinObserverNotification();
   addSyntheticAnnotatedType(type, id);
   BootstrapLogger.LOG.addAnnotatedTypeCalled(getReceiver(), type);
 }
 @Override
 public void veto() {
   checkWithinObserverNotification();
   this.veto = true;
   BootstrapLogger.LOG.annotatedTypeVetoed(getReceiver(), annotatedType);
 }