SourceForge.net Logo

de.mindmatters.faces.spring.context
Class ContextLoader

java.lang.Object
  extended byde.mindmatters.faces.spring.context.ContextLoader

public class ContextLoader
extends java.lang.Object

Performs the actual initialization work for the faces root application context. Called by ContextLoaderListener and ContextLoaderServlet.

Looks for the context-param faces.spring.factoryClass to determine the internal bean factory class type, falling back to the default implementation of ManagedBeanFactory if not found. With the default ContextLoader implementation, any factory class specified needs to implement ManagedBeanFactory.

Looks for the context-param faces.spring.contextClass to determine the context class type, falling back to the default implementation of FacesWebApplicationContext if not found. With the default ContextLoader implementation, any context class specified needs to implement FacesWebApplicationContext.

Passes the context-param faces.spring.CONTEXT_FILES to the context instance, parsing it into potentially multiple file paths which can be separated by any number of commas and spaces, like "applicationContext1.xml, applicationContext2.xml". If not explicitly specified, the context implementation is supposed to use a default location ("/WEB-INF/faces-spring-context.xml").

Above and beyond loading the faces root application context, this class tries to obtain and hook up a shared parent context to the faces root application context. See the loadParentContext(ServletContext) method for more information.

Author:
Andreas Kuhrwahl
See Also:
ContextLoaderListener, ContextLoaderServlet, DefaultFacesWebApplicationContext

Field Summary
static java.lang.String CONFIG_LOCATION_PARAM
          Context initialization parameter name for a comma delimited list of context-relative resource paths (which is loaded automatically if it exists) containing faces-spring-context configuration information: faces.spring.CONTEXT_FILES.
static java.lang.String CONTEXT_CLASS_PARAM
          Config param for root faces application context implementation class FacesWebApplicationContext to use: faces.spring.contextClass.
static java.lang.String FACTORY_CLASS_PARAM
          Config param for internal bean factory implementation class of the root ManagedBeanFactory to use: faces.spring.factoryClass.
protected  org.apache.commons.logging.Log logger
          For logging.
 
Constructor Summary
ContextLoader()
           
 
Method Summary
 void closeFacesConfigWebApplicationContext(javax.servlet.ServletContext servletContext)
          Closes the faces web application context for the given servlet context.
protected  void closeParentApplicationContext(javax.servlet.ServletContext servletContext, ApplicationContext parent)
          Closes the parent web application context of faces web application context for the given servlet context.
protected  FacesWebApplicationContext createFacesConfigWebApplicationContext(javax.servlet.ServletContext servletContext, ApplicationContext parent)
          Creates and returns a FacesWebApplicationContext.
protected  java.lang.Class determineContextClass(javax.servlet.ServletContext servletContext, java.lang.String initParam, java.lang.Class strategyClass)
          Returns the WebApplicationContext implementation class to use, either the default FacesWebApplicationContext or a custom context class if specified.
 FacesWebApplicationContext initFacesConfigWebApplicationContext(javax.servlet.ServletContext servletContext)
          Initializes faces' web application context for the given servlet context, regarding the "faces.spring.contextClass", "faces.spring.factoryClass" and "faces.spring.CONTEXT_FILES" context-params.
protected  ApplicationContext loadParentContext(javax.servlet.ServletContext servletContext)
          Loads and returns a root parent application context for the FacesWebApplicationContext (usually an xml context based on the "spring-beans" DTD).
protected  java.lang.String[] resolveFacesConfigLocations(ResourceLoader resourceLoader, javax.servlet.ServletContext servletContext)
          Returns a list with Strings identifying the faces configuration file resources.
protected  java.lang.String[] resolveFacesSpringConfigLocations(ResourceLoader resourceLoader, javax.servlet.ServletContext servletContext)
          Returns a list with Strings identifying the faces-spring configuration file resources.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

protected final org.apache.commons.logging.Log logger
For logging.


CONTEXT_CLASS_PARAM

public static final java.lang.String CONTEXT_CLASS_PARAM
Config param for root faces application context implementation class FacesWebApplicationContext to use: faces.spring.contextClass.

See Also:
Constant Field Values

FACTORY_CLASS_PARAM

public static final java.lang.String FACTORY_CLASS_PARAM
Config param for internal bean factory implementation class of the root ManagedBeanFactory to use: faces.spring.factoryClass.

See Also:
Constant Field Values

CONFIG_LOCATION_PARAM

public static final java.lang.String CONFIG_LOCATION_PARAM
Context initialization parameter name for a comma delimited list of context-relative resource paths (which is loaded automatically if it exists) containing faces-spring-context configuration information: faces.spring.CONTEXT_FILES.

See Also:
Constant Field Values
Constructor Detail

ContextLoader

public ContextLoader()
Method Detail

initFacesConfigWebApplicationContext

public final FacesWebApplicationContext initFacesConfigWebApplicationContext(javax.servlet.ServletContext servletContext)
Initializes faces' web application context for the given servlet context, regarding the "faces.spring.contextClass", "faces.spring.factoryClass" and "faces.spring.CONTEXT_FILES" context-params.

Parameters:
servletContext - current servlet context
Returns:
the new FacesWebApplicationContext
Throws:
BeansException - if the context couldn't be initialized
See Also:
CONTEXT_CLASS_PARAM, FACTORY_CLASS_PARAM, CONFIG_LOCATION_PARAM

loadParentContext

protected ApplicationContext loadParentContext(javax.servlet.ServletContext servletContext)
Loads and returns a root parent application context for the FacesWebApplicationContext (usually an xml context based on the "spring-beans" DTD).

Parameters:
servletContext - the servlet context
Returns:
a parent ApplicationContext
Throws:
BeansException - in cases of errors
See Also:
ContextLoader

determineContextClass

protected final java.lang.Class determineContextClass(javax.servlet.ServletContext servletContext,
                                                      java.lang.String initParam,
                                                      java.lang.Class strategyClass)
Returns the WebApplicationContext implementation class to use, either the default FacesWebApplicationContext or a custom context class if specified.

Parameters:
servletContext - current servlet context
initParam - the ServletContext config param for a potentially defined custom context class
strategyClass - the key for the proper default strategy
Returns:
the WebApplicationContext implementation class to use
Throws:
ApplicationContextException - if the context class couldn't be loaded
See Also:
CONTEXT_CLASS_PARAM, XmlWebApplicationContext

createFacesConfigWebApplicationContext

protected FacesWebApplicationContext createFacesConfigWebApplicationContext(javax.servlet.ServletContext servletContext,
                                                                            ApplicationContext parent)
Creates and returns a FacesWebApplicationContext.

Parameters:
servletContext - the servlet context
parent - parent application context
Returns:
a new FacesWebApplicationContext
Throws:
BeansException - in cases of errors

resolveFacesConfigLocations

protected final java.lang.String[] resolveFacesConfigLocations(ResourceLoader resourceLoader,
                                                               javax.servlet.ServletContext servletContext)
Returns a list with Strings identifying the faces configuration file resources.

Parameters:
resourceLoader - the ResourceLoader to use for loading config locations
servletContext - the servlet context
Returns:
the resolved config locations
Throws:
BeansException - in cases of errors
See Also:
FacesServlet.CONFIG_FILES_ATTR

resolveFacesSpringConfigLocations

protected final java.lang.String[] resolveFacesSpringConfigLocations(ResourceLoader resourceLoader,
                                                                     javax.servlet.ServletContext servletContext)
Returns a list with Strings identifying the faces-spring configuration file resources.

Parameters:
resourceLoader - the ResourceLoader to use for loading config locations
servletContext - the servlet context
Returns:
the resolved config locations
Throws:
BeansException - in cases of errors
See Also:
CONFIG_LOCATION_PARAM

closeFacesConfigWebApplicationContext

public final void closeFacesConfigWebApplicationContext(javax.servlet.ServletContext servletContext)
Closes the faces web application context for the given servlet context.

Parameters:
servletContext - the servlet context

closeParentApplicationContext

protected void closeParentApplicationContext(javax.servlet.ServletContext servletContext,
                                             ApplicationContext parent)
Closes the parent web application context of faces web application context for the given servlet context. If overriding loadParentContext(ServletContext), you may have to override this method as well.

Parameters:
servletContext - the servlet context
parent - parent ApplicationContext

SourceForge.net Logo

Copyright © 2002 mindmatters GmbH & Co. KG