org.jasig.springframework.web.portlet.context
Class PortletContextLoader

java.lang.Object
  extended by org.jasig.springframework.web.portlet.context.PortletContextLoader

public class PortletContextLoader
extends Object

Performs the actual initialization work for the root application context. Called by PortletContextLoaderListener.

Looks for a "portletContextClass" context-param at the web.xml level to specify the context class type, falling back to the default of ContribXmlPortletApplicationContext if not found. With the default PortletContextLoader implementation, any context class specified needs to implement the ConfigurablePortletApplicationContext interface.

Processes a "portletContextConfigLocation" context-param at the web.xml level and passes its value to the context instance, parsing it into potentially multiple file paths which can be separated by any number of commas and spaces, e.g. "WEB-INF/portletApplicationContext1.xml, WEB-INF/portletApplicationContext2.xml". Ant-style path patterns are supported as well, e.g. "WEB-INF/portlet*Context.xml,WEB-INF/springPortlet*.xml" or "WEB-INF/**/portlet*Context.xml". If not explicitly specified, the context implementation is supposed to use a default location (with ContribXmlPortletApplicationContext: "/WEB-INF/portletApplicationContext.xml").

Note: In case of multiple config locations, later bean definitions will override ones defined in previously loaded files, at least when using one of Spring's default ApplicationContext implementations. This can be leveraged to deliberately override certain bean definitions via an extra XML file.

Above and beyond loading the root portlet application context, this class can optionally load or obtain and hook up a shared parent context to the root application context. See the loadParentContext(PortletContext) method for more information.

Author:
Juergen Hoeller, Colin Sampaleanu, Sam Brannen, Eric Dalquist
See Also:
PortletContextLoaderListener, PortletApplicationContext, XmlPortletApplicationContext

Field Summary
static String CONFIG_LOCATION_PARAM
          Name of portlet context parameter (i.e., "portletContextConfigLocation") that can specify the config location for the root context, falling back to the implementation's default otherwise.
static String CONTEXT_CLASS_PARAM
          Config param for the root PortletApplicationContext implementation class to use: "portletContextClass"
static String CONTEXT_ID_PARAM
          Config param for the root PortletApplicationContext id, to be used as serialization id for the underlying BeanFactory: "portletContextId"
static String CONTEXT_INITIALIZER_CLASSES_PARAM
          Config param for which ApplicationContextInitializer classes to use for initializing the web application context: "portletContextInitializerClasses"
 
Constructor Summary
PortletContextLoader(javax.servlet.ServletContext servletContext)
           
 
Method Summary
 void closeWebApplicationContext(javax.servlet.ServletContext servletContext)
          Close Spring's web application context for the given portlet context.
protected  void configureAndRefreshPortletApplicationContext(org.springframework.web.portlet.context.ConfigurablePortletApplicationContext pac, javax.portlet.PortletContext pc)
           
protected  PortletApplicationContext createPortletApplicationContext(javax.portlet.PortletContext sc)
          Instantiate the root PortletApplicationContext for this loader, either the default context class or a custom context class if specified.
protected  void customizeContext(javax.portlet.PortletContext portletContext, org.springframework.web.portlet.context.ConfigurablePortletApplicationContext applicationContext)
          Customize the ConfigurablePortletApplicationContext created by this PortletContextLoader after config locations have been supplied to the context but before the context is refreshed.
protected  Class<?> determineContextClass(javax.portlet.PortletContext portletContext)
          Return the PortletApplicationContext implementation class to use, either the default XmlPortletApplicationContext or a custom context class if specified.
protected  List<Class<org.springframework.context.ApplicationContextInitializer<org.springframework.context.ConfigurableApplicationContext>>> determineContextInitializerClasses(javax.portlet.PortletContext portletContext)
          Return the ApplicationContextInitializer implementation classes to use if any have been specified by CONTEXT_INITIALIZER_CLASSES_PARAM.
static PortletApplicationContext getCurrentPortletApplicationContext()
          Obtain the Spring root portlet application context for the current thread (i.e.
 PortletApplicationContext initWebApplicationContext(javax.portlet.PortletContext portletContext)
          Initialize Spring's portlet application context for the given portlet context, using the application context provided at construction time, or creating a new one according to the "contextClass" and "contextConfigLocation" context-params.
protected  org.springframework.context.ApplicationContext loadParentContext(javax.portlet.PortletContext portletContext)
          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 PortletApplicationContext.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CONTEXT_CLASS_PARAM

public static final String CONTEXT_CLASS_PARAM
Config param for the root PortletApplicationContext implementation class to use: "portletContextClass"

See Also:
determineContextClass(PortletContext), #createWebApplicationContext(PortletContext, ApplicationContext), Constant Field Values

CONTEXT_ID_PARAM

public static final String CONTEXT_ID_PARAM
Config param for the root PortletApplicationContext id, to be used as serialization id for the underlying BeanFactory: "portletContextId"

See Also:
Constant Field Values

CONTEXT_INITIALIZER_CLASSES_PARAM

public static final String CONTEXT_INITIALIZER_CLASSES_PARAM
Config param for which ApplicationContextInitializer classes to use for initializing the web application context: "portletContextInitializerClasses"

See Also:
customizeContext(PortletContext, ConfigurablePortletApplicationContext), Constant Field Values

CONFIG_LOCATION_PARAM

public static final String CONFIG_LOCATION_PARAM
Name of portlet context parameter (i.e., "portletContextConfigLocation") that can specify the config location for the root context, falling back to the implementation's default otherwise.

See Also:
XmlPortletApplicationContext.DEFAULT_CONFIG_LOCATION, Constant Field Values
Constructor Detail

PortletContextLoader

public PortletContextLoader(javax.servlet.ServletContext servletContext)
Method Detail

initWebApplicationContext

public PortletApplicationContext initWebApplicationContext(javax.portlet.PortletContext portletContext)
Initialize Spring's portlet application context for the given portlet context, using the application context provided at construction time, or creating a new one according to the "contextClass" and "contextConfigLocation" context-params.

Parameters:
portletContext - current portlet context
Returns:
the new PortletApplicationContext
See Also:
CONTEXT_CLASS_PARAM, CONFIG_LOCATION_PARAM

createPortletApplicationContext

protected PortletApplicationContext createPortletApplicationContext(javax.portlet.PortletContext sc)
Instantiate the root PortletApplicationContext for this loader, either the default context class or a custom context class if specified.

This implementation expects custom contexts to implement the ConfigurablePortletApplicationContext interface. Can be overridden in subclasses.

In addition, customizeContext(javax.portlet.PortletContext, org.springframework.web.portlet.context.ConfigurablePortletApplicationContext) gets called prior to refreshing the context, allowing subclasses to perform custom modifications to the context.

Parameters:
sc - current portlet context
Returns:
the root WebApplicationContext
See Also:
ConfigurablePortletApplicationContext

configureAndRefreshPortletApplicationContext

protected void configureAndRefreshPortletApplicationContext(org.springframework.web.portlet.context.ConfigurablePortletApplicationContext pac,
                                                            javax.portlet.PortletContext pc)

determineContextClass

protected Class<?> determineContextClass(javax.portlet.PortletContext portletContext)
Return the PortletApplicationContext implementation class to use, either the default XmlPortletApplicationContext or a custom context class if specified.

Parameters:
portletContext - current portlet context
Returns:
the WebApplicationContext implementation class to use
See Also:
CONTEXT_CLASS_PARAM, XmlPortletApplicationContext

determineContextInitializerClasses

protected List<Class<org.springframework.context.ApplicationContextInitializer<org.springframework.context.ConfigurableApplicationContext>>> determineContextInitializerClasses(javax.portlet.PortletContext portletContext)
Return the ApplicationContextInitializer implementation classes to use if any have been specified by CONTEXT_INITIALIZER_CLASSES_PARAM.

Parameters:
portletContext - current portlet context
See Also:
CONTEXT_INITIALIZER_CLASSES_PARAM

customizeContext

protected void customizeContext(javax.portlet.PortletContext portletContext,
                                org.springframework.web.portlet.context.ConfigurablePortletApplicationContext applicationContext)
Customize the ConfigurablePortletApplicationContext created by this PortletContextLoader after config locations have been supplied to the context but before the context is refreshed.

The default implementation determines what (if any) context initializer classes have been specified through context init parameters and invokes each with the given web application context.

Any ApplicationContextInitializers implementing Ordered or marked with @Order will be sorted appropriately.

Parameters:
portletContext - the current portlet context
applicationContext - the newly created application context
See Also:
createPortletApplicationContext(PortletContext), CONTEXT_INITIALIZER_CLASSES_PARAM, ApplicationContextInitializer.initialize(ConfigurableApplicationContext)

loadParentContext

protected org.springframework.context.ApplicationContext loadParentContext(javax.portlet.PortletContext portletContext)
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 PortletApplicationContext. If the return value from the method is null, no parent context is set.

The default implementation uses PortletApplicationContextUtils.getWebApplicationContext(PortletContext) to load a parent context.

Parameters:
portletContext - current portlet context
Returns:
the parent application context, or null if none

closeWebApplicationContext

public void closeWebApplicationContext(javax.servlet.ServletContext servletContext)
Close Spring's web application context for the given portlet context. If the default loadParentContext(PortletContext) implementation, which uses ContextSingletonBeanFactoryLocator, has loaded any shared parent context, release one reference to that shared parent context.

If overriding loadParentContext(PortletContext), you may have to override this method as well.

Parameters:
servletContext - the PortletContext that the WebApplicationContext runs in

getCurrentPortletApplicationContext

public static PortletApplicationContext getCurrentPortletApplicationContext()
Obtain the Spring root portlet application context for the current thread (i.e. for the current thread's context ClassLoader, which needs to be the web application's ClassLoader).

Returns:
the current root web application context, or null if none found
See Also:
org.springframework.web.context.support.SpringBeanAutowiringSupport


Copyright © 2013 Jasig. All Rights Reserved.