JSF-Spring

de.mindmatters.faces.spring.context
Class ContextLoader

java.lang.Object
  extended by de.mindmatters.faces.spring.context.ContextLoader

public class ContextLoader
extends java.lang.Object

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

For further informtion please have a look at the documentation of ContextLoader.

Author:
Andreas Kuhrwahl

Field Summary
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 CONTEXT_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 LOCATOR_FACTORY_KEY_PARAM
          Optional servlet context parameter used only when obtaining a parent context using the default implementation of loadParentContext(ServletContext servletContext).
static java.lang.String LOCATOR_FACTORY_SELECTOR_PARAM
          Optional servlet context parameter used only when obtaining a parent context using the default implementation of loadParentContext(ServletContext servletContext).
protected  org.apache.commons.logging.Log logger
          For logging.
 
Constructor Summary
ContextLoader()
           
 
Method Summary
protected  void closeParentApplicationContext(javax.servlet.ServletContext servletContext, ApplicationContext parent)
          Closes the parent web application context of jsf-spring web application context for the given servlet context.
 void closeWebApplicationContext(javax.servlet.ServletContext servletContext)
          Closes the web application context for the given servlet context.
protected  WebApplicationContext createWebApplicationContext(javax.servlet.ServletContext servletContext, ApplicationContext parent)
          Creates and returns a WebApplicationContext.
protected  java.lang.Class determineContextClass(javax.servlet.ServletContext servletContext)
          Returns the WebApplicationContext implementation class to use, either the default FacesWebApplicationContext or a custom context class if specified.
 WebApplicationContext initWebApplicationContext(javax.servlet.ServletContext servletContext)
          Initialize web application context for the given servlet context, regarding the faces.spring.configClass and faces.spring.CONFIG_FILES context-params.
protected  ApplicationContext loadParentContext(javax.servlet.ServletContext servletContext)
          Template method with default implementation (which may be overridden by a subclass), to load or obtain an ApplicationContext instance which will be used as the parent context of the root WebApplicationContext.
 
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

CONTEXT_LOCATION_PARAM

public static final java.lang.String CONTEXT_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

LOCATOR_FACTORY_SELECTOR_PARAM

public static final java.lang.String LOCATOR_FACTORY_SELECTOR_PARAM
Optional servlet context parameter used only when obtaining a parent context using the default implementation of loadParentContext(ServletContext servletContext). Specifies the 'selector' used in the ContextSingletonBeanFactoryLocator.getInstance(String selector) method call used to obtain the BeanFactoryLocator instance from which the parent context is obtained.

This will normally be set to classpath*:beanRefContext.xml to match the default applied for the ContextSingletonBeanFactoryLocator.getInstance() method.

See Also:
Constant Field Values

LOCATOR_FACTORY_KEY_PARAM

public static final java.lang.String LOCATOR_FACTORY_KEY_PARAM
Optional servlet context parameter used only when obtaining a parent context using the default implementation of loadParentContext(ServletContext servletContext). Specifies the 'factoryKey' used in the #useBeanFactory(String factoryKey) method call used to obtain the parent application context from the BeanFactoryLocator instance.

See Also:
Constant Field Values
Constructor Detail

ContextLoader

public ContextLoader()
Method Detail

initWebApplicationContext

public final WebApplicationContext initWebApplicationContext(javax.servlet.ServletContext servletContext)
Initialize web application context for the given servlet context, regarding the faces.spring.configClass and faces.spring.CONFIG_FILES context-params.

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

loadParentContext

protected ApplicationContext loadParentContext(javax.servlet.ServletContext servletContext)
Template method with default implementation (which may be overridden by a subclass), to load or obtain an ApplicationContext instance which will be used as the parent context of the root WebApplicationContext. If the return value from the method is null, no parent context is set.

The default implementation uses ContextSingletonBeanFactoryLocator, configured via LOCATOR_FACTORY_SELECTOR_PARAM and LOCATOR_FACTORY_KEY_PARAM, to load a parent context which will be shared by all other users of ContextsingletonBeanFactoryLocator which also use the same configuration parameters, or if LOCATOR_FACTORY_KEY_PARAM is not set a parent context obtained by WebApplicationContextUtils.getWebApplicationContext(javax.servlet.ServletContext).

Parameters:
servletContext - current servlet context
Returns:
the parent application context, or null if none
Throws:
BeansException - if the context couldn't be initialized
See Also:
BeanFactoryLocator, ContextSingletonBeanFactoryLocator

createWebApplicationContext

protected WebApplicationContext createWebApplicationContext(javax.servlet.ServletContext servletContext,
                                                            ApplicationContext parent)
Creates and returns a WebApplicationContext.

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

determineContextClass

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

Parameters:
servletContext - current servlet context
Returns:
the WebApplicationContext implementation class to use
Throws:
ApplicationContextException - if the context class couldn't be loaded
See Also:
CONTEXT_CLASS_PARAM, XmlWebApplicationContext

closeWebApplicationContext

public final void closeWebApplicationContext(javax.servlet.ServletContext servletContext)
Closes the 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 jsf-spring 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

JSF-Spring

Copyright © 2006 mindmatters GmbH & Co. KG