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); } }
/** * 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; }
/** * This method bootstraps JSF based on the parsed configuration resources. * * @param sc the <code>ServletContext</code> for the application that requires initialization */ public void initialize(ServletContext sc) { if (!hasBeenInitialized(sc)) { initializedContexts.add(sc); try { WebConfiguration webConfig = WebConfiguration.getInstance(sc); boolean validating = webConfig.isOptionEnabled(ValidateFacesConfigFiles); ExecutorService executor = createExecutorService(); Document[] facesDocuments = getConfigDocuments(sc, getFacesConfigResourceProviders(), executor, validating); WebInfFacesConfigInfo facesConfigInfo = new WebInfFacesConfigInfo(facesDocuments[facesDocuments.length - 1]); facesDocuments = sortDocuments(facesDocuments, facesConfigInfo); boolean isFaceletsDisabled = isFaceletsDisabled(webConfig, facesConfigInfo); if (!facesConfigInfo.isMetadataComplete()) { // execute the Task responsible for finding annotation classes Future<Map<Class<? extends Annotation>, Set<Class<?>>>> annotationScan = executor.submit(new AnnotationScanTask(sc)); pushTaskToContext(sc, annotationScan); } // process the ordered documents FACES_CONFIG_PROCESSOR_CHAIN.process(facesDocuments); if (!isFaceletsDisabled) { FACELET_TAGLIB_CONFIG_PROCESSOR_CHAIN.process( getConfigDocuments(sc, getFaceletConfigResourceProviders(), executor, validating)); } executor.shutdown(); publishPostConfigEvent(); } catch (Exception e) { // clear out any configured factories releaseFactories(); if (LOGGER.isLoggable(Level.INFO)) { LOGGER.log(Level.INFO, "Unsanitized stacktrace from failed start...", e); } Throwable t = unwind(e); throw new ConfigurationException("CONFIGURATION FAILED! " + t.getMessage(), t); } finally { sc.removeAttribute(ANNOTATIONS_SCAN_TASK_KEY); } } }
/** * 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()]); }
static { // initialize the resource providers for faces-config documents List<ConfigurationResourceProvider> facesConfigProviders = new ArrayList<ConfigurationResourceProvider>(3); facesConfigProviders.add(new MojarraFacesConfigResourceProvider()); facesConfigProviders.add(new MetaInfFacesConfigResourceProvider()); facesConfigProviders.add(new WebFacesConfigResourceProvider()); FACES_CONFIG_RESOURCE_PROVIDERS = Collections.unmodifiableList(facesConfigProviders); // initialize the resource providers for facelet-taglib documents List<ConfigurationResourceProvider> faceletTaglibProviders = new ArrayList<ConfigurationResourceProvider>(3); faceletTaglibProviders.add(new MetaInfFaceletTaglibraryConfigProvider()); faceletTaglibProviders.add(new WebFaceletTaglibResourceProvider()); FACELET_TAGLIBRARY_RESOURCE_PROVIDERS = Collections.unmodifiableList(faceletTaglibProviders); // initialize the config processors for faces-config documents ConfigProcessor[] configProcessors = { new FactoryConfigProcessor(), new LifecycleConfigProcessor(), new ApplicationConfigProcessor(), new ComponentConfigProcessor(), new ConverterConfigProcessor(), new ValidatorConfigProcessor(), new ManagedBeanConfigProcessor(), new RenderKitConfigProcessor(), new NavigationConfigProcessor(), new BehaviorConfigProcessor(), }; for (int i = 0; i < configProcessors.length; i++) { ConfigProcessor p = configProcessors[i]; if ((i + 1) < configProcessors.length) { p.setNext(configProcessors[i + 1]); } } FACES_CONFIG_PROCESSOR_CHAIN = configProcessors[0]; // initialize the config processor for facelet-taglib documents FACELET_TAGLIB_CONFIG_PROCESSOR_CHAIN = new FaceletTaglibConfigProcessor(); }
/** * @param sc the <code>ServletContext</code> for the application in question * @return <code>true</code> if this application has already been initialized, otherwise returns * </code>fase</code> */ public boolean hasBeenInitialized(ServletContext sc) { return (initializedContexts.contains(sc)); }
/** * This method will remove any information about the application. * * @param sc the <code>ServletContext</code> for the application that needs to be removed */ public void destory(ServletContext sc) { releaseFactories(); initializedContexts.remove(sc); }