use of com.sun.faces.config.manager.documents.DocumentInfo in project mojarra by eclipse-ee4j.
the class ConfigManager method initialize.
// ---------------------------------------------------------- Public instance Methods
/**
* <p>
* This method bootstraps Faces based on the parsed configuration resources.
* </p>
*
* @param servletContext the <code>ServletContext</code> for the application that requires initialization
* @param facesContext the involved initialization faces context
*/
public void initialize(ServletContext servletContext, InitFacesContext facesContext) {
if (!hasBeenInitialized(servletContext)) {
initializedContexts.add(servletContext);
initializeConfigProcessers(servletContext, facesContext);
ExecutorService executor = null;
try {
WebConfiguration webConfig = WebConfiguration.getInstance(servletContext);
boolean validating = webConfig.isOptionEnabled(ValidateFacesConfigFiles);
if (useThreads(servletContext)) {
executor = createExecutorService();
}
// Obtain and merge the XML and Programmatic documents
DocumentInfo[] facesDocuments = mergeDocuments(getXMLDocuments(servletContext, getFacesConfigResourceProviders(), executor, validating), getProgrammaticDocuments(getConfigPopulators()));
FacesConfigInfo lastFacesConfigInfo = new FacesConfigInfo(facesDocuments[facesDocuments.length - 1]);
facesDocuments = sortDocuments(facesDocuments, lastFacesConfigInfo);
InjectionProvider containerConnector = InjectionProviderFactory.createInstance(facesContext.getExternalContext());
facesContext.getAttributes().put(INJECTION_PROVIDER_KEY, containerConnector);
if (!lastFacesConfigInfo.isWebInfFacesConfig() || !lastFacesConfigInfo.isMetadataComplete()) {
findAnnotations(facesDocuments, containerConnector, servletContext, facesContext, executor);
}
// See if the app is running in a HA enabled env
if (containerConnector instanceof HighAvailabilityEnabler) {
((HighAvailabilityEnabler) containerConnector).enableHighAvailability(servletContext);
}
// Process the ordered and merged documents
// This invokes a chain or processors where each processor grabs its own elements of interest
// from each document.
DocumentInfo[] facesDocuments2 = facesDocuments;
configProcessors.subList(0, 3).stream().forEach(e -> {
try {
e.process(servletContext, facesContext, facesDocuments2);
} catch (Exception e2) {
// TODO Auto-generated catch block
e2.printStackTrace();
}
});
long parentThreadId = Thread.currentThread().getId();
ClassLoader parentContextClassLoader = Thread.currentThread().getContextClassLoader();
ThreadContext threadContext = getThreadContext(containerConnector);
Object parentWebContext = threadContext != null ? threadContext.getParentWebContext() : null;
configProcessors.subList(3, configProcessors.size()).stream().forEach(e -> {
long currentThreadId = Thread.currentThread().getId();
InitFacesContext initFacesContext = null;
if (currentThreadId != parentThreadId) {
Thread.currentThread().setContextClassLoader(parentContextClassLoader);
initFacesContext = InitFacesContext.getInstance(servletContext);
if (parentWebContext != null) {
threadContext.propagateWebContextToChild(parentWebContext);
}
} else {
initFacesContext = facesContext;
}
try {
e.process(servletContext, initFacesContext, facesDocuments2);
} catch (Exception e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} finally {
if (currentThreadId != parentThreadId) {
Thread.currentThread().setContextClassLoader(null);
if (parentWebContext != null) {
threadContext.clearChildContext();
}
}
}
});
faceletTaglibConfigProcessor.process(servletContext, facesContext, getXMLDocuments(servletContext, getFaceletConfigResourceProviders(), executor, validating));
} 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();
}
servletContext.removeAttribute(ANNOTATIONS_SCAN_TASK_KEY);
}
}
DbfFactory.removeSchemaMap(servletContext);
}
use of com.sun.faces.config.manager.documents.DocumentInfo in project mojarra by eclipse-ee4j.
the class NavigationConfigProcessor method process.
// -------------------------------------------- Methods from ConfigProcessor
@Override
public void process(ServletContext sc, FacesContext facesContext, DocumentInfo[] documentInfos) throws Exception {
NavigationHandler handler = getApplication().getNavigationHandler();
for (DocumentInfo documentInfo : documentInfos) {
if (LOGGER.isLoggable(FINE)) {
LOGGER.log(FINE, format("Processing navigation-rule elements for document: ''{0}''", documentInfo.getSourceURI()));
}
Document document = documentInfo.getDocument();
String namespace = document.getDocumentElement().getNamespaceURI();
NodeList navigationRules = document.getDocumentElement().getElementsByTagNameNS(namespace, NAVIGATION_RULE);
if (navigationRules != null && navigationRules.getLength() > 0) {
addNavigationRules(navigationRules, handler, sc);
}
}
}
use of com.sun.faces.config.manager.documents.DocumentInfo in project mojarra by eclipse-ee4j.
the class ParseConfigResourceToDOMTask method call.
// ----------------------------------------------- Methods from Callable
/**
* @return the result of the parse operation (a DOM)
* @throws Exception if an error occurs during the parsing process
*/
@Override
public DocumentInfo call() throws Exception {
try {
Timer timer = Timer.getInstance();
if (timer != null) {
timer.startTiming();
}
Document document = getDocument();
if (timer != null) {
timer.stopTiming();
timer.logResult("Parse " + documentURI.toURL().toExternalForm());
}
return new DocumentInfo(document, documentURI);
} catch (Exception e) {
throw new ConfigurationException(format("Unable to parse document ''{0}'': {1}", documentURI.toURL().toExternalForm(), e.getMessage()), e);
}
}
use of com.sun.faces.config.manager.documents.DocumentInfo in project mojarra by eclipse-ee4j.
the class ProvideMetadataToAnnotationScanTask method initializeIvars.
private void initializeIvars(Set<Class<?>> annotatedSet) {
if (uris != null || jarNames != null) {
return;
}
uris = new HashSet<>(documentInfos.length);
jarNames = new HashSet<>(documentInfos.length);
for (DocumentInfo docInfo : documentInfos) {
URI sourceURI = docInfo.getSourceURI();
Matcher jarMatcher = JAR_PATTERN.matcher(sourceURI == null ? "" : sourceURI.toString());
if (jarMatcher.matches()) {
String jarName = jarMatcher.group(2);
if (!jarNames.contains(jarName)) {
FacesConfigInfo configInfo = new FacesConfigInfo(docInfo);
if (!configInfo.isMetadataComplete()) {
uris.add(sourceURI);
jarNames.add(jarName);
} else {
/*
* Because the container annotation scanning does not know anything about faces-config.xml metadata-complete the
* annotatedSet of classes will include classes that are not supposed to be included.
*
* The code below looks at the CodeSource of the class and determines whether or not it should be removed from the
* annotatedSet because the faces-config.xml that owns it has metadata-complete="true".
*/
ArrayList<Class<?>> toRemove = new ArrayList<>(1);
String sourceURIString = sourceURI.toString();
if (annotatedSet != null) {
for (Class<?> clazz : annotatedSet) {
if (sourceURIString.contains(clazz.getProtectionDomain().getCodeSource().getLocation().toString())) {
toRemove.add(clazz);
}
}
annotatedSet.removeAll(toRemove);
}
}
}
}
}
}
use of com.sun.faces.config.manager.documents.DocumentInfo in project mojarra by eclipse-ee4j.
the class Documents method getXMLDocuments.
/**
* <p>
* Obtains an array of <code>Document</code>s to be processed
* </p>
*
* @param servletContext the <code>ServletContext</code> for the application to be processed
* @param providers <code>List</code> of <code>ConfigurationResourceProvider</code> instances that provide the URL of
* the documents to parse.
* @param executor the <code>ExecutorService</code> used to dispatch parse request to
* @param validating flag indicating whether or not the documents should be validated
* @return an array of <code>DocumentInfo</code>s
*/
public static DocumentInfo[] getXMLDocuments(ServletContext servletContext, List<ConfigurationResourceProvider> providers, ExecutorService executor, boolean validating) {
// Query all configuration providers to give us a URL to the configuration they are providing
List<FutureTask<Collection<URI>>> uriTasks = new ArrayList<>(providers.size());
for (ConfigurationResourceProvider provider : providers) {
FutureTask<Collection<URI>> uriTask = new FutureTask<>(new FindConfigResourceURIsTask(provider, servletContext));
uriTasks.add(uriTask);
if (executor != null) {
executor.execute(uriTask);
} else {
uriTask.run();
}
}
// Load and XML parse all documents to which the URLs that we collected above point to
List<FutureTask<DocumentInfo>> docTasks = new ArrayList<>(providers.size() << 1);
for (FutureTask<Collection<URI>> uriTask : uriTasks) {
try {
for (URI uri : uriTask.get()) {
FutureTask<DocumentInfo> docTask = new FutureTask<>(new ParseConfigResourceToDOMTask(servletContext, validating, uri));
docTasks.add(docTask);
if (executor != null) {
executor.execute(docTask);
} else {
docTask.run();
}
}
} catch (InterruptedException ignored) {
} catch (Exception e) {
throw new ConfigurationException(e);
}
}
// Collect the results of the documents we parsed above
List<DocumentInfo> docs = new ArrayList<>(docTasks.size());
for (FutureTask<DocumentInfo> docTask : docTasks) {
try {
docs.add(docTask.get());
} catch (ExecutionException e) {
throw new ConfigurationException(e);
} catch (InterruptedException ignored) {
}
}
return docs.toArray(new DocumentInfo[docs.size()]);
}
Aggregations