Ejemplo n.º 1
0
  /**
   * This method bootstraps JSF based on the parsed configuration resources.
   *
   * @param sc the <code>ServletContext</code> for the application that requires initialization
   */
  public void initialize(ServletContext sc) {

    if (!hasBeenInitialized(sc)) {
      initializedContexts.add(sc);
      try {
        WebConfiguration webConfig = WebConfiguration.getInstance(sc);
        boolean validating = webConfig.isOptionEnabled(ValidateFacesConfigFiles);
        ExecutorService executor = createExecutorService();

        Document[] facesDocuments =
            getConfigDocuments(sc, getFacesConfigResourceProviders(), executor, validating);

        WebInfFacesConfigInfo facesConfigInfo =
            new WebInfFacesConfigInfo(facesDocuments[facesDocuments.length - 1]);

        facesDocuments = sortDocuments(facesDocuments, facesConfigInfo);

        boolean isFaceletsDisabled = isFaceletsDisabled(webConfig, facesConfigInfo);
        if (!facesConfigInfo.isMetadataComplete()) {
          // execute the Task responsible for finding annotation classes
          Future<Map<Class<? extends Annotation>, Set<Class<?>>>> annotationScan =
              executor.submit(new AnnotationScanTask(sc));
          pushTaskToContext(sc, annotationScan);
        }

        // process the ordered documents
        FACES_CONFIG_PROCESSOR_CHAIN.process(facesDocuments);
        if (!isFaceletsDisabled) {
          FACELET_TAGLIB_CONFIG_PROCESSOR_CHAIN.process(
              getConfigDocuments(sc, getFaceletConfigResourceProviders(), executor, validating));
        }

        executor.shutdown();
        publishPostConfigEvent();
      } catch (Exception e) {
        // clear out any configured factories
        releaseFactories();
        if (LOGGER.isLoggable(Level.INFO)) {
          LOGGER.log(Level.INFO, "Unsanitized stacktrace from failed start...", e);
        }
        Throwable t = unwind(e);
        throw new ConfigurationException("CONFIGURATION FAILED! " + t.getMessage(), t);
      } finally {
        sc.removeAttribute(ANNOTATIONS_SCAN_TASK_KEY);
      }
    }
  }
Ejemplo n.º 2
0
  static {

    // initialize the resource providers for faces-config documents
    List<ConfigurationResourceProvider> facesConfigProviders =
        new ArrayList<ConfigurationResourceProvider>(3);
    facesConfigProviders.add(new MojarraFacesConfigResourceProvider());
    facesConfigProviders.add(new MetaInfFacesConfigResourceProvider());
    facesConfigProviders.add(new WebFacesConfigResourceProvider());
    FACES_CONFIG_RESOURCE_PROVIDERS = Collections.unmodifiableList(facesConfigProviders);

    // initialize the resource providers for facelet-taglib documents
    List<ConfigurationResourceProvider> faceletTaglibProviders =
        new ArrayList<ConfigurationResourceProvider>(3);
    faceletTaglibProviders.add(new MetaInfFaceletTaglibraryConfigProvider());
    faceletTaglibProviders.add(new WebFaceletTaglibResourceProvider());
    FACELET_TAGLIBRARY_RESOURCE_PROVIDERS = Collections.unmodifiableList(faceletTaglibProviders);

    // initialize the config processors for faces-config documents
    ConfigProcessor[] configProcessors = {
      new FactoryConfigProcessor(),
      new LifecycleConfigProcessor(),
      new ApplicationConfigProcessor(),
      new ComponentConfigProcessor(),
      new ConverterConfigProcessor(),
      new ValidatorConfigProcessor(),
      new ManagedBeanConfigProcessor(),
      new RenderKitConfigProcessor(),
      new NavigationConfigProcessor(),
      new BehaviorConfigProcessor(),
      new FacesConfigExtensionProcessor()
    };
    for (int i = 0; i < configProcessors.length; i++) {
      ConfigProcessor p = configProcessors[i];
      if ((i + 1) < configProcessors.length) {
        p.setNext(configProcessors[i + 1]);
      }
    }
    FACES_CONFIG_PROCESSOR_CHAIN = configProcessors[0];

    // initialize the config processor for facelet-taglib documents
    FACELET_TAGLIB_CONFIG_PROCESSOR_CHAIN = new FaceletTaglibConfigProcessor();
  }
Ejemplo n.º 3
0
  /**
   * This method bootstraps JSF based on the parsed configuration resources.
   *
   * @param sc the <code>ServletContext</code> for the application that requires initialization
   */
  public void initialize(ServletContext sc) {

    if (!hasBeenInitialized(sc)) {
      initializedContexts.add(sc);
      ExecutorService executor = null;
      try {
        WebConfiguration webConfig = WebConfiguration.getInstance(sc);
        boolean validating = webConfig.isOptionEnabled(ValidateFacesConfigFiles);
        if (useThreads(sc)) {
          executor = createExecutorService();
        }

        DocumentInfo[] facesDocuments =
            getConfigDocuments(sc, getFacesConfigResourceProviders(), executor, validating);

        FacesConfigInfo webInfFacesConfigInfo =
            new FacesConfigInfo(facesDocuments[facesDocuments.length - 1]);

        facesDocuments = sortDocuments(facesDocuments, webInfFacesConfigInfo);
        InitFacesContext context = (InitFacesContext) FacesContext.getCurrentInstance();

        InjectionProvider containerConnector =
            InjectionProviderFactory.createInstance(context.getExternalContext());
        context.getAttributes().put(INJECTION_PROVIDER_KEY, containerConnector);

        boolean isFaceletsDisabled = isFaceletsDisabled(webConfig, webInfFacesConfigInfo);
        if (!webInfFacesConfigInfo.isWebInfFacesConfig()
            || !webInfFacesConfigInfo.isMetadataComplete()) {
          // execute the Task responsible for finding annotation classes
          ProvideMetadataToAnnotationScanTask taskMetadata =
              new ProvideMetadataToAnnotationScanTask(facesDocuments, containerConnector);
          Future<Map<Class<? extends Annotation>, Set<Class<?>>>> annotationScan;
          if (executor != null) {
            annotationScan = executor.submit(new AnnotationScanTask(sc, context, taskMetadata));
            pushTaskToContext(sc, annotationScan);
          } else {
            annotationScan =
                new FutureTask<Map<Class<? extends Annotation>, Set<Class<?>>>>(
                    new AnnotationScanTask(sc, context, taskMetadata));
            ((FutureTask) annotationScan).run();
          }
          pushTaskToContext(sc, annotationScan);
        }

        // see if the app is running in a HA enabled env
        if (containerConnector instanceof HighAvailabilityEnabler) {
          ((HighAvailabilityEnabler) containerConnector).enableHighAvailability(sc);
        }
        // process the ordered documents
        FACES_CONFIG_PROCESSOR_CHAIN.process(sc, facesDocuments);
        if (!isFaceletsDisabled) {
          FACELET_TAGLIB_CONFIG_PROCESSOR_CHAIN.process(
              sc,
              getConfigDocuments(sc, getFaceletConfigResourceProviders(), executor, validating));
        }

        publishPostConfigEvent();
      } catch (Exception e) {
        // clear out any configured factories
        releaseFactories();
        Throwable t = e;
        if (!(e instanceof ConfigurationException)) {
          t = new ConfigurationException("CONFIGURATION FAILED! " + t.getMessage(), t);
        }
        throw (ConfigurationException) t;
      } finally {
        if (executor != null) {
          executor.shutdown();
        }
        sc.removeAttribute(ANNOTATIONS_SCAN_TASK_KEY);
      }
    }
  }