public abstract class PortletApplicationContextUtils
extends java.lang.Object
WebApplicationContext
for
a given PortletContext
. This is useful for programmatically accessing
a Spring application context from within custom Portlet implementations.ContextLoader
,
WebApplicationContextUtils
,
FrameworkPortlet
,
DispatcherPortlet
Modifier and Type | Class and Description |
---|---|
private static class |
PortletApplicationContextUtils.RequestObjectFactory
Factory that exposes the current request object on demand.
|
private static class |
PortletApplicationContextUtils.ResponseObjectFactory
Factory that exposes the current response 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 and Description |
---|
PortletApplicationContextUtils() |
Modifier and Type | Method and Description |
---|---|
private static PortletRequestAttributes |
currentRequestAttributes()
Return the current RequestAttributes instance as PortletRequestAttributes.
|
static ApplicationContext |
getRequiredWebApplicationContext(PortletContext pc)
Find the root
WebApplicationContext for this web app, typically
loaded via ContextLoaderListener . |
static ApplicationContext |
getWebApplicationContext(PortletContext pc)
Find the root
WebApplicationContext for this web app, typically
loaded via ContextLoaderListener . |
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 servletContext ,
portletContext and portletConfig objects. |
(package private) static void |
registerEnvironmentBeans(ConfigurableListableBeanFactory bf,
ServletContext servletContext,
PortletContext portletContext,
PortletConfig portletConfig)
Register web-specific environment beans ("contextParameters", "contextAttributes")
with the given BeanFactory, as used by the Portlet ApplicationContext.
|
(package private) static void |
registerPortletApplicationScopes(ConfigurableListableBeanFactory bf,
PortletContext pc)
Register web-specific scopes ("request", "session", "globalSession")
with the given BeanFactory, as used by the Portlet ApplicationContext.
|
public static ApplicationContext getWebApplicationContext(PortletContext pc)
WebApplicationContext
for this web app, typically
loaded via ContextLoaderListener
.
Will rethrow an exception that happened on root context startup, to differentiate between a failed context startup and no context at all.
pc
- PortletContext to find the web application context fornull
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)WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE
public static ApplicationContext getRequiredWebApplicationContext(PortletContext pc) throws java.lang.IllegalStateException
WebApplicationContext
for this web app, typically
loaded via ContextLoaderListener
.
Will rethrow an exception that happened on root context startup, to differentiate between a failed context startup and no context at all.
pc
- PortletContext to find the web application context forjava.lang.IllegalStateException
- if the root WebApplicationContext could not be foundWebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE
static void registerPortletApplicationScopes(ConfigurableListableBeanFactory bf, PortletContext pc)
bf
- the BeanFactory to configurepc
- the PortletContext that we're running withinstatic void registerEnvironmentBeans(ConfigurableListableBeanFactory bf, ServletContext servletContext, PortletContext portletContext, PortletConfig portletConfig)
bf
- the BeanFactory to configureservletContext
- the ServletContext that we're running withinportletContext
- the PortletContext that we're running withinportletConfig
- the PortletConfig of the containing Portletpublic static void initPortletPropertySources(MutablePropertySources propertySources, ServletContext servletContext, PortletContext portletContext, PortletConfig portletConfig)
Servlet
- and Portlet
-based stub property
sources
with actual instances populated with the given servletContext
,
portletContext
and portletConfig
objects.
This method is idempotent with respect to the fact it may be called any number of times but will perform replacement of stub property sources with their corresponding actual property sources once and only once.
propertySources
- the MutablePropertySources
to initialize (must not be null
)servletContext
- the current ServletContext
(ignored if null
or if the servlet context property source
has already been initialized)portletContext
- the current PortletContext
(ignored if null
or if the portlet context property source
has already been initialized)portletConfig
- the current PortletConfig
(ignored if null
or if the portlet config property source
has already been initialized)PropertySource.StubPropertySource
,
WebApplicationContextUtils.initServletPropertySources(MutablePropertySources, ServletContext)
,
ConfigurableEnvironment.getPropertySources()
private static PortletRequestAttributes currentRequestAttributes()