コード例 #1
0
 protected BeanDeployerEnvironment(
     Set<SlimAnnotatedTypeContext<?>> annotatedTypes,
     Set<Class<?>> vetoedClasses,
     SetMultimap<Class<?>, AbstractClassBean<?>> classBeanMap,
     Set<ProducerField<?, ?>> producerFields,
     SetMultimap<WeldMethodKey, ProducerMethod<?, ?>> producerMethodBeanMap,
     Set<RIBean<?>> beans,
     Set<ObserverInitializationContext<?, ?>> observers,
     Set<DisposalMethod<?, ?>> allDisposalBeans,
     Set<DisposalMethod<?, ?>> resolvedDisposalBeans,
     Set<DecoratorImpl<?>> decorators,
     Set<InterceptorImpl<?>> interceptors,
     Set<Type> newBeanTypes,
     BeanManagerImpl manager) {
   this.annotatedTypes = annotatedTypes;
   this.vetoedClasses = vetoedClasses;
   this.classBeanMap = classBeanMap;
   this.producerFields = producerFields;
   this.producerMethodBeanMap = producerMethodBeanMap;
   this.beans = beans;
   this.observers = observers;
   this.allDisposalBeans = allDisposalBeans;
   this.resolvedDisposalBeans = resolvedDisposalBeans;
   this.decorators = decorators;
   this.interceptors = interceptors;
   this.disposalMethodResolver =
       new TypeSafeDisposerResolver(
           allDisposalBeans, manager.getServices().get(WeldConfiguration.class));
   this.classTransformer = manager.getServices().get(ClassTransformer.class);
   this.newBeanTypes = newBeanTypes;
   this.manager = manager;
 }
コード例 #2
0
ファイル: SlimAnnotatedType.java プロジェクト: hasys/core
 /*
  * It may in theory happen that an app calls BeanManager.createAnnotatedType() for a previously unknown class on node1 and then
  * stores this annotated type in session. On node2, this annotated type is not know. We'll try to load it.
  */
 private SlimAnnotatedType<?> tryToLoadUnknownBackedAnnotatedType() {
   if (identifier.getSuffix() != null || identifier.isModified()) {
     return null; // this is not a backed annotated type
   }
   // first, obtain the BeanManager for a given BDA
   final BeanManagerImpl manager =
       Container.instance(identifier).getBeanManager(identifier.getBdaId());
   if (manager == null) {
     return null;
   }
   // second, try to load the class
   final ResourceLoader resourceLoader = manager.getServices().get(ResourceLoader.class);
   Class<?> clazz = null;
   try {
     clazz = resourceLoader.classForName(identifier.getClassName());
   } catch (ResourceLoadingException e) {
     MetadataLogger.LOG.catchingDebug(e);
     return null;
   }
   // finally, try to load the annotated type
   try {
     return manager
         .getServices()
         .get(ClassTransformer.class)
         .getBackedAnnotatedType(clazz, identifier.getBdaId());
   } catch (ResourceLoadingException e) {
     MetadataLogger.LOG.catchingDebug(e);
     return null;
   }
 }
コード例 #3
0
 protected AfterTypeDiscoveryImpl(
     BeanManagerImpl beanManager,
     BeanDeploymentArchiveMapping bdaMapping,
     Deployment deployment,
     Collection<ContextHolder<? extends Context>> contexts) {
   super(beanManager, AfterTypeDiscovery.class, bdaMapping, deployment, contexts);
   this.builder = beanManager.getServices().get(GlobalEnablementBuilder.class);
   this.events = beanManager.getServices().get(ContainerLifecycleEvents.class);
   this.transformer = beanManager.getServices().get(ClassTransformer.class);
   this.store = beanManager.getServices().get(SlimAnnotatedTypeStore.class);
 }
コード例 #4
0
 private AfterBeanDiscoveryImpl(
     BeanManagerImpl beanManager,
     Deployment deployment,
     BeanDeploymentArchiveMapping bdaMapping,
     Collection<ContextHolder<? extends Context>> contexts) {
   super(beanManager, WeldAfterBeanDiscovery.class, bdaMapping, deployment, contexts);
   this.slimAnnotatedTypeStore = beanManager.getServices().get(SlimAnnotatedTypeStore.class);
   this.containerLifecycleEvents = beanManager.getServices().get(ContainerLifecycleEvents.class);
   this.additionalBeans = new LinkedList<BeanRegistration>();
   this.additionalObservers = new LinkedList<ObserverMethod<?>>();
   this.additionalObserverConfigurators = new LinkedList<ObserverMethodConfigurator<?>>();
 }
コード例 #5
0
ファイル: Validator.java プロジェクト: edpzjh/core
 /** finds pseudo beans and adds them to the list of beans to be validated */
 private static void validatePseudoScopedInjectionPoint(
     InjectionPoint ij,
     BeanManagerImpl beanManager,
     Set<Bean<?>> dependencyPath,
     Set<Bean<?>> validatedBeans) {
   Set<Bean<?>> resolved = beanManager.getBeans(ij);
   try {
     Bean<? extends Object> bean = beanManager.resolve(resolved);
     if (bean != null) {
       if (!(bean instanceof AbstractBuiltInBean<?>)) {
         boolean normalScoped =
             beanManager
                 .getServices()
                 .get(MetaAnnotationStore.class)
                 .getScopeModel(bean.getScope())
                 .isNormal();
         if (!normalScoped) {
           reallyValidatePseudoScopedBean(bean, beanManager, dependencyPath, validatedBeans);
         }
       }
     }
   } catch (AmbiguousResolutionException e) {
     // this is handled by another validator
   }
 }
コード例 #6
0
ファイル: WeldRuntime.java プロジェクト: treblereel/core-1
  public void shutdown() {
    try {
      // First, the container must destroy all contexts.
      deploymentManager.instance().select(ApplicationContext.class).get().invalidate();
      deploymentManager.instance().select(SingletonContext.class).get().invalidate();

    } finally {
      try {
        // fire @Destroyed(ApplicationScoped.class) for non-web modules
        // web modules are handled by HttpContextLifecycle
        for (BeanDeploymentModule module :
            deploymentManager.getServices().get(BeanDeploymentModules.class)) {
          if (!module.isWebModule()) {
            module.fireEvent(
                Object.class, ContextEvent.APPLICATION_DESTROYED, DestroyedLiteral.APPLICATION);
          }
        }
      } catch (Exception ignored) {
      }
      try {
        // Finally, the container must fire an event of type BeforeShutdown.
        BeforeShutdownImpl.fire(deploymentManager);
      } finally {
        Container container = Container.instance(contextId);
        container.setState(ContainerState.SHUTDOWN);
        container.cleanup();
      }
    }
  }
コード例 #7
0
 public InjectionTargetService(BeanManagerImpl beanManager) {
   this.validator = beanManager.getServices().get(Validator.class);
   this.producersToValidate = new ConcurrentLinkedQueue<Producer<?>>();
   this.injectionTargetsToInitialize =
       new ConcurrentLinkedQueue<InjectionTargetInitializationContext<?>>();
   this.container = Container.instance(beanManager);
   this.beanManager = beanManager;
 }
コード例 #8
0
ファイル: BeanManagerProxy.java プロジェクト: weld/core
 public BeanManagerProxy(BeanManagerImpl manager) {
   this.manager = manager;
   this.nonPortableMode =
       manager
           .getServices()
           .get(WeldConfiguration.class)
           .getBooleanProperty(ConfigurationKey.NON_PORTABLE_MODE);
 }
コード例 #9
0
ファイル: WeldStartup.java プロジェクト: subaochen/core
 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);
 }
コード例 #10
0
  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;
  }
コード例 #11
0
 // TODO Move class stuff into startContainer phase
 // TODO read EJB descriptors after reading classes
 public void deployBeans(Environment environment) {
   beanDeployer.addClasses(loadClasses());
   beanDeployer.fireProcessAnnotatedTypeForTypesAddedThroughTheSPI();
   beanDeployer.getEnvironment().addBuiltInBean(new InjectionPointBean(beanManager));
   beanDeployer.getEnvironment().addBuiltInBean(new EventBean(beanManager));
   beanDeployer.getEnvironment().addBuiltInBean(new InstanceBean(beanManager));
   beanDeployer.getEnvironment().addBuiltInBean(new ConversationBean(beanManager));
   if (beanManager.getServices().contains(TransactionServices.class)) {
     beanDeployer.getEnvironment().addBuiltInBean(new UserTransactionBean(beanManager));
   }
   if (beanManager.getServices().contains(SecurityServices.class)) {
     beanDeployer.getEnvironment().addBuiltInBean(new PrincipalBean(beanManager));
   }
   if (beanManager.getServices().contains(ValidationServices.class)) {
     beanDeployer.getEnvironment().addBuiltInBean(new DefaultValidatorBean(beanManager));
     beanDeployer.getEnvironment().addBuiltInBean(new DefaultValidatorFactoryBean(beanManager));
   }
   // Register the context beans
   for (ContextHolder<? extends Context> context : contexts) {
     beanDeployer.getEnvironment().addBuiltInBean(ContextBean.of(context, beanManager));
   }
   // TODO Register the context beans
   beanDeployer.createBeans().deploy();
 }
コード例 #12
0
ファイル: Validator.java プロジェクト: edpzjh/core
 /**
  * Returns true if the bean should be validated according to CDI 1.0 (6.6.4). This is the case if
  * the bean declares a passivating scope or is a SFSB.
  */
 protected boolean isPassivationCapabilityCheckRequired(
     BeanManagerImpl beanManager, AbstractClassBean<?> classBean) {
   if (beanManager
       .getServices()
       .get(MetaAnnotationStore.class)
       .getScopeModel(classBean.getScope())
       .isPassivating()) {
     return true;
   }
   if ((classBean instanceof SessionBean<?>)
       && ((SessionBean<?>) classBean).getEjbDescriptor().isStateful()) {
     return true;
   }
   return false;
 }
コード例 #13
0
ファイル: AbstractClassBean.java プロジェクト: edpzjh/core
 /**
  * Extracts the complete set of interception bindings from a given set of annotations.
  *
  * @param beanManager
  * @param annotations
  * @return
  */
 protected static Set<Annotation> flattenInterceptorBindings(
     BeanManagerImpl beanManager, Set<Annotation> annotations) {
   Set<Annotation> foundInterceptionBindingTypes = new HashSet<Annotation>();
   for (Annotation annotation : annotations) {
     if (beanManager.isInterceptorBinding(annotation.annotationType())) {
       foundInterceptionBindingTypes.add(annotation);
       foundInterceptionBindingTypes.addAll(
           beanManager
               .getServices()
               .get(MetaAnnotationStore.class)
               .getInterceptorBindingModel(annotation.annotationType())
               .getInheritedInterceptionBindingTypes());
     }
   }
   return foundInterceptionBindingTypes;
 }
コード例 #14
0
ファイル: Validator.java プロジェクト: edpzjh/core
 private void validateBean(Bean<?> bean, BeanManagerImpl beanManager) {
   for (InjectionPoint ij : bean.getInjectionPoints()) {
     validateInjectionPoint(ij, beanManager);
   }
   boolean normalScoped =
       beanManager
           .getServices()
           .get(MetaAnnotationStore.class)
           .getScopeModel(bean.getScope())
           .isNormal();
   if (normalScoped && !Beans.isBeanProxyable(bean)) {
     throw Proxies.getUnproxyableTypesException(bean);
   }
   if (!normalScoped) {
     validatePseudoScopedBean(bean, beanManager);
   }
 }
コード例 #15
0
ファイル: WeldStartup.java プロジェクト: subaochen/core
  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();
    }
  }
コード例 #16
0
ファイル: Validator.java プロジェクト: edpzjh/core
 /**
  * Variation of the validateInjectionPoint method which allows the bean to be defined explicitly
  * (used for disposer method validation)
  */
 public void validateInjectionPoint(InjectionPoint ij, Bean<?> bean, BeanManagerImpl beanManager) {
   if (ij.getAnnotated().getAnnotation(New.class) != null && ij.getQualifiers().size() > 1) {
     throw new DefinitionException(NEW_WITH_QUALIFIERS, ij);
   }
   if (ij.getType().equals(InjectionPoint.class) && bean == null) {
     throw new DefinitionException(INJECTION_INTO_NON_BEAN, ij);
   }
   if (ij.getType().equals(InjectionPoint.class) && !Dependent.class.equals(bean.getScope())) {
     throw new DefinitionException(INJECTION_INTO_NON_DEPENDENT_BEAN, ij);
   }
   if (ij.getType() instanceof TypeVariable<?>) {
     throw new DefinitionException(INJECTION_POINT_WITH_TYPE_VARIABLE, ij);
   }
   if (!(ij.getMember() instanceof Field)
       && ij.getAnnotated().isAnnotationPresent(Named.class)
       && ij.getAnnotated().getAnnotation(Named.class).value().equals("")) {
     throw new DefinitionException(NON_FIELD_INJECTION_POINT_CANNOT_USE_NAMED, ij);
   }
   boolean newBean = (bean instanceof NewManagedBean<?>) || (bean instanceof NewSessionBean<?>);
   if (!newBean) {
     checkScopeAnnotations(ij, beanManager.getServices().get(MetaAnnotationStore.class));
   }
   checkFacadeInjectionPoint(ij, Instance.class);
   checkFacadeInjectionPoint(ij, Event.class);
   Annotation[] bindings = ij.getQualifiers().toArray(new Annotation[0]);
   Set<?> resolvedBeans = beanManager.getBeanResolver().resolve(beanManager.getBeans(ij));
   if (!isInjectionPointSatisfied(ij, resolvedBeans, beanManager)) {
     throw new DeploymentException(
         INJECTION_POINT_HAS_UNSATISFIED_DEPENDENCIES,
         ij,
         Formats.formatAnnotations(bindings),
         Formats.formatType(ij.getType()));
   }
   if (resolvedBeans.size() > 1 && !ij.isDelegate()) {
     throw new DeploymentException(
         INJECTION_POINT_HAS_AMBIGUOUS_DEPENDENCIES,
         ij,
         Formats.formatAnnotations(bindings),
         Formats.formatType(ij.getType()),
         resolvedBeans);
   }
   // Account for the case this is disabled decorator
   if (!resolvedBeans.isEmpty()) {
     Bean<?> resolvedBean = (Bean<?>) resolvedBeans.iterator().next();
     if (beanManager
         .getServices()
         .get(MetaAnnotationStore.class)
         .getScopeModel(resolvedBean.getScope())
         .isNormal()) {
       UnproxyableResolutionException ue = Proxies.getUnproxyableTypeException(ij.getType());
       if (ue != null) {
         UnproxyableResolutionException exception =
             new UnproxyableResolutionException(
                 INJECTION_POINT_HAS_NON_PROXYABLE_DEPENDENCIES, ij);
         exception.initCause(ue);
         throw exception;
       }
     }
     if (Reflections.isPrimitive(ij.getType()) && resolvedBean.isNullable()) {
       throw new NullableDependencyException(INJECTION_POINT_HAS_NULLABLE_DEPENDENCIES, ij);
     }
     if (bean != null
         && Beans.isPassivatingScope(bean, beanManager)
         && (!ij.isTransient())
         && !Beans.isPassivationCapableBean(resolvedBean)) {
       validateInjectionPointPassivationCapable(ij, resolvedBean, beanManager);
     }
   }
 }
コード例 #17
0
ファイル: WeldStartup.java プロジェクト: subaochen/core
  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);
        }
      }
    }
  }