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.
@@ -67,18 +67,16 @@ public abstract class WebApplicationContextUtils {
67
67
68
68
69
69
/**
70
- * Find the root WebApplicationContext for this web application, which is
71
- * typically loaded via {@link org.springframework.web.context.ContextLoaderListener}.
70
+ * Find the root {@link WebApplicationContext} for this web app, typically
71
+ * loaded via {@link org.springframework.web.context.ContextLoaderListener}.
72
72
* <p>Will rethrow an exception that happened on root context startup,
73
73
* to differentiate between a failed context startup and no context at all.
74
74
* @param sc ServletContext to find the web application context for
75
75
* @return the root WebApplicationContext for this web app
76
76
* @throws IllegalStateException if the root WebApplicationContext could not be found
77
77
* @see org.springframework.web.context.WebApplicationContext#ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE
78
78
*/
79
- public static WebApplicationContext getRequiredWebApplicationContext (ServletContext sc )
80
- throws IllegalStateException {
81
-
79
+ public static WebApplicationContext getRequiredWebApplicationContext (ServletContext sc ) throws IllegalStateException {
82
80
WebApplicationContext wac = getWebApplicationContext (sc );
83
81
if (wac == null ) {
84
82
throw new IllegalStateException ("No WebApplicationContext found: no ContextLoaderListener registered?" );
@@ -87,8 +85,8 @@ public static WebApplicationContext getRequiredWebApplicationContext(ServletCont
87
85
}
88
86
89
87
/**
90
- * Find the root WebApplicationContext for this web application, which is
91
- * typically loaded via {@link org.springframework.web.context.ContextLoaderListener}.
88
+ * Find the root {@link WebApplicationContext} for this web app, typically
89
+ * loaded via {@link org.springframework.web.context.ContextLoaderListener}.
92
90
* <p>Will rethrow an exception that happened on root context startup,
93
91
* to differentiate between a failed context startup and no context at all.
94
92
* @param sc ServletContext to find the web application context for
@@ -100,7 +98,7 @@ public static WebApplicationContext getWebApplicationContext(ServletContext sc)
100
98
}
101
99
102
100
/**
103
- * Find a custom WebApplicationContext for this web application .
101
+ * Find a custom {@link WebApplicationContext} for this web app .
104
102
* @param sc ServletContext to find the web application context for
105
103
* @param attrName the name of the ServletContext attribute to look for
106
104
* @return the desired WebApplicationContext for this web app, or {@code null} if none
@@ -175,34 +173,34 @@ public static void registerEnvironmentBeans(ConfigurableListableBeanFactory bf,
175
173
* Register web-specific environment beans ("contextParameters", "contextAttributes")
176
174
* with the given BeanFactory, as used by the WebApplicationContext.
177
175
* @param bf the BeanFactory to configure
178
- * @param sc the ServletContext that we're running within
179
- * @param config the ServletConfig of the containing Portlet
176
+ * @param servletContext the ServletContext that we're running within
177
+ * @param servletConfig the ServletConfig of the containing Portlet
180
178
*/
181
179
public static void registerEnvironmentBeans (
182
- ConfigurableListableBeanFactory bf , ServletContext sc , ServletConfig config ) {
180
+ ConfigurableListableBeanFactory bf , ServletContext servletContext , ServletConfig servletConfig ) {
183
181
184
- if (sc != null && !bf .containsBean (WebApplicationContext .SERVLET_CONTEXT_BEAN_NAME )) {
185
- bf .registerSingleton (WebApplicationContext .SERVLET_CONTEXT_BEAN_NAME , sc );
182
+ if (servletContext != null && !bf .containsBean (WebApplicationContext .SERVLET_CONTEXT_BEAN_NAME )) {
183
+ bf .registerSingleton (WebApplicationContext .SERVLET_CONTEXT_BEAN_NAME , servletContext );
186
184
}
187
185
188
- if (config != null && !bf .containsBean (ConfigurableWebApplicationContext .SERVLET_CONFIG_BEAN_NAME )) {
189
- bf .registerSingleton (ConfigurableWebApplicationContext .SERVLET_CONFIG_BEAN_NAME , config );
186
+ if (servletConfig != null && !bf .containsBean (ConfigurableWebApplicationContext .SERVLET_CONFIG_BEAN_NAME )) {
187
+ bf .registerSingleton (ConfigurableWebApplicationContext .SERVLET_CONFIG_BEAN_NAME , servletConfig );
190
188
}
191
189
192
190
if (!bf .containsBean (WebApplicationContext .CONTEXT_PARAMETERS_BEAN_NAME )) {
193
191
Map <String , String > parameterMap = new HashMap <String , String >();
194
- if (sc != null ) {
195
- Enumeration <?> paramNameEnum = sc .getInitParameterNames ();
192
+ if (servletContext != null ) {
193
+ Enumeration <?> paramNameEnum = servletContext .getInitParameterNames ();
196
194
while (paramNameEnum .hasMoreElements ()) {
197
195
String paramName = (String ) paramNameEnum .nextElement ();
198
- parameterMap .put (paramName , sc .getInitParameter (paramName ));
196
+ parameterMap .put (paramName , servletContext .getInitParameter (paramName ));
199
197
}
200
198
}
201
- if (config != null ) {
202
- Enumeration <?> paramNameEnum = config .getInitParameterNames ();
199
+ if (servletConfig != null ) {
200
+ Enumeration <?> paramNameEnum = servletConfig .getInitParameterNames ();
203
201
while (paramNameEnum .hasMoreElements ()) {
204
202
String paramName = (String ) paramNameEnum .nextElement ();
205
- parameterMap .put (paramName , config .getInitParameter (paramName ));
203
+ parameterMap .put (paramName , servletConfig .getInitParameter (paramName ));
206
204
}
207
205
}
208
206
bf .registerSingleton (WebApplicationContext .CONTEXT_PARAMETERS_BEAN_NAME ,
@@ -211,11 +209,11 @@ public static void registerEnvironmentBeans(
211
209
212
210
if (!bf .containsBean (WebApplicationContext .CONTEXT_ATTRIBUTES_BEAN_NAME )) {
213
211
Map <String , Object > attributeMap = new HashMap <String , Object >();
214
- if (sc != null ) {
215
- Enumeration <?> attrNameEnum = sc .getAttributeNames ();
212
+ if (servletContext != null ) {
213
+ Enumeration <?> attrNameEnum = servletContext .getAttributeNames ();
216
214
while (attrNameEnum .hasMoreElements ()) {
217
215
String attrName = (String ) attrNameEnum .nextElement ();
218
- attributeMap .put (attrName , sc .getAttribute (attrName ));
216
+ attributeMap .put (attrName , servletContext .getAttribute (attrName ));
219
217
}
220
218
}
221
219
bf .registerSingleton (WebApplicationContext .CONTEXT_ATTRIBUTES_BEAN_NAME ,
@@ -229,9 +227,7 @@ public static void registerEnvironmentBeans(
229
227
* {@link ServletConfig} parameter.
230
228
* @see #initServletPropertySources(MutablePropertySources, ServletContext, ServletConfig)
231
229
*/
232
- public static void initServletPropertySources (
233
- MutablePropertySources propertySources , ServletContext servletContext ) {
234
-
230
+ public static void initServletPropertySources (MutablePropertySources propertySources , ServletContext servletContext ) {
235
231
initServletPropertySources (propertySources , servletContext , null );
236
232
}
237
233
0 commit comments