Example #1
0
  protected Collection<ContextHolder<? extends Context>> createContexts(ServiceRegistry services) {
    List<ContextHolder<? extends Context>> contexts =
        new ArrayList<ContextHolder<? extends Context>>();

    BeanIdentifierIndex beanIdentifierIndex = services.get(BeanIdentifierIndex.class);

    /*
     * Register a full set of bound and unbound contexts. Although we may not use all of
     * these (e.g. if we are running in a servlet environment) they may be
     * useful for an application.
     */
    contexts.add(
        new ContextHolder<ApplicationContext>(
            new ApplicationContextImpl(contextId),
            ApplicationContext.class,
            UnboundLiteral.INSTANCE));
    contexts.add(
        new ContextHolder<SingletonContext>(
            new SingletonContextImpl(contextId), SingletonContext.class, UnboundLiteral.INSTANCE));
    contexts.add(
        new ContextHolder<BoundSessionContext>(
            new BoundSessionContextImpl(contextId, beanIdentifierIndex),
            BoundSessionContext.class,
            BoundLiteral.INSTANCE));
    contexts.add(
        new ContextHolder<BoundConversationContext>(
            new BoundConversationContextImpl(contextId, services),
            BoundConversationContext.class,
            BoundLiteral.INSTANCE));
    contexts.add(
        new ContextHolder<BoundRequestContext>(
            new BoundRequestContextImpl(contextId),
            BoundRequestContext.class,
            BoundLiteral.INSTANCE));
    contexts.add(
        new ContextHolder<RequestContext>(
            new RequestContextImpl(contextId), RequestContext.class, UnboundLiteral.INSTANCE));
    contexts.add(
        new ContextHolder<DependentContext>(
            new DependentContextImpl(services.get(ContextualStore.class)),
            DependentContext.class,
            UnboundLiteral.INSTANCE));

    services.get(WeldModules.class).postContextRegistration(contextId, services, contexts);

    /*
     * Register the contexts with the bean manager and add the beans to the
     * deployment manager so that they are easily accessible (contexts are app
     * scoped)
     */
    for (ContextHolder<? extends Context> context : contexts) {
      deploymentManager.addContext(context.getContext());
      deploymentManager.addBean(ContextBean.of(context, deploymentManager));
    }

    return contexts;
  }
 // 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();
 }