1
1
/*
2
- * Copyright 2002-2013 the original author or authors.
2
+ * Copyright 2002-2014 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
56
56
public abstract class PortletApplicationContextUtils {
57
57
58
58
/**
59
- * Find the root WebApplicationContext for this portlet application, which is
60
- * typically loaded via ContextLoaderListener or ContextLoaderServlet .
59
+ * Find the root {@link WebApplicationContext} for this web app, typically
60
+ * loaded via {@link org.springframework.web.context.ContextLoaderListener} .
61
61
* <p>Will rethrow an exception that happened on root context startup,
62
62
* to differentiate between a failed context startup and no context at all.
63
63
* @param pc PortletContext to find the web application context for
@@ -85,8 +85,8 @@ public static ApplicationContext getWebApplicationContext(PortletContext pc) {
85
85
}
86
86
87
87
/**
88
- * Find the root WebApplicationContext for this portlet application, which is
89
- * typically loaded via ContextLoaderListener or ContextLoaderServlet .
88
+ * Find the root {@link WebApplicationContext} for this web app, typically
89
+ * loaded via {@link org.springframework.web.context.ContextLoaderListener} .
90
90
* <p>Will rethrow an exception that happened on root context startup,
91
91
* to differentiate between a failed context startup and no context at all.
92
92
* @param pc PortletContext to find the web application context for
@@ -96,9 +96,7 @@ public static ApplicationContext getWebApplicationContext(PortletContext pc) {
96
96
* @throws IllegalStateException if the root WebApplicationContext could not be found
97
97
* @see org.springframework.web.context.WebApplicationContext#ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE
98
98
*/
99
- public static ApplicationContext getRequiredWebApplicationContext (PortletContext pc )
100
- throws IllegalStateException {
101
-
99
+ public static ApplicationContext getRequiredWebApplicationContext (PortletContext pc ) throws IllegalStateException {
102
100
ApplicationContext wac = getWebApplicationContext (pc );
103
101
if (wac == null ) {
104
102
throw new IllegalStateException ("No WebApplicationContext found: no ContextLoaderListener registered?" );
@@ -110,62 +108,62 @@ public static ApplicationContext getRequiredWebApplicationContext(PortletContext
110
108
/**
111
109
* Register web-specific scopes ("request", "session", "globalSession")
112
110
* with the given BeanFactory, as used by the Portlet ApplicationContext.
113
- * @param beanFactory the BeanFactory to configure
111
+ * @param bf the BeanFactory to configure
114
112
* @param pc the PortletContext that we're running within
115
113
*/
116
- static void registerPortletApplicationScopes (ConfigurableListableBeanFactory beanFactory , PortletContext pc ) {
117
- beanFactory .registerScope (WebApplicationContext .SCOPE_REQUEST , new RequestScope ());
118
- beanFactory .registerScope (WebApplicationContext .SCOPE_SESSION , new SessionScope (false ));
119
- beanFactory .registerScope (WebApplicationContext .SCOPE_GLOBAL_SESSION , new SessionScope (true ));
114
+ static void registerPortletApplicationScopes (ConfigurableListableBeanFactory bf , PortletContext pc ) {
115
+ bf .registerScope (WebApplicationContext .SCOPE_REQUEST , new RequestScope ());
116
+ bf .registerScope (WebApplicationContext .SCOPE_SESSION , new SessionScope (false ));
117
+ bf .registerScope (WebApplicationContext .SCOPE_GLOBAL_SESSION , new SessionScope (true ));
120
118
if (pc != null ) {
121
119
PortletContextScope appScope = new PortletContextScope (pc );
122
- beanFactory .registerScope (WebApplicationContext .SCOPE_APPLICATION , appScope );
120
+ bf .registerScope (WebApplicationContext .SCOPE_APPLICATION , appScope );
123
121
// Register as PortletContext attribute, for ContextCleanupListener to detect it.
124
122
pc .setAttribute (PortletContextScope .class .getName (), appScope );
125
123
}
126
124
127
- beanFactory .registerResolvableDependency (PortletRequest .class , new RequestObjectFactory ());
128
- beanFactory .registerResolvableDependency (PortletSession .class , new SessionObjectFactory ());
129
- beanFactory .registerResolvableDependency (WebRequest .class , new WebRequestObjectFactory ());
125
+ bf .registerResolvableDependency (PortletRequest .class , new RequestObjectFactory ());
126
+ bf .registerResolvableDependency (PortletSession .class , new SessionObjectFactory ());
127
+ bf .registerResolvableDependency (WebRequest .class , new WebRequestObjectFactory ());
130
128
}
131
129
132
130
/**
133
131
* Register web-specific environment beans ("contextParameters", "contextAttributes")
134
132
* with the given BeanFactory, as used by the Portlet ApplicationContext.
135
133
* @param bf the BeanFactory to configure
136
- * @param sc the ServletContext that we're running within
137
- * @param pc the PortletContext that we're running within
138
- * @param config the PortletConfig of the containing Portlet
134
+ * @param servletContext the ServletContext that we're running within
135
+ * @param portletContext the PortletContext that we're running within
136
+ * @param portletConfig the PortletConfig of the containing Portlet
139
137
*/
140
- static void registerEnvironmentBeans (
141
- ConfigurableListableBeanFactory bf , ServletContext sc , PortletContext pc , PortletConfig config ) {
138
+ static void registerEnvironmentBeans (ConfigurableListableBeanFactory bf , ServletContext servletContext ,
139
+ PortletContext portletContext , PortletConfig portletConfig ) {
142
140
143
- if (sc != null && !bf .containsBean (WebApplicationContext .SERVLET_CONTEXT_BEAN_NAME )) {
144
- bf .registerSingleton (WebApplicationContext .SERVLET_CONTEXT_BEAN_NAME , sc );
141
+ if (servletContext != null && !bf .containsBean (WebApplicationContext .SERVLET_CONTEXT_BEAN_NAME )) {
142
+ bf .registerSingleton (WebApplicationContext .SERVLET_CONTEXT_BEAN_NAME , servletContext );
145
143
}
146
144
147
- if (pc != null && !bf .containsBean (ConfigurablePortletApplicationContext .PORTLET_CONTEXT_BEAN_NAME )) {
148
- bf .registerSingleton (ConfigurablePortletApplicationContext .PORTLET_CONTEXT_BEAN_NAME , pc );
145
+ if (portletContext != null && !bf .containsBean (ConfigurablePortletApplicationContext .PORTLET_CONTEXT_BEAN_NAME )) {
146
+ bf .registerSingleton (ConfigurablePortletApplicationContext .PORTLET_CONTEXT_BEAN_NAME , portletContext );
149
147
}
150
148
151
- if (config != null && !bf .containsBean (ConfigurablePortletApplicationContext .PORTLET_CONFIG_BEAN_NAME )) {
152
- bf .registerSingleton (ConfigurablePortletApplicationContext .PORTLET_CONFIG_BEAN_NAME , config );
149
+ if (portletConfig != null && !bf .containsBean (ConfigurablePortletApplicationContext .PORTLET_CONFIG_BEAN_NAME )) {
150
+ bf .registerSingleton (ConfigurablePortletApplicationContext .PORTLET_CONFIG_BEAN_NAME , portletConfig );
153
151
}
154
152
155
153
if (!bf .containsBean (WebApplicationContext .CONTEXT_PARAMETERS_BEAN_NAME )) {
156
154
Map <String , String > parameterMap = new HashMap <String , String >();
157
- if (pc != null ) {
158
- Enumeration <String > paramNameEnum = pc .getInitParameterNames ();
155
+ if (portletContext != null ) {
156
+ Enumeration <String > paramNameEnum = portletContext .getInitParameterNames ();
159
157
while (paramNameEnum .hasMoreElements ()) {
160
158
String paramName = paramNameEnum .nextElement ();
161
- parameterMap .put (paramName , pc .getInitParameter (paramName ));
159
+ parameterMap .put (paramName , portletContext .getInitParameter (paramName ));
162
160
}
163
161
}
164
- if (config != null ) {
165
- Enumeration <String > paramNameEnum = config .getInitParameterNames ();
162
+ if (portletConfig != null ) {
163
+ Enumeration <String > paramNameEnum = portletConfig .getInitParameterNames ();
166
164
while (paramNameEnum .hasMoreElements ()) {
167
165
String paramName = paramNameEnum .nextElement ();
168
- parameterMap .put (paramName , config .getInitParameter (paramName ));
166
+ parameterMap .put (paramName , portletConfig .getInitParameter (paramName ));
169
167
}
170
168
}
171
169
bf .registerSingleton (WebApplicationContext .CONTEXT_PARAMETERS_BEAN_NAME ,
@@ -174,11 +172,11 @@ static void registerEnvironmentBeans(
174
172
175
173
if (!bf .containsBean (WebApplicationContext .CONTEXT_ATTRIBUTES_BEAN_NAME )) {
176
174
Map <String , Object > attributeMap = new HashMap <String , Object >();
177
- if (pc != null ) {
178
- Enumeration <String > attrNameEnum = pc .getAttributeNames ();
175
+ if (portletContext != null ) {
176
+ Enumeration <String > attrNameEnum = portletContext .getAttributeNames ();
179
177
while (attrNameEnum .hasMoreElements ()) {
180
178
String attrName = attrNameEnum .nextElement ();
181
- attributeMap .put (attrName , pc .getAttribute (attrName ));
179
+ attributeMap .put (attrName , portletContext .getAttribute (attrName ));
182
180
}
183
181
}
184
182
bf .registerSingleton (WebApplicationContext .CONTEXT_ATTRIBUTES_BEAN_NAME ,
0 commit comments