Search in sources :

Example 1 with ParseConfigResourceToDOMTask

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()]);
}
Also used : ParseConfigResourceToDOMTask(com.sun.faces.config.manager.tasks.ParseConfigResourceToDOMTask) ConfigurationResourceProvider(com.sun.faces.spi.ConfigurationResourceProvider) ArrayList(java.util.ArrayList) URI(java.net.URI) ConfigurationException(com.sun.faces.config.ConfigurationException) ExecutionException(java.util.concurrent.ExecutionException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) FutureTask(java.util.concurrent.FutureTask) ConfigurationException(com.sun.faces.config.ConfigurationException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) Collection(java.util.Collection) FindConfigResourceURIsTask(com.sun.faces.config.manager.tasks.FindConfigResourceURIsTask) ExecutionException(java.util.concurrent.ExecutionException) DocumentInfo(com.sun.faces.config.manager.documents.DocumentInfo)

Aggregations

ConfigurationException (com.sun.faces.config.ConfigurationException)1 DocumentInfo (com.sun.faces.config.manager.documents.DocumentInfo)1 FindConfigResourceURIsTask (com.sun.faces.config.manager.tasks.FindConfigResourceURIsTask)1 ParseConfigResourceToDOMTask (com.sun.faces.config.manager.tasks.ParseConfigResourceToDOMTask)1 ConfigurationResourceProvider (com.sun.faces.spi.ConfigurationResourceProvider)1 URI (java.net.URI)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 ExecutionException (java.util.concurrent.ExecutionException)1 FutureTask (java.util.concurrent.FutureTask)1 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1