All Downloads are FREE. Search and download functionalities are using the official Maven repository.

javax.faces.FactoryFinder Maven / Gradle / Ivy

Go to download

This is the master POM file for Sun's Implementation of the JSF 2.1 Specification.

There is a newer version: 2.2.20
Show newest version
/*
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
 *
 * Copyright (c) 1997-2010 Oracle and/or its affiliates. All rights reserved.
 *
 * The contents of this file are subject to the terms of either the GNU
 * General Public License Version 2 only ("GPL") or the Common Development
 * and Distribution License("CDDL") (collectively, the "License").  You
 * may not use this file except in compliance with the License.  You can
 * obtain a copy of the License at
 * https://glassfish.dev.java.net/public/CDDL+GPL_1_1.html
 * or packager/legal/LICENSE.txt.  See the License for the specific
 * language governing permissions and limitations under the License.
 *
 * When distributing the software, include this License Header Notice in each
 * file and include the License file at packager/legal/LICENSE.txt.
 *
 * GPL Classpath Exception:
 * Oracle designates this particular file as subject to the "Classpath"
 * exception as provided by Oracle in the GPL Version 2 section of the License
 * file that accompanied this code.
 *
 * Modifications:
 * If applicable, add the following below the License Header, with the fields
 * enclosed by brackets [] replaced by your own identifying information:
 * "Portions Copyright [year] [name of copyright owner]"
 *
 * Contributor(s):
 * If you wish your version of this file to be governed by only the CDDL or
 * only the GPL Version 2, indicate your decision by adding "[Contributor]
 * elects to include this software in this distribution under the [CDDL or GPL
 * Version 2] license."  If you don't indicate a single choice of license, a
 * recipient has the option to distribute your version of this file under
 * either the CDDL, the GPL Version 2 or to extend the choice of license to
 * its licensees as provided above.  However, if you add GPL Version 2 code
 * and therefore, elected the GPL Version 2 license, then the option applies
 * only if the new code is made subject to such option by the copyright
 * holder.
 */

package javax.faces;


/**
 * 

FactoryFinder * implements the standard discovery algorithm for all factory objects * specified in the JavaServer Faces APIs. For a given factory class * name, a corresponding implementation class is searched for based on * the following algorithm. Items are listed in order of decreasing * search precedence:

*
    *
  • If the JavaServer Faces configuration file bundled into the * WEB-INF directory of the webapp contains a * factory entry of the given factory class name, that * factory is used.

  • *
  • If the JavaServer Faces configuration files named by the * javax.faces.CONFIG_FILES ServletContext init * parameter contain any factory entries of the given * factory class name, those injectionProvider are used, with the last one taking * precedence.

  • *
  • If there are any JavaServer Faces configuration files bundled * into the META-INF directory of any jars on the * ServletContext's resource paths, the * factory entries of the given factory class name in those * files are used, with the last one taking precedence.

  • *
  • If a META-INF/services/{factory-class-name} * resource is visible to the web application class loader for the * calling application (typically as a injectionProvider of being present in the * manifest of a JAR file), its first line is read and assumed to be the * name of the factory implementation class to use.

  • *
  • If none of the above steps yield a match, the JavaServer Faces * implementation specific class is used.

  • *
*

If any of the injectionProvider found on any of the steps above happen to * have a one-argument constructor, with argument the type being the * abstract factory class, that constructor is invoked, and the previous * match is passed to the constructor. For example, say the container * vendor provided an implementation of {@link * javax.faces.context.FacesContextFactory}, and identified it in * META-INF/services/javax.faces.context.FacesContextFactory * in a jar on the webapp ClassLoader. Also say this implementation * provided by the container vendor had a one argument constructor that * took a FacesContextFactory instance. The * FactoryFinder system would call that one-argument * constructor, passing the implementation of * FacesContextFactory provided by the JavaServer Faces * implementation.

*

If a Factory implementation does not provide a proper one-argument * constructor, it must provide a zero-arguments constructor in order to * be successfully instantiated.

*

Once the name of the factory implementation class is located, the * web application class loader for the calling application is requested * to load this class, and a corresponding instance of the class will be * created. A side effect of this rule is that each web application * will receive its own instance of each factory class, whether the * JavaServer Faces implementation is included within the web * application or is made visible through the container's facilities for * shared libraries.

*/ public final class FactoryFinder { // ----------------------------------------------------------- Constructors /** * Package-private constructor to disable instantiation of this class. */ FactoryFinder() { } // ----------------------------------------------------- Manifest Constants /** *

The property name for the * {@link javax.faces.application.ApplicationFactory} class name.

*/ public final static String APPLICATION_FACTORY = "javax.faces.application.ApplicationFactory"; /** *

The property name for the * {@link javax.faces.lifecycle.ClientWindowFactory} class name.

* @since 2.2 */ public final static String CLIENT_WINDOW_FACTORY = "javax.faces.lifecycle.ClientWindowFactory"; /** *

The property name for the {@link * javax.faces.context.ExceptionHandlerFactory} class name.

*/ public final static String EXCEPTION_HANDLER_FACTORY = "javax.faces.context.ExceptionHandlerFactory"; /** *

The property name for the {@link * javax.faces.context.ExternalContextFactory} class name.

*/ public final static String EXTERNAL_CONTEXT_FACTORY = "javax.faces.context.ExternalContextFactory"; /** *

The property name for the * {@link javax.faces.context.FacesContextFactory} class name.

*/ public final static String FACES_CONTEXT_FACTORY = "javax.faces.context.FacesContextFactory"; /** *

The property name for the * {@link javax.faces.view.facelets.FaceletCacheFactory} class name.

* * @since 2.1 */ public final static String FACELET_CACHE_FACTORY = "javax.faces.view.facelets.FaceletCacheFactory"; /** *

The property name for the * {@link javax.faces.context.FlashFactory} class name.

* * @since 2.2 */ public final static String FLASH_FACTORY = "javax.faces.context.FlashFactory"; /** *

The property name for the * {@link javax.faces.flow.FlowHandlerFactory} class name.

* * @since 2.2 */ public final static String FLOW_HANDLER_FACTORY = "javax.faces.flow.FlowHandlerFactory"; /** *

The property name for the {@link * javax.faces.context.PartialViewContextFactory} class name.

*/ public final static String PARTIAL_VIEW_CONTEXT_FACTORY = "javax.faces.context.PartialViewContextFactory"; /** *

The property name for the {@link * javax.faces.component.visit.VisitContextFactory} class name.

*/ public final static String VISIT_CONTEXT_FACTORY = "javax.faces.component.visit.VisitContextFactory"; /** *

The property name for the * {@link javax.faces.lifecycle.LifecycleFactory} class name.

*/ public final static String LIFECYCLE_FACTORY = "javax.faces.lifecycle.LifecycleFactory"; /** *

The property name for the * {@link javax.faces.render.RenderKitFactory} class name.

*/ public final static String RENDER_KIT_FACTORY = "javax.faces.render.RenderKitFactory"; /** *

The property name for the {@link * javax.faces.view.ViewDeclarationLanguage} class name.

*/ public final static String VIEW_DECLARATION_LANGUAGE_FACTORY = "javax.faces.view.ViewDeclarationLanguageFactory"; /** *

The property name for the {@link * javax.faces.view.facelets.TagHandlerDelegate} class name.

*/ public final static String TAG_HANDLER_DELEGATE_FACTORY = "javax.faces.view.facelets.TagHandlerDelegateFactory"; // ------------------------------------------------------- Static Variables static final CurrentThreadToServletContext FACTORIES_CACHE; static { FACTORIES_CACHE = new CurrentThreadToServletContext(); } // --------------------------------------------------------- Public Methods /** *

Create (if * necessary) and return a per-web-application instance of the * appropriate implementation class for the specified JavaServer * Faces factory class, based on the discovery algorithm described * in the class description.

* *

The standard injectionProvider and wrappers * in JSF all implement the interface {@link FacesWrapper}. If the * returned Object is an implementation of one of the * standard injectionProvider, it must be legal to cast it to an instance of * FacesWrapper and call {@link * FacesWrapper#getWrapped} on the instance.

* * @param factoryName Fully qualified name of the JavaServer Faces factory * for which an implementation instance is requested * @throws FacesException if the web application class loader * cannot be identified * @throws FacesException if an instance of the configured factory * implementation class cannot be loaded * @throws FacesException if an instance of the configured factory * implementation class cannot be instantiated * @throws IllegalArgumentException if factoryName does not * identify a standard JavaServer Faces factory name * @throws IllegalStateException if there is no configured factory * implementation class for the specified factory name * @throws NullPointerException if factoryname * is null */ public static Object getFactory(String factoryName) throws FacesException { FactoryFinderInstance manager; // Bug 20458755: If the factory being requested is the special // SERVLET_CONTEXT_FINDER, do not lazily create the FactoryFinderInstance. if (null != factoryName && factoryName.equals(ServletContextFacesContextFactory.SERVLET_CONTEXT_FINDER_NAME)) { manager = FACTORIES_CACHE.getApplicationFactoryManager(false); } else { manager = FACTORIES_CACHE.getApplicationFactoryManager(); } Object result = null; if (null != manager) { result = manager.getFactory(factoryName); } return result; } /** *

This method will store the argument * factoryName/implName mapping in such a way that * {@link #getFactory} will find this mapping when searching for a * match.

*

*

This method has no effect if getFactory() has * already been called looking for a factory for this * factoryName.

*

*

This method can be used by implementations to store a factory * mapping while parsing the Faces configuration file

* * @throws IllegalArgumentException if factoryName does not * identify a standard JavaServer Faces factory name * @throws NullPointerException if factoryname * is null */ public static void setFactory(String factoryName, String implName) { FactoryFinderInstance manager = FACTORIES_CACHE.getApplicationFactoryManager(); manager.addFactory(factoryName, implName); } /** *

Release any * references to factory instances associated with the class loader * for the calling web application. This method must be called during of * web application shutdown.

* * @throws FacesException if the web application class loader * cannot be identified */ public static void releaseFactories() throws FacesException { synchronized(FACTORIES_CACHE) { if (!FACTORIES_CACHE.applicationMap.isEmpty()) { FactoryFinderInstance fm = FACTORIES_CACHE.getApplicationFactoryManager(); fm.releaseFactories(); } FACTORIES_CACHE.removeApplicationFactoryManager(); } } // -------------------------------------------------------- Private Methods // Called via reflection from automated tests. private static void reInitializeFactoryManager() { FACTORIES_CACHE.resetSpecialInitializationCaseFlags(); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy