Merge 3.1.0 development branch into trunk

Branch in question is 'env' branch from git://git.springsource.org/sandbox/cbeams.git; merged into
git-svn repository with:

    git merge -s recursive -Xtheirs --no-commit env

No merge conflicts, but did need to

    git rm spring-build

prior to committing.

With this change, Spring 3.1.0 development is now happening on SVN
trunk. Further commits to the 3.0.x line will happen in an as-yet
uncreated SVN branch.  3.1.0 snapshots will be available
per the usual nightly CI build from trunk.
This commit is contained in:
Chris Beams
2010-10-25 19:48:20 +00:00
parent b0ea2b13d2
commit f480333d31
211 changed files with 9876 additions and 623 deletions

View File

@@ -21,6 +21,7 @@ import javax.servlet.ServletContext;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.context.support.AbstractRefreshableConfigApplicationContext;
import org.springframework.core.env.DefaultWebEnvironment;
import org.springframework.core.io.Resource;
import org.springframework.core.io.support.ResourcePatternResolver;
import org.springframework.ui.context.Theme;
@@ -92,11 +93,14 @@ public abstract class AbstractRefreshableWebApplicationContext extends AbstractR
public AbstractRefreshableWebApplicationContext() {
setDisplayName("Root WebApplicationContext");
setEnvironment(new DefaultWebEnvironment());
}
public void setServletContext(ServletContext servletContext) {
this.servletContext = servletContext;
// TODO: SPR-7508 extract createEnvironment() method; do also in GWAC
this.getEnvironment().getPropertySources().push(new ServletContextPropertySource(this.servletContext));
}
public ServletContext getServletContext() {
@@ -106,8 +110,10 @@ public abstract class AbstractRefreshableWebApplicationContext extends AbstractR
public void setServletConfig(ServletConfig servletConfig) {
this.servletConfig = servletConfig;
if (servletConfig != null && this.servletContext == null) {
this.servletContext = servletConfig.getServletContext();
this.setServletContext(servletConfig.getServletContext());
}
// TODO: SPR-7508 extract createEnvironment() method; do also in GWAC
this.getEnvironment().getPropertySources().push(new ServletConfigPropertySource(servletConfig));
}
public ServletConfig getServletConfig() {

View File

@@ -71,7 +71,11 @@ public class AnnotationConfigWebApplicationContext extends AbstractRefreshableWe
@Override
protected void loadBeanDefinitions(DefaultListableBeanFactory beanFactory) {
AnnotatedBeanDefinitionReader reader = new AnnotatedBeanDefinitionReader(beanFactory);
reader.setEnvironment(this.getEnvironment());
ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(beanFactory);
scanner.setEnvironment(this.getEnvironment());
BeanNameGenerator beanNameGenerator = getBeanNameGenerator();
ScopeMetadataResolver scopeMetadataResolver = getScopeMetadataResolver();
if (beanNameGenerator != null) {

View File

@@ -21,6 +21,7 @@ import javax.servlet.ServletContext;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.context.support.GenericApplicationContext;
import org.springframework.core.env.DefaultWebEnvironment;
import org.springframework.core.io.Resource;
import org.springframework.core.io.support.ResourcePatternResolver;
import org.springframework.ui.context.Theme;
@@ -60,6 +61,11 @@ public class GenericWebApplicationContext extends GenericApplicationContext
private ThemeSource themeSource;
// override superclass definition of environment
// TODO SPR-7508: polish
{
this.setEnvironment(new DefaultWebEnvironment());
}
/**
* Create a new GenericWebApplicationContext.
@@ -154,6 +160,7 @@ public class GenericWebApplicationContext extends GenericApplicationContext
@Override
protected void onRefresh() {
this.themeSource = UiApplicationContextUtils.initThemeSource(this);
this.getEnvironment().getPropertySources().push(new ServletContextPropertySource(servletContext));
}
public Theme getTheme(String themeName) {

View File

@@ -0,0 +1,70 @@
/*
* Copyright 2002-2010 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.web.context.support;
import java.util.Enumeration;
import javax.servlet.ServletConfig;
import org.springframework.core.env.DefaultWebEnvironment;
import org.springframework.core.env.PropertySource;
/**
* TODO SPR-7508: document
*
* @author Chris Beams
* @since 3.1
* @see ServletContextPropertySource
*/
public class ServletConfigPropertySource extends PropertySource<ServletConfig> {
public ServletConfigPropertySource(ServletConfig servletConfig) {
this(DefaultWebEnvironment.SERVLET_CONFIG_PARAMS_PROPERTY_SOURCE_NAME, servletConfig);
}
public ServletConfigPropertySource(String name, ServletConfig servletConfig) {
super(name, servletConfig);
}
@Override
public boolean containsProperty(String name) {
Enumeration<?> initParamNames = this.source.getInitParameterNames();
while (initParamNames.hasMoreElements()) {
if (initParamNames.nextElement().equals(name)) {
return true;
}
}
return false;
}
@Override
public String getProperty(String name) {
return this.source.getInitParameter(name);
}
@Override
public int size() {
int size=0;
Enumeration<?> initParamNames = this.source.getInitParameterNames();
while (initParamNames.hasMoreElements()) {
initParamNames.nextElement();
size++;
}
return size;
}
}

View File

@@ -21,8 +21,10 @@ import java.util.Properties;
import javax.servlet.ServletContext;
import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer;
import org.springframework.context.support.EnvironmentAwarePropertyPlaceholderConfigurer;
import org.springframework.web.context.ServletContextAware;
/**
* Subclass of PropertyPlaceholderConfigurer that resolves placeholders as
* ServletContext init parameters (that is, <code>web.xml</code> context-param
@@ -57,7 +59,10 @@ import org.springframework.web.context.ServletContextAware;
* @see #setSearchContextAttributes
* @see javax.servlet.ServletContext#getInitParameter(String)
* @see javax.servlet.ServletContext#getAttribute(String)
* @deprecated in Spring 3.1 in favor of {@link EnvironmentAwarePropertyPlaceholderConfigurer}
* in conjunction with {@link org.springframework.core.env.DefaultWebEnvironment}.
*/
@Deprecated
public class ServletContextPropertyPlaceholderConfigurer extends PropertyPlaceholderConfigurer
implements ServletContextAware {

View File

@@ -0,0 +1,70 @@
/*
* Copyright 2002-2010 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.web.context.support;
import java.util.Enumeration;
import javax.servlet.ServletContext;
import org.springframework.core.env.DefaultWebEnvironment;
import org.springframework.core.env.PropertySource;
/**
* TODO SPR-7508: document
*
* @author Chris Beams
* @since 3.1
* @see ServletConfigPropertySource
*/
public class ServletContextPropertySource extends PropertySource<ServletContext> {
public ServletContextPropertySource(ServletContext servletContext) {
this(DefaultWebEnvironment.SERVLET_CONTEXT_PARAMS_PROPERTY_SOURCE_NAME, servletContext);
}
public ServletContextPropertySource(String name, ServletContext servletContext) {
super(name, servletContext);
}
@Override
public boolean containsProperty(String name) {
Enumeration<?> initParamNames = this.source.getInitParameterNames();
while (initParamNames.hasMoreElements()) {
if (initParamNames.nextElement().equals(name)) {
return true;
}
}
return false;
}
@Override
public String getProperty(String name) {
return this.source.getInitParameter(name);
}
@Override
public int size() {
int size=0;
Enumeration<?> initParamNames = this.source.getInitParameterNames();
while (initParamNames.hasMoreElements()) {
initParamNames.nextElement();
size++;
}
return size;
}
}

View File

@@ -16,11 +16,15 @@
package org.springframework.web.context.support;
import java.util.LinkedList;
import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.context.support.StaticApplicationContext;
import org.springframework.core.env.DefaultWebEnvironment;
import org.springframework.core.env.PropertySource;
import org.springframework.core.io.Resource;
import org.springframework.core.io.support.ResourcePatternResolver;
import org.springframework.ui.context.Theme;
@@ -66,6 +70,7 @@ public class StaticWebApplicationContext extends StaticApplicationContext
public StaticWebApplicationContext() {
setDisplayName("Root WebApplicationContext");
setEnvironment(new DefaultWebEnvironment()); // TODO SPR-7508: see GenericWebApplicationContext, AbstractRefreshableWebApplicationContext
}
@@ -164,6 +169,9 @@ public class StaticWebApplicationContext extends StaticApplicationContext
@Override
protected void onRefresh() {
this.themeSource = UiApplicationContextUtils.initThemeSource(this);
LinkedList<PropertySource<?>> propertySources = this.getEnvironment().getPropertySources();
propertySources.push(new ServletContextPropertySource(servletContext));
propertySources.push(new ServletConfigPropertySource(servletConfig));
}
public Theme getTheme(String themeName) {

View File

@@ -84,6 +84,7 @@ public class XmlWebApplicationContext extends AbstractRefreshableWebApplicationC
// Configure the bean definition reader with this context's
// resource loading environment.
beanDefinitionReader.setEnvironment(this.getEnvironment());
beanDefinitionReader.setResourceLoader(this);
beanDefinitionReader.setEntityResolver(new ResourceEntityResolver(this));

View File

@@ -37,6 +37,9 @@ import org.springframework.beans.PropertyValues;
import org.springframework.beans.factory.BeanNameAware;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.context.EnvironmentAware;
import org.springframework.core.env.DefaultWebEnvironment;
import org.springframework.core.env.Environment;
import org.springframework.core.io.Resource;
import org.springframework.core.io.ResourceEditor;
import org.springframework.core.io.ResourceLoader;
@@ -74,7 +77,7 @@ import org.springframework.web.util.NestedServletException;
* @see #doFilter
*/
public abstract class GenericFilterBean implements
Filter, BeanNameAware, ServletContextAware, InitializingBean, DisposableBean {
Filter, BeanNameAware, EnvironmentAware, ServletContextAware, InitializingBean, DisposableBean {
/** Logger available to subclasses */
protected final Log logger = LogFactory.getLog(getClass());
@@ -88,9 +91,15 @@ public abstract class GenericFilterBean implements
/* The FilterConfig of this filter */
private FilterConfig filterConfig;
private String beanName;
/**
* TODO SPR-7508: document
* Defaults to {@link DefaultWebEnvironment}; can be overriden if deployed
* as a spring bean by {@link #setEnvironment(Environment)}
*/
private Environment environment = new DefaultWebEnvironment();
private ServletContext servletContext;
@@ -105,6 +114,13 @@ public abstract class GenericFilterBean implements
this.beanName = beanName;
}
/**
* TODO SPR-7508: document
*/
public void setEnvironment(Environment environment) {
this.environment = environment;
}
/**
* Stores the ServletContext that the bean factory runs in.
* <p>Only relevant in case of initialization as bean, to have a ServletContext
@@ -164,7 +180,7 @@ public abstract class GenericFilterBean implements
PropertyValues pvs = new FilterConfigPropertyValues(filterConfig, this.requiredProperties);
BeanWrapper bw = PropertyAccessorFactory.forBeanPropertyAccess(this);
ResourceLoader resourceLoader = new ServletContextResourceLoader(filterConfig.getServletContext());
bw.registerCustomEditor(Resource.class, new ResourceEditor(resourceLoader));
bw.registerCustomEditor(Resource.class, new ResourceEditor(resourceLoader, this.environment));
initBeanWrapper(bw);
bw.setPropertyValues(pvs, true);
}