renamed AbstractPropertyPlaceholderConfigurer to PlaceholderConfigurerSupport

git-svn-id: https://src.springframework.org/svn/spring-framework/trunk@3985 50f2f4bb-b051-0410-bef5-90022cba6387
This commit is contained in:
Juergen Hoeller 2011-02-10 01:55:11 +00:00
parent c16e01cb14
commit 541f8595ab
3 changed files with 67 additions and 61 deletions

View File

@ -85,7 +85,7 @@ import org.springframework.util.StringValueResolver;
* @see PropertyPlaceholderConfigurer
* @see org.springframework.context.support.PropertySourcesPlaceholderConfigurer
*/
public abstract class AbstractPropertyPlaceholderConfigurer extends PropertyResourceConfigurer
public abstract class PlaceholderConfigurerSupport extends PropertyResourceConfigurer
implements BeanNameAware, BeanFactoryAware {
/** Default placeholder prefix: {@value} */
@ -97,6 +97,7 @@ public abstract class AbstractPropertyPlaceholderConfigurer extends PropertyReso
/** Default value separator: {@value} */
public static final String DEFAULT_VALUE_SEPARATOR = ":";
/** Defaults to {@value #DEFAULT_PLACEHOLDER_PREFIX} */
protected String placeholderPrefix = DEFAULT_PLACEHOLDER_PREFIX;
@ -189,8 +190,10 @@ public abstract class AbstractPropertyPlaceholderConfigurer extends PropertyReso
this.beanFactory = beanFactory;
}
protected void doProcessProperties(ConfigurableListableBeanFactory beanFactoryToProcess,
StringValueResolver valueResolver) {
BeanDefinitionVisitor visitor = new BeanDefinitionVisitor(valueResolver);
String[] beanNames = beanFactoryToProcess.getBeanDefinitionNames();

View File

@ -20,15 +20,13 @@ import java.util.Properties;
import java.util.Set;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanFactoryAware;
import org.springframework.beans.factory.BeanNameAware;
import org.springframework.core.Constants;
import org.springframework.util.PropertyPlaceholderHelper;
import org.springframework.util.PropertyPlaceholderHelper.PlaceholderResolver;
import org.springframework.util.StringValueResolver;
/**
* {@link AbstractPropertyPlaceholderConfigurer} subclass that resolves ${...} placeholders
* {@link PlaceholderConfigurerSupport} subclass that resolves ${...} placeholders
* against {@link #setLocation local} {@link #setProperties properties} and/or system properties
* and environment variables.
*
@ -50,7 +48,7 @@ import org.springframework.util.StringValueResolver;
*
* <p>Prior to Spring 3.1, the {@code <context:property-placeholder/>} namespace element
* registered an instance of {@code PropertyPlaceholderConfigurer}. It will still do so if
* using the {@code spring-beans-3.0.xsd} definition of the namespace. That is, you can preserve
* using the {@code spring-context-3.0.xsd} definition of the namespace. That is, you can preserve
* registration of {@code PropertyPlaceholderConfigurer} through the namespace, even if using Spring 3.1;
* simply do not update your {@code xsi:schemaLocation} and continue using the 3.0 XSD.
*
@ -58,12 +56,11 @@ import org.springframework.util.StringValueResolver;
* @author Chris Beams
* @since 02.10.2003
* @see #setSystemPropertiesModeName
* @see AbstractPropertyPlaceholderConfigurer
* @see PlaceholderConfigurerSupport
* @see PropertyOverrideConfigurer
* @see org.springframework.context.support.PropertySourcesPlaceholderConfigurer
*/
public class PropertyPlaceholderConfigurer extends AbstractPropertyPlaceholderConfigurer
implements BeanNameAware, BeanFactoryAware {
public class PropertyPlaceholderConfigurer extends PlaceholderConfigurerSupport {
/** Never check system properties. */
public static final int SYSTEM_PROPERTIES_MODE_NEVER = 0;
@ -140,7 +137,7 @@ public class PropertyPlaceholderConfigurer extends AbstractPropertyPlaceholderCo
/**
* Resolve the given placeholder using the given properties, performing
* a system properties check according to the given mode.
* <p>Default implementation delegates to <code>resolvePlaceholder
* <p>The default implementation delegates to <code>resolvePlaceholder
* (placeholder, props)</code> before/after the system properties check.
* <p>Subclasses can override this for custom resolution strategies,
* including customized points for the system properties check.
@ -209,6 +206,7 @@ public class PropertyPlaceholderConfigurer extends AbstractPropertyPlaceholderCo
}
}
/**
* Visit each bean definition in the given bean factory and attempt to replace ${...} property
* placeholders with values from the given properties.
@ -222,24 +220,6 @@ public class PropertyPlaceholderConfigurer extends AbstractPropertyPlaceholderCo
this.doProcessProperties(beanFactoryToProcess, valueResolver);
}
private class PlaceholderResolvingStringValueResolver implements StringValueResolver {
private final PropertyPlaceholderHelper helper;
private final PlaceholderResolver resolver;
public PlaceholderResolvingStringValueResolver(Properties props) {
this.helper = new PropertyPlaceholderHelper(
placeholderPrefix, placeholderSuffix, valueSeparator, ignoreUnresolvablePlaceholders);
this.resolver = new PropertyPlaceholderConfigurerResolver(props);
}
public String resolveStringValue(String strVal) throws BeansException {
String value = this.helper.replacePlaceholders(strVal, this.resolver);
return (value.equals(nullValue) ? null : value);
}
}
/**
* Parse the given String value for placeholder resolution.
* @param strVal the String value to parse
@ -258,6 +238,26 @@ public class PropertyPlaceholderConfigurer extends AbstractPropertyPlaceholderCo
return helper.replacePlaceholders(strVal, resolver);
}
private class PlaceholderResolvingStringValueResolver implements StringValueResolver {
private final PropertyPlaceholderHelper helper;
private final PlaceholderResolver resolver;
public PlaceholderResolvingStringValueResolver(Properties props) {
this.helper = new PropertyPlaceholderHelper(
placeholderPrefix, placeholderSuffix, valueSeparator, ignoreUnresolvablePlaceholders);
this.resolver = new PropertyPlaceholderConfigurerResolver(props);
}
public String resolveStringValue(String strVal) throws BeansException {
String value = this.helper.replacePlaceholders(strVal, this.resolver);
return (value.equals(nullValue) ? null : value);
}
}
private class PropertyPlaceholderConfigurerResolver implements PlaceholderResolver {
private final Properties props;

View File

@ -17,11 +17,12 @@
package org.springframework.context.support;
import java.io.IOException;
import java.util.Properties;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanInitializationException;
import org.springframework.beans.factory.config.AbstractPropertyPlaceholderConfigurer;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.config.PlaceholderConfigurerSupport;
import org.springframework.context.EnvironmentAware;
import org.springframework.core.env.ConfigurablePropertyResolver;
import org.springframework.core.env.Environment;
@ -33,17 +34,17 @@ import org.springframework.core.env.PropertySourcesPropertyResolver;
import org.springframework.util.StringValueResolver;
/**
* Specialization of {@link AbstractPropertyPlaceholderConfigurer}
* Specialization of {@link org.springframework.beans.factory.config.PlaceholderConfigurerSupport}
*
* <p>Local properties are added as a property source in any case. Precedence is based
* on the value of the {@link #setLocalOverride localOverride} property.
*
* @author Chris Beams
* @since 3.1
* @see AbstractPropertyPlaceholderConfigurer
* @see org.springframework.beans.factory.config.PlaceholderConfigurerSupport
* @see org.springframework.beans.factory.config.PropertyPlaceholderConfigurer
*/
public class PropertySourcesPlaceholderConfigurer extends AbstractPropertyPlaceholderConfigurer
public class PropertySourcesPlaceholderConfigurer extends PlaceholderConfigurerSupport
implements EnvironmentAware {
/**
@ -58,21 +59,12 @@ public class PropertySourcesPlaceholderConfigurer extends AbstractPropertyPlaceh
*/
public static final String ENVIRONMENT_PROPERTIES_PROPERTY_SOURCE_NAME = "environmentProperties";
private MutablePropertySources propertySources;
private Environment environment;
/**
* {@inheritDoc}
* <p>{@code PropertySources} from this environment will be searched when replacing ${...} placeholders
* @see #setPropertySources
* @see #postProcessBeanFactory
*/
public void setEnvironment(Environment environment) {
this.environment = environment;
}
/**
* Customize the set of {@link PropertySources} to be used by this configurer.
* Setting this property indicates that environment property sources and local
@ -83,6 +75,17 @@ public class PropertySourcesPlaceholderConfigurer extends AbstractPropertyPlaceh
this.propertySources = new MutablePropertySources(propertySources);
}
/**
* {@inheritDoc}
* <p>{@code PropertySources} from this environment will be searched when replacing ${...} placeholders.
* @see #setPropertySources
* @see #postProcessBeanFactory
*/
public void setEnvironment(Environment environment) {
this.environment = environment;
}
/**
* {@inheritDoc}
* <p>Processing occurs by replacing ${...} placeholders in bean definitions by resolving each
@ -118,7 +121,8 @@ public class PropertySourcesPlaceholderConfigurer extends AbstractPropertyPlaceh
new PropertiesPropertySource(LOCAL_PROPERTIES_PROPERTY_SOURCE_NAME, this.mergeProperties());
if (this.localOverride) {
this.propertySources.addFirst(localPropertySource);
} else {
}
else {
this.propertySources.addLast(localPropertySource);
}
}
@ -150,20 +154,19 @@ public class PropertySourcesPlaceholderConfigurer extends AbstractPropertyPlaceh
}
};
this.doProcessProperties(beanFactoryToProcess, valueResolver);
doProcessProperties(beanFactoryToProcess, valueResolver);
}
/**
* Implemented for compatibility with {@link AbstractPropertyPlaceholderConfigurer}.
* Implemented for compatibility with {@link org.springframework.beans.factory.config.PlaceholderConfigurerSupport}.
* @deprecated in favor of {@link #processProperties(ConfigurableListableBeanFactory, ConfigurablePropertyResolver)}
* @throws UnsupportedOperationException
*/
@Override
@Deprecated
protected void processProperties(ConfigurableListableBeanFactory beanFactory, java.util.Properties props)
throws BeansException {
protected void processProperties(ConfigurableListableBeanFactory beanFactory, Properties props) {
throw new UnsupportedOperationException(
"call processProperties(ConfigurableListableBeanFactory, ConfigurablePropertyResolver)");
"Call processProperties(ConfigurableListableBeanFactory, ConfigurablePropertyResolver) instead");
}
}