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;
  }
 @Override
 protected void initValid() {
   super.initValid();
   if (!getAnnotatedAnnotation().isAnnotationPresent(Target.class)) {
     this.valid = false;
     log.debug(MISSING_TARGET, getAnnotatedAnnotation());
   } else if (!Arrays2.unorderedEquals(
       getAnnotatedAnnotation().getAnnotation(Target.class).value(), METHOD, FIELD, TYPE)) {
     this.valid = false;
     log.debug(MISSING_TARGET_METHOD_FIELD_TYPE, getAnnotatedAnnotation());
   }
 }
  protected void activateConversationContext(HttpServletRequest request) {
    HttpConversationContext conversationContext = httpConversationContext();
    String cid = getConversationId(request, httpConversationContext());
    log.debug(RESUMING_CONVERSATION, cid);

    /*
     * Don't try to reactivate the ConversationContext if we have already activated it for this request WELD-877
     */
    if (!isContextActivatedInRequest(request)) {
      setContextActivatedInRequest(request);
      conversationContext.activate(cid);
      if (cid == null) { // transient conversation
        beanManager
            .getAccessibleLenientObserverNotifier()
            .fireEvent(request, InitializedLiteral.CONVERSATION);
      }
    } else {
      /*
       * We may have previously been associated with a ConversationContext, but the reference to that context may have
       * been lost during a Servlet forward WELD-877
       */
      conversationContext.dissociate(request);
      conversationContext.associate(request);
      conversationContext.activate(cid);
    }
  }