use of com.sun.faces.config.manager.tasks.ParseConfigResourceToDOMTask 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