Polishing

(cherry picked from commit 16325c2)
This commit is contained in:
Juergen Hoeller
2014-09-20 00:29:16 +02:00
parent 205e681295
commit 50e50d0c18
12 changed files with 218 additions and 200 deletions

View File

@@ -295,7 +295,8 @@ public abstract class AbstractEnvironment implements ConfigurableEnvironment {
}
/**
* {@inheritDoc}
* Specify the set of profiles to be made active by default if no other profiles
* are explicitly made active through {@link #setActiveProfiles}.
* <p>Calling this method removes overrides any reserved default profiles
* that may have been added during construction of the environment.
* @see #AbstractEnvironment()
@@ -455,6 +456,51 @@ public abstract class AbstractEnvironment implements ConfigurableEnvironment {
// Implementation of ConfigurablePropertyResolver interface
//---------------------------------------------------------------------
@Override
public ConfigurableConversionService getConversionService() {
return this.propertyResolver.getConversionService();
}
@Override
public void setConversionService(ConfigurableConversionService conversionService) {
this.propertyResolver.setConversionService(conversionService);
}
@Override
public void setPlaceholderPrefix(String placeholderPrefix) {
this.propertyResolver.setPlaceholderPrefix(placeholderPrefix);
}
@Override
public void setPlaceholderSuffix(String placeholderSuffix) {
this.propertyResolver.setPlaceholderSuffix(placeholderSuffix);
}
@Override
public void setValueSeparator(String valueSeparator) {
this.propertyResolver.setValueSeparator(valueSeparator);
}
@Override
public void setIgnoreUnresolvableNestedPlaceholders(boolean ignoreUnresolvableNestedPlaceholders) {
this.propertyResolver.setIgnoreUnresolvableNestedPlaceholders(ignoreUnresolvableNestedPlaceholders);
}
@Override
public void setRequiredProperties(String... requiredProperties) {
this.propertyResolver.setRequiredProperties(requiredProperties);
}
@Override
public void validateRequiredProperties() throws MissingRequiredPropertiesException {
this.propertyResolver.validateRequiredProperties();
}
//---------------------------------------------------------------------
// Implementation of PropertyResolver interface
//---------------------------------------------------------------------
@Override
public boolean containsProperty(String key) {
return this.propertyResolver.containsProperty(key);
@@ -495,16 +541,6 @@ public abstract class AbstractEnvironment implements ConfigurableEnvironment {
return this.propertyResolver.getRequiredProperty(key, targetType);
}
@Override
public void setRequiredProperties(String... requiredProperties) {
this.propertyResolver.setRequiredProperties(requiredProperties);
}
@Override
public void validateRequiredProperties() throws MissingRequiredPropertiesException {
this.propertyResolver.validateRequiredProperties();
}
@Override
public String resolvePlaceholders(String text) {
return this.propertyResolver.resolvePlaceholders(text);
@@ -515,36 +551,6 @@ public abstract class AbstractEnvironment implements ConfigurableEnvironment {
return this.propertyResolver.resolveRequiredPlaceholders(text);
}
@Override
public void setIgnoreUnresolvableNestedPlaceholders(boolean ignoreUnresolvableNestedPlaceholders) {
this.propertyResolver.setIgnoreUnresolvableNestedPlaceholders(ignoreUnresolvableNestedPlaceholders);
}
@Override
public void setConversionService(ConfigurableConversionService conversionService) {
this.propertyResolver.setConversionService(conversionService);
}
@Override
public ConfigurableConversionService getConversionService() {
return this.propertyResolver.getConversionService();
}
@Override
public void setPlaceholderPrefix(String placeholderPrefix) {
this.propertyResolver.setPlaceholderPrefix(placeholderPrefix);
}
@Override
public void setPlaceholderSuffix(String placeholderSuffix) {
this.propertyResolver.setPlaceholderSuffix(placeholderSuffix);
}
@Override
public void setValueSeparator(String valueSeparator) {
this.propertyResolver.setValueSeparator(valueSeparator);
}
@Override
public String toString() {

View File

@@ -65,16 +65,50 @@ public abstract class AbstractPropertyResolver implements ConfigurablePropertyRe
this.conversionService = conversionService;
}
/**
* Set the prefix that placeholders replaced by this resolver must begin with.
* <p>The default is "${".
* @see org.springframework.util.SystemPropertyUtils#PLACEHOLDER_PREFIX
*/
@Override
public String getProperty(String key, String defaultValue) {
String value = getProperty(key);
return (value != null ? value : defaultValue);
public void setPlaceholderPrefix(String placeholderPrefix) {
this.placeholderPrefix = placeholderPrefix;
}
/**
* Set the suffix that placeholders replaced by this resolver must end with.
* <p>The default is "}".
* @see org.springframework.util.SystemPropertyUtils#PLACEHOLDER_SUFFIX
*/
@Override
public <T> T getProperty(String key, Class<T> targetType, T defaultValue) {
T value = getProperty(key, targetType);
return (value != null ? value : defaultValue);
public void setPlaceholderSuffix(String placeholderSuffix) {
this.placeholderSuffix = placeholderSuffix;
}
/**
* Specify the separating character between the placeholders replaced by this
* resolver and their associated default value, or {@code null} if no such
* special character should be processed as a value separator.
* <p>The default is ":".
* @see org.springframework.util.SystemPropertyUtils#VALUE_SEPARATOR
*/
@Override
public void setValueSeparator(String valueSeparator) {
this.valueSeparator = valueSeparator;
}
/**
* Set whether to throw an exception when encountering an unresolvable placeholder
* nested within the value of a given property. A {@code false} value indicates strict
* resolution, i.e. that an exception will be thrown. A {@code true} value indicates
* that unresolvable nested placeholders should be passed through in their unresolved
* ${...} form.
* <p>The default is {@code false}.
* @since 3.2
*/
@Override
public void setIgnoreUnresolvableNestedPlaceholders(boolean ignoreUnresolvableNestedPlaceholders) {
this.ignoreUnresolvableNestedPlaceholders = ignoreUnresolvableNestedPlaceholders;
}
@Override
@@ -97,6 +131,19 @@ public abstract class AbstractPropertyResolver implements ConfigurablePropertyRe
}
}
@Override
public String getProperty(String key, String defaultValue) {
String value = getProperty(key);
return (value != null ? value : defaultValue);
}
@Override
public <T> T getProperty(String key, Class<T> targetType, T defaultValue) {
T value = getProperty(key, targetType);
return (value != null ? value : defaultValue);
}
@Override
public String getRequiredProperty(String key) throws IllegalStateException {
String value = getProperty(key);
@@ -115,33 +162,6 @@ public abstract class AbstractPropertyResolver implements ConfigurablePropertyRe
return value;
}
/**
* {@inheritDoc} The default is "${".
* @see org.springframework.util.SystemPropertyUtils#PLACEHOLDER_PREFIX
*/
@Override
public void setPlaceholderPrefix(String placeholderPrefix) {
this.placeholderPrefix = placeholderPrefix;
}
/**
* {@inheritDoc} The default is "}".
* @see org.springframework.util.SystemPropertyUtils#PLACEHOLDER_SUFFIX
*/
@Override
public void setPlaceholderSuffix(String placeholderSuffix) {
this.placeholderSuffix = placeholderSuffix;
}
/**
* {@inheritDoc} The default is ":".
* @see org.springframework.util.SystemPropertyUtils#VALUE_SEPARATOR
*/
@Override
public void setValueSeparator(String valueSeparator) {
this.valueSeparator = valueSeparator;
}
@Override
public String resolvePlaceholders(String text) {
if (this.nonStrictHelper == null) {
@@ -158,16 +178,6 @@ public abstract class AbstractPropertyResolver implements ConfigurablePropertyRe
return doResolvePlaceholders(text, this.strictHelper);
}
/**
* {@inheritDoc}
* <p>The default value for this implementation is {@code false}.
* @since 3.2
*/
@Override
public void setIgnoreUnresolvableNestedPlaceholders(boolean ignoreUnresolvableNestedPlaceholders) {
this.ignoreUnresolvableNestedPlaceholders = ignoreUnresolvableNestedPlaceholders;
}
/**
* Resolve placeholders within the given string, deferring to the value of
* {@link #setIgnoreUnresolvableNestedPlaceholders} to determine whether any
@@ -199,6 +209,7 @@ public abstract class AbstractPropertyResolver implements ConfigurablePropertyRe
});
}
/**
* Retrieve the specified property as a raw String,
* i.e. without resolution of nested placeholders.

View File

@@ -223,8 +223,7 @@ public abstract class CommandLinePropertySource<T> extends EnumerablePropertySou
}
/**
* Return whether this {@code PropertySource} contains a property with the given name.
* <p>This implementation first checks to see if the name specified is the special
* This implementation first checks to see if the name specified is the special
* {@linkplain #setNonOptionArgsPropertyName(String) "non-option arguments" property},
* and if so delegates to the abstract {@link #getNonOptionArgs()} method
* checking to see whether it returns an empty collection. Otherwise delegates to and
@@ -239,8 +238,7 @@ public abstract class CommandLinePropertySource<T> extends EnumerablePropertySou
}
/**
* {@inheritDoc}
* <p>This implementation first checks to see if the name specified is the special
* This implementation first checks to see if the name specified is the special
* {@linkplain #setNonOptionArgsPropertyName(String) "non-option arguments" property},
* and if so delegates to the abstract {@link #getNonOptionArgs()} method. If so
* and the collection of non-option arguments is empty, this method returns {@code

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2014 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.
@@ -73,6 +73,19 @@ public interface ConfigurablePropertyResolver extends PropertyResolver {
*/
void setValueSeparator(String valueSeparator);
/**
* Set whether to throw an exception when encountering an unresolvable placeholder
* nested within the value of a given property. A {@code false} value indicates strict
* resolution, i.e. that an exception will be thrown. A {@code true} value indicates
* that unresolvable nested placeholders should be passed through in their unresolved
* ${...} form.
* <p>Implementations of {@link #getProperty(String)} and its variants must inspect
* the value set here to determine correct behavior when property values contain
* unresolvable placeholders.
* @since 3.2
*/
void setIgnoreUnresolvableNestedPlaceholders(boolean ignoreUnresolvableNestedPlaceholders);
/**
* Specify which properties must be present, to be verified by
* {@link #validateRequiredProperties()}.
@@ -88,16 +101,4 @@ public interface ConfigurablePropertyResolver extends PropertyResolver {
*/
void validateRequiredProperties() throws MissingRequiredPropertiesException;
/**
* Set whether to throw an exception when encountering an unresolvable placeholder
* nested within the value of a given property. A {@code false} value indicates strict
* resolution, i.e. that an exception will be thrown. A {@code true} value indicates
* that unresolvable nested placeholders should be passed through in their unresolved
* ${...} form.
* <p>Implementations of {@link #getProperty(String)} and its variants must inspect
* the value set here to determine correct behavior when property values contain
* unresolvable placeholders.
* @since 3.2
*/
void setIgnoreUnresolvableNestedPlaceholders(boolean ignoreUnresolvableNestedPlaceholders);
}

View File

@@ -41,6 +41,7 @@ import org.springframework.util.Assert;
* or not.
*
* @author Chris Beams
* @author Juergen Hoeller
* @since 3.1
*/
public abstract class EnumerablePropertySource<T> extends PropertySource<T> {
@@ -56,12 +57,6 @@ public abstract class EnumerablePropertySource<T> extends PropertySource<T> {
}
/**
* Return the names of all properties contained by the
* {@linkplain #getSource() source} object (never {@code null}).
*/
public abstract String[] getPropertyNames();
/**
* Return whether this {@code PropertySource} contains a property with the given name.
* <p>This implementation checks for the presence of the given name within the
@@ -85,4 +80,10 @@ public abstract class EnumerablePropertySource<T> extends PropertySource<T> {
return false;
}
/**
* Return the names of all properties contained by the
* {@linkplain #getSource() source} object (never {@code null}).
*/
public abstract String[] getPropertyNames();
}

View File

@@ -33,6 +33,7 @@ public class MapPropertySource extends EnumerablePropertySource<Map<String, Obje
super(name, source);
}
@Override
public Object getProperty(String name) {
return this.source.get(name);

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2013 the original author or authors.
* Copyright 2002-2014 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.
@@ -40,11 +40,11 @@ import org.springframework.util.Assert;
* {@code true} if any of the above properties are present, otherwise {@code false}.
*
* <p>This feature is particularly useful when specifying active or default profiles as
* environment variables. The following is not allowable under Bash
* environment variables. The following is not allowable under Bash:
*
* <pre class="code">spring.profiles.active=p1 java -classpath ... MyApp</pre>
*
* However, the following syntax is permitted and is also more conventional.
* However, the following syntax is permitted and is also more conventional:
*
* <pre class="code">SPRING_PROFILES_ACTIVE=p1 java -classpath ... MyApp</pre>
*
@@ -70,8 +70,9 @@ public class SystemEnvironmentPropertySource extends MapPropertySource {
super(name, source);
}
/**
* Return true if a property with the given name or any underscore/uppercase variant
* Return {@code true} if a property with the given name or any underscore/uppercase variant
* thereof exists in this property source.
*/
@Override
@@ -80,13 +81,11 @@ public class SystemEnvironmentPropertySource extends MapPropertySource {
}
/**
* {@inheritDoc}
* <p>This implementation returns {@code true} if a property with the given name or
* This implementation returns {@code true} if a property with the given name or
* any underscore/uppercase variant thereof exists in this property source.
*/
@Override
public Object getProperty(String name) {
Assert.notNull(name, "property name must not be null");
String actualName = resolvePropertyName(name);
if (logger.isDebugEnabled() && !name.equals(actualName)) {
logger.debug(String.format("PropertySource [%s] does not contain '%s', but found equivalent '%s'",
@@ -101,6 +100,7 @@ public class SystemEnvironmentPropertySource extends MapPropertySource {
* found or otherwise the original name. Never returns {@code null}.
*/
private String resolvePropertyName(String name) {
Assert.notNull(name, "Property name must not be null");
if (super.containsProperty(name)) {
return name;
}
@@ -125,4 +125,5 @@ public class SystemEnvironmentPropertySource extends MapPropertySource {
return name;
}
}