com.sun.faces.config.ConfigManager Maven / Gradle / Ivy
Show all versions of jakarta.faces Show documentation
/*
* Copyright (c) 1997, 2020 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* This Source Code may also be made available under the following Secondary
* Licenses when the conditions for such availability set forth in the
* Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
* version 2 with the GNU Classpath Exception, which is available at
* https://www.gnu.org/software/classpath/license.html.
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
*/
package com.sun.faces.config;
import static com.sun.faces.RIConstants.FACES_PREFIX;
import static com.sun.faces.config.WebConfiguration.BooleanWebContextInitParameter.EnableThreading;
import static com.sun.faces.config.WebConfiguration.BooleanWebContextInitParameter.ValidateFacesConfigFiles;
import static com.sun.faces.config.manager.Documents.getProgrammaticDocuments;
import static com.sun.faces.config.manager.Documents.getXMLDocuments;
import static com.sun.faces.config.manager.Documents.mergeDocuments;
import static com.sun.faces.config.manager.Documents.sortDocuments;
import static com.sun.faces.spi.ConfigurationResourceProviderFactory.ProviderType.FaceletConfig;
import static com.sun.faces.spi.ConfigurationResourceProviderFactory.ProviderType.FacesConfig;
import static com.sun.faces.spi.ConfigurationResourceProviderFactory.createProviders;
import static java.util.Arrays.asList;
import static java.util.Collections.emptyMap;
import static java.util.Collections.unmodifiableList;
import static java.util.logging.Level.FINE;
import java.lang.annotation.Annotation;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.ServiceLoader;
import java.util.Set;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.FutureTask;
import java.util.logging.Logger;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import com.sun.faces.config.configpopulator.MojarraRuntimePopulator;
import com.sun.faces.config.configprovider.MetaInfFaceletTaglibraryConfigProvider;
import com.sun.faces.config.configprovider.MetaInfFacesConfigResourceProvider;
import com.sun.faces.config.configprovider.WebAppFlowConfigResourceProvider;
import com.sun.faces.config.configprovider.WebFaceletTaglibResourceProvider;
import com.sun.faces.config.configprovider.WebFacesConfigResourceProvider;
import com.sun.faces.config.manager.DbfFactory;
import com.sun.faces.config.manager.FacesConfigInfo;
import com.sun.faces.config.manager.documents.DocumentInfo;
import com.sun.faces.config.manager.tasks.FindAnnotatedConfigClasses;
import com.sun.faces.config.manager.tasks.ProvideMetadataToAnnotationScanTask;
import com.sun.faces.config.processor.ApplicationConfigProcessor;
import com.sun.faces.config.processor.BehaviorConfigProcessor;
import com.sun.faces.config.processor.ComponentConfigProcessor;
import com.sun.faces.config.processor.ConfigProcessor;
import com.sun.faces.config.processor.ConverterConfigProcessor;
import com.sun.faces.config.processor.FaceletTaglibConfigProcessor;
import com.sun.faces.config.processor.FacesConfigExtensionProcessor;
import com.sun.faces.config.processor.FacesFlowDefinitionConfigProcessor;
import com.sun.faces.config.processor.FactoryConfigProcessor;
import com.sun.faces.config.processor.LifecycleConfigProcessor;
import com.sun.faces.config.processor.NavigationConfigProcessor;
import com.sun.faces.config.processor.ProtectedViewsConfigProcessor;
import com.sun.faces.config.processor.RenderKitConfigProcessor;
import com.sun.faces.config.processor.ResourceLibraryContractsConfigProcessor;
import com.sun.faces.config.processor.ValidatorConfigProcessor;
import com.sun.faces.el.ELContextImpl;
import com.sun.faces.spi.ConfigurationResourceProvider;
import com.sun.faces.spi.ConfigurationResourceProviderFactory;
import com.sun.faces.spi.HighAvailabilityEnabler;
import com.sun.faces.spi.InjectionProvider;
import com.sun.faces.spi.InjectionProviderFactory;
import com.sun.faces.spi.ThreadContext;
import com.sun.faces.util.FacesLogger;
import jakarta.el.ELContext;
import jakarta.el.ELContextEvent;
import jakarta.el.ELContextListener;
import jakarta.faces.FacesException;
import jakarta.faces.FactoryFinder;
import jakarta.faces.application.Application;
import jakarta.faces.application.ApplicationConfigurationPopulator;
import jakarta.faces.context.FacesContext;
import jakarta.faces.event.PostConstructApplicationEvent;
import jakarta.servlet.ServletContext;
/**
*
* This class manages the initialization of each web application that uses Faces.
*
*/
public class ConfigManager {
private static final Logger LOGGER = FacesLogger.CONFIG.getLogger();
/**
* The initialization time FacesContext scoped key under which the InjectionProvider is stored.
*/
public static final String INJECTION_PROVIDER_KEY = ConfigManager.class.getName() + "_INJECTION_PROVIDER_TASK";
/**
*
* The ConfigManager
will multithread the calls to the ConfigurationResourceProvider
s as well
* as any calls to parse a resources into a DOM. By default, we'll use only 5 threads per web application.
*
*/
private static final int NUMBER_OF_TASK_THREADS = 5;
private static final String CONFIG_MANAGER_INSTANCE_KEY = FACES_PREFIX + "CONFIG_MANAGER_KEY";
/**
* The application-scoped key under which the Future responsible for annotation scanning is associated with.
*/
private static final String ANNOTATIONS_SCAN_TASK_KEY = ConfigManager.class.getName() + "_ANNOTATION_SCAN_TASK";
/**
*
* Contains each ServletContext
that we've initialized. The ServletContext
will be removed
* when the application is destroyed.
*
*/
private final List initializedContexts = new CopyOnWriteArrayList<>();
private final List configProcessors = List.of(
new FactoryConfigProcessor(),
new LifecycleConfigProcessor(),
new ApplicationConfigProcessor(),
new ComponentConfigProcessor(),
new ConverterConfigProcessor(),
new ValidatorConfigProcessor(),
new RenderKitConfigProcessor(),
new NavigationConfigProcessor(),
new BehaviorConfigProcessor(),
new FacesConfigExtensionProcessor(),
new ProtectedViewsConfigProcessor(),
new FacesFlowDefinitionConfigProcessor(),
new ResourceLibraryContractsConfigProcessor());
/**
*
* A List of resource providers that search for faces-config documents. By default, this contains a provider for the
* Mojarra, and two other providers to satisfy the requirements of the specification.
*
*/
private final List facesConfigProviders = List.of(
new MetaInfFacesConfigResourceProvider(), new WebAppFlowConfigResourceProvider(), new WebFacesConfigResourceProvider());
/**
*
* A List of resource providers that search for faces-config documents. By default, this contains a provider for the
* Mojarra, and one other providers to satisfy the requirements of the specification.
*
*/
private final List facesletsTagLibConfigProviders = List.of(
new MetaInfFaceletTaglibraryConfigProvider(), new WebFaceletTaglibResourceProvider());
/**
*
* The chain of {@link ConfigProcessor} instances to processing of facelet-taglib documents.
*
*/
private final ConfigProcessor faceletTaglibConfigProcessor = new FaceletTaglibConfigProcessor();
// ---------------------------------------------------------- Public STATIC Methods
public static ConfigManager createInstance(ServletContext servletContext) {
ConfigManager result = new ConfigManager();
servletContext.setAttribute(CONFIG_MANAGER_INSTANCE_KEY, result);
return result;
}
/**
* @param servletContext the involved servlet context
* @return a ConfigManager
instance
*/
public static ConfigManager getInstance(ServletContext servletContext) {
return (ConfigManager) servletContext.getAttribute(CONFIG_MANAGER_INSTANCE_KEY);
}
/**
* @param ctx the involved faces context
* @return the results of the annotation scan task
*/
public static Map, Set>> getAnnotatedClasses(FacesContext ctx) {
Map appMap = ctx.getExternalContext().getApplicationMap();
@SuppressWarnings("unchecked")
Future