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