예제 #1
0
  /**
   * Obtains an array of <code>Document</code>s to be processed by {@link
   * ConfigManager#FACES_CONFIG_PROCESSOR_CHAIN}.
   *
   * @param sc 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>Document</code>s
   */
  private static Document[] getConfigDocuments(
      ServletContext sc,
      List<ConfigurationResourceProvider> providers,
      ExecutorService executor,
      boolean validating) {

    List<FutureTask<Collection<URL>>> urlTasks =
        new ArrayList<FutureTask<Collection<URL>>>(providers.size());
    for (ConfigurationResourceProvider p : providers) {
      FutureTask<Collection<URL>> t = new FutureTask<Collection<URL>>(new URLTask(p, sc));
      urlTasks.add(t);
      executor.execute(t);
    }

    List<FutureTask<Document>> docTasks =
        new ArrayList<FutureTask<Document>>(providers.size() << 1);

    for (FutureTask<Collection<URL>> t : urlTasks) {
      try {
        Collection<URL> l = t.get();
        for (URL u : l) {
          FutureTask<Document> d = new FutureTask<Document>(new ParseTask(validating, u));
          docTasks.add(d);
          executor.execute(d);
        }
      } catch (InterruptedException ignored) {
      } catch (Exception e) {
        throw new ConfigurationException(e);
      }
    }

    List<Document> docs = new ArrayList<Document>(docTasks.size());
    for (FutureTask<Document> t : docTasks) {
      try {
        docs.add(t.get());
      } catch (ExecutionException e) {
        throw new ConfigurationException(e);
      } catch (InterruptedException ignored) {
      }
    }

    return docs.toArray(new Document[docs.size()]);
  }
예제 #2
0
  private List<ConfigurationResourceProvider> getConfigurationResourceProviders(
      List<ConfigurationResourceProvider> defaultProviders,
      ConfigurationResourceProviderFactory.ProviderType providerType) {

    ConfigurationResourceProvider[] custom =
        ConfigurationResourceProviderFactory.createProviders(providerType);
    if (custom.length == 0) {
      return defaultProviders;
    } else {
      List<ConfigurationResourceProvider> list = new ArrayList<ConfigurationResourceProvider>();
      list.addAll(defaultProviders);
      // insert the custom providers after the META-INF providers and
      // before those that scan /WEB-INF
      list.addAll((defaultProviders.size() - 1), Arrays.asList(custom));
      return Collections.unmodifiableList(list);
    }
  }
예제 #3
0
  /**
   * Sort the <code>faces-config</code> documents found on the classpath and those specified by the
   * <code>javax.faces.CONFIG_FILES</code> context init parameter.
   *
   * @param facesDocuments an array of <em>all</em> <code>faces-config</code> documents
   * @param facesConfig WebInfoFacesConfigInfo for this app
   * @return the sorted documents
   */
  private Document[] sortDocuments(Document[] facesDocuments, WebInfFacesConfigInfo facesConfig) {

    int len = (facesConfig.exists() ? facesDocuments.length - 1 : facesDocuments.length);

    List<String> absoluteOrdering = facesConfig.getAbsoluteOrdering();

    if (len > 1) {
      List<DocumentOrderingWrapper> list = new ArrayList<DocumentOrderingWrapper>();
      for (int i = 1; i < len; i++) {
        list.add(new DocumentOrderingWrapper(facesDocuments[i]));
      }
      DocumentOrderingWrapper[] ordering = list.toArray(new DocumentOrderingWrapper[list.size()]);
      if (absoluteOrdering == null) {
        DocumentOrderingWrapper.sort(ordering);
        // sorting complete, now update the appropriate locations within
        // the original array with the sorted documentation.
        for (int i = 1; i < len; i++) {
          facesDocuments[i] = ordering[i - 1].getDocument();
        }
        return facesDocuments;
      } else {
        DocumentOrderingWrapper[] result = DocumentOrderingWrapper.sort(ordering, absoluteOrdering);
        Document[] ret =
            new Document[((facesConfig.exists()) ? (result.length + 2) : (result.length + 1))];
        for (int i = 1; i < len; i++) {
          ret[i] = result[i - 1].getDocument();
        }
        // add the impl specific config file
        ret[0] = facesDocuments[0];
        // add the WEB-INF if necessary
        if (facesConfig.exists()) {
          ret[ret.length - 1] = facesDocuments[facesDocuments.length - 1];
        }
        return ret;
      }
    }

    return facesDocuments;
  }