org.springframework.web.portlet.context
Class PortletApplicationContextUtils

java.lang.Object
  extended by org.springframework.web.portlet.context.PortletApplicationContextUtils

public abstract class PortletApplicationContextUtils
extends java.lang.Object

Convenience methods for retrieving the root WebApplicationContext for a given PortletContext. This is e.g. useful for accessing a Spring context from within custom Portlet implementations.

Since:
2.0
Author:
Juergen Hoeller, John A. Lewis
See Also:
ContextLoader, WebApplicationContextUtils, FrameworkPortlet, DispatcherPortlet

Nested Class Summary
private static class PortletApplicationContextUtils.RequestObjectFactory
          Factory that exposes the current request object on demand.
private static class PortletApplicationContextUtils.SessionObjectFactory
          Factory that exposes the current session object on demand.
private static class PortletApplicationContextUtils.WebRequestObjectFactory
          Factory that exposes the current WebRequest object on demand.
 
Constructor Summary
PortletApplicationContextUtils()
           
 
Method Summary
private static PortletRequestAttributes currentRequestAttributes()
          Return the current RequestAttributes instance as PortletRequestAttributes.
static ApplicationContext getRequiredWebApplicationContext(PortletContext pc)
          Find the root WebApplicationContext for this portlet application, which is typically loaded via ContextLoaderListener or ContextLoaderServlet.
static ApplicationContext getWebApplicationContext(PortletContext pc)
          Find the root WebApplicationContext for this portlet application, which is typically loaded via ContextLoaderListener or ContextLoaderServlet.
static void initPortletPropertySources(MutablePropertySources propertySources, ServletContext servletContext, PortletContext portletContext, PortletConfig portletConfig)
          Replace Servlet- and Portlet-based stub property sources with actual instances populated with the given context and config objects.
(package private) static void registerEnvironmentBeans(ConfigurableListableBeanFactory bf, ServletContext sc, PortletContext pc, PortletConfig config)
          Register web-specific environment beans ("contextParameters", "contextAttributes") with the given BeanFactory, as used by the Portlet ApplicationContext.
(package private) static void registerPortletApplicationScopes(ConfigurableListableBeanFactory beanFactory, PortletContext pc)
          Register web-specific scopes ("request", "session", "globalSession") with the given BeanFactory, as used by the Portlet ApplicationContext.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PortletApplicationContextUtils

public PortletApplicationContextUtils()
Method Detail

getWebApplicationContext

public static ApplicationContext getWebApplicationContext(PortletContext pc)
Find the root WebApplicationContext for this portlet application, which is typically loaded via ContextLoaderListener or ContextLoaderServlet.

Will rethrow an exception that happened on root context startup, to differentiate between a failed context startup and no context at all.

Parameters:
pc - PortletContext to find the web application context for
Returns:
the root WebApplicationContext for this web app, or null if none (typed to ApplicationContext to avoid a Servlet API dependency; can usually be casted to WebApplicationContext, but there shouldn't be a need to)
See Also:
WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE

getRequiredWebApplicationContext

public static ApplicationContext getRequiredWebApplicationContext(PortletContext pc)
                                                           throws java.lang.IllegalStateException
Find the root WebApplicationContext for this portlet application, which is typically loaded via ContextLoaderListener or ContextLoaderServlet.

Will rethrow an exception that happened on root context startup, to differentiate between a failed context startup and no context at all.

Parameters:
pc - PortletContext to find the web application context for
Returns:
the root WebApplicationContext for this web app (typed to ApplicationContext to avoid a Servlet API dependency; can usually be casted to WebApplicationContext, but there shouldn't be a need to)
Throws:
java.lang.IllegalStateException - if the root WebApplicationContext could not be found
See Also:
WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE

registerPortletApplicationScopes

static void registerPortletApplicationScopes(ConfigurableListableBeanFactory beanFactory,
                                             PortletContext pc)
Register web-specific scopes ("request", "session", "globalSession") with the given BeanFactory, as used by the Portlet ApplicationContext.

Parameters:
beanFactory - the BeanFactory to configure
pc - the PortletContext that we're running within

registerEnvironmentBeans

static void registerEnvironmentBeans(ConfigurableListableBeanFactory bf,
                                     ServletContext sc,
                                     PortletContext pc,
                                     PortletConfig config)
Register web-specific environment beans ("contextParameters", "contextAttributes") with the given BeanFactory, as used by the Portlet ApplicationContext.

Parameters:
bf - the BeanFactory to configure
sc - the ServletContext that we're running within
pc - the PortletContext that we're running within
config - the PortletConfig of the containing Portlet

initPortletPropertySources

public static void initPortletPropertySources(MutablePropertySources propertySources,
                                              ServletContext servletContext,
                                              PortletContext portletContext,
                                              PortletConfig portletConfig)
Replace Servlet- and Portlet-based stub property sources with actual instances populated with the given context and config objects.

See Also:
PropertySource.StubPropertySource, ConfigurableEnvironment.getPropertySources(), WebApplicationContextUtils.initServletPropertySources(MutablePropertySources, ServletContext)

currentRequestAttributes

private static PortletRequestAttributes currentRequestAttributes()
Return the current RequestAttributes instance as PortletRequestAttributes.

See Also:
RequestContextHolder.currentRequestAttributes()