示例#1
0
 @Override
 public void init(final Application application) {
   AnnotationEventDispatcherConfig config = new AnnotationEventDispatcherConfig();
   application.setMetaData(ANNOTATION_EVENT_DISPATCHER_CONFIG_CONTEXT_KEY, config);
   AnnotationEventDispatcher dispatcher = new AnnotationEventDispatcher();
   application.getComponentInstantiationListeners().add(dispatcher);
   application.getFrameworkSettings().add(dispatcher);
 }
  /**
   * Configures the specified application
   *
   * @param application
   * @return
   */
  public CdiContainer configure(Application application) {
    if (beanManager == null) {
      throw new IllegalStateException(
          "Configuration does not have a BeanManager instance configured");
    }

    CdiContainer container = new CdiContainer(beanManager, nonContextualManager);
    container.bind(application);

    RequestCycleListenerCollection listeners = new RequestCycleListenerCollection();
    application.getRequestCycleListeners().add(listeners);

    // enable conversation propagation
    if (getPropagation() != ConversationPropagation.NONE) {
      listeners.add(new ConversationPropagator(application, container, getPropagation()));
      application
          .getComponentPreOnBeforeRenderListeners()
          .add(new ConversationExpiryChecker(container));
      SeamConversationContextFactory.setDisableNoopInstance(true);
    }

    // enable detach event
    listeners.add(new DetachEventEmitter(container));

    // inject application instance
    if (isInjectApplication()) {
      container.getNonContextualManager().postConstruct(application);
    }

    // enable injection of various framework components

    if (isInjectSession()) {
      application.getSessionListeners().add(new SessionInjector(container));
    }

    if (isInjectComponents()) {
      application.getComponentInstantiationListeners().add(new ComponentInjector(container));
    }

    if (isInjectBehaviors()) {
      application.getBehaviorInstantiationListeners().add(new BehaviorInjector(container));
    }

    // enable cleanup

    application
        .getApplicationListeners()
        .add(new CdiShutdownCleaner(beanManager, isInjectApplication()));

    return container;
  }