Top Fields Constructors Methods
javax.faces

pack-priv final Class FactoryFinderInstance

extends Object
Class Inheritance
Imports
com.sun.faces.spi.InjectionProvider, java.io.BufferedReader, .IOException, .InputStream, .InputStreamReader, .UnsupportedEncodingException, java.lang.reflect.Constructor, .InvocationTargetException, java.net.URL, .URLConnection, java.text.MessageFormat, java.util.ArrayList, .Arrays, .Collection, .Collections, .Enumeration, .HashMap, .List, .Map, .ResourceBundle, java.util.concurrent.locks.ReentrantReadWriteLock, java.util.logging.Level, .Logger, javax.faces.context.FacesContext

Field Summary

Modifier and TypeField and Description
private final Map<String, Object>
private static final Map<String, Class<T>>
FACTORY_CLASSES

Map of Class instances for the our factory names.

private static final String[]
FACTORY_NAMES

The set of JavaServer Faces factory classes for which the factory discovery mechanism is supported.

private static final String
private final ReentrantReadWriteLock
private static final Logger
private final Map<String, List<String>>
private ServletContextFacesContextFactory

Constructor Summary

AccessConstructor and Description
pack-priv
pack-priv

Method Summary

Modifier and TypeMethod and Description
pack-priv void
addFactory(String factoryName, String implementation)

pack-priv void
private void
private ClassLoader
pack-priv Collection<Object>
pack-priv Object
getFactory(String factoryName)

private Class<T>

Returns:

the java.lang.Class for the argument factory.
getFactoryClass
(String factoryClassName)

private Object
getImplementationInstance(ClassLoader
Class loader for the web application that will be loading the implementation class
classLoader
,
String factoryName, List<E>
A List of implementations for a given factory class.
implementations
)

Load and return an instance of the specified implementation class using the following algorithm.

private Object
getImplGivenPreviousImpl(ClassLoader
the ClassLoader from which to load the class
classLoader
,
String
the fully qualified class name of the factory.
factoryName
,
String
the fully qualified class name of a class that implements the factory.
implName
,
Object
if non-null, the factory instance to be passed to the constructor of the new factory.
previousImpl
)

Implement the decorator pattern for the factory implementation.

private List<String>
getImplNameFromServices(ClassLoader classLoader, String factoryName)

Perform the logic to get the implementation class for the second step of FactoryFinder#getImplementationInstance(ClassLoader, String, java.util.List).

pack-priv InjectionProvider
pack-priv void
private void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

factoriesback to summary
private final Map<String, Object> factories
FACTORY_CLASSESback to summary
private static final Map<String, Class<T>> FACTORY_CLASSES

Map of Class instances for the our factory names.

FACTORY_NAMESback to summary
private static final String[] FACTORY_NAMES

The set of JavaServer Faces factory classes for which the factory discovery mechanism is supported. The entries in this list must be alphabetically ordered according to the entire string of the *value* of each of the literals, not just the last part of the literal!

INJECTION_PROVIDER_KEYback to summary
private static final String INJECTION_PROVIDER_KEY
lockback to summary
private final ReentrantReadWriteLock lock
LOGGERback to summary
private static final Logger LOGGER
savedFactoryNamesback to summary
private final Map<String, List<String>> savedFactoryNames
servletContextFinderback to summary
private ServletContextFacesContextFactory servletContextFinder

Constructor Detail

FactoryFinderInstanceback to summary
pack-priv FactoryFinderInstance()
FactoryFinderInstanceback to summary
pack-priv FactoryFinderInstance(FactoryFinderInstance toCopy)

Method Detail

addFactoryback to summary
pack-priv void addFactory(String factoryName, String implementation)
clearInjectionProviderback to summary
pack-priv void clearInjectionProvider()
copyInjectionProviderFromFacesContextback to summary
private void copyInjectionProviderFromFacesContext()
getClassLoaderback to summary
private ClassLoader getClassLoader() throws FacesException
getFactoriesback to summary
pack-priv Collection<Object> getFactories()
getFactoryback to summary
pack-priv Object getFactory(String factoryName)
getFactoryClassback to summary
private Class<T> getFactoryClass(String factoryClassName)
Returns:Class<T>

the java.lang.Class for the argument factory.

getImplementationInstanceback to summary
private Object getImplementationInstance(ClassLoader classLoader, String factoryName, List<E> implementations) throws FacesException

Load and return an instance of the specified implementation class using the following algorithm.

  1. If the argument implementations list has more than one element, or exactly one element, interpret the last element in the list to be the fully qualified class name of a class implementing factoryName. Instantiate that class and save it for return. If the implementations list has only one element, skip this step.

  2. Look for a resource called /META-INF/services/<factoryName>. If found, interpret it as a properties file, and read out the first entry. Interpret the first entry as a fully qualify class name of a class that implements factoryName. If we have an instantiated factory from the previous step and the implementing class has a one arg constructor of the type for factoryName, instantiate it, passing the instantiated factory from the previous step. If there is no one arg constructor, just instantiate the zero arg constructor. Save the newly instantiated factory for return, replacing the instantiated factory from the previous step.

  3. Treat each remaining element in the implementations list as a fully qualified class name of a class implementing factoryName. If the currentKeyrent element has a one arg constructor of the type for factoryName, instantiate it, passing the instantiated factory from the previous or step iteration. If there is no one arg constructor, just instantiate the zero arg constructor, replacing the instantiated factory from the previous step or iteration.

  4. Return the saved factory

Parameters
classLoader:ClassLoader

Class loader for the web application that will be loading the implementation class

implementations:List<E>

A List of implementations for a given factory class.

Exceptions
FacesException:
  • if the specified implementation class cannot be loaded
  • if an instance of the specified implementation class cannot be instantiated
getImplGivenPreviousImplback to summary
private Object getImplGivenPreviousImpl(ClassLoader classLoader, String factoryName, String implName, Object previousImpl)

Implement the decorator pattern for the factory implementation.

If previousImpl is non-null and the class named by the argument implName has a one arg contstructor of type factoryName, instantiate it, passing previousImpl to the constructor.

Otherwise, we just instantiate and return implName.

Parameters
classLoader:ClassLoader

the ClassLoader from which to load the class

factoryName:String

the fully qualified class name of the factory.

implName:String

the fully qualified class name of a class that implements the factory.

previousImpl:Object

if non-null, the factory instance to be passed to the constructor of the new factory.

getImplNameFromServicesback to summary
private List<String> getImplNameFromServices(ClassLoader classLoader, String factoryName)

Perform the logic to get the implementation class for the second step of FactoryFinder#getImplementationInstance(ClassLoader, String, java.util.List).

getInjectionProviderback to summary
pack-priv InjectionProvider getInjectionProvider()
releaseFactoriesback to summary
pack-priv void releaseFactories()
validateFactoryNameback to summary
private void validateFactoryName(String factoryName)