Polishing along with 3.1.3 backport

Issue: SPR-9761
Issue: SPR-9762
This commit is contained in:
Juergen Hoeller
2012-10-11 00:30:40 +02:00
committed by unknown
parent 69b380583a
commit 84b3f7106d

View File

@@ -17,7 +17,6 @@
package org.springframework.core.env;
import java.security.AccessControlException;
import java.util.Collections;
import java.util.LinkedHashSet;
import java.util.Map;
@@ -31,7 +30,6 @@ import org.springframework.util.Assert;
import org.springframework.util.StringUtils;
import static java.lang.String.*;
import static org.springframework.util.StringUtils.*;
/**
@@ -88,15 +86,14 @@ public abstract class AbstractEnvironment implements ConfigurableEnvironment {
*/
protected static final String RESERVED_DEFAULT_PROFILE_NAME = "default";
protected final Log logger = LogFactory.getLog(getClass());
private Set<String> activeProfiles = new LinkedHashSet<String>();
private Set<String> defaultProfiles =
new LinkedHashSet<String>(this.getReservedDefaultProfiles());
private Set<String> defaultProfiles = new LinkedHashSet<String>(getReservedDefaultProfiles());
private final MutablePropertySources propertySources =
new MutablePropertySources(this.logger);
private final MutablePropertySources propertySources = new MutablePropertySources(this.logger);
private final ConfigurablePropertyResolver propertyResolver =
new PropertySourcesPropertyResolver(this.propertySources);
@@ -110,13 +107,11 @@ public abstract class AbstractEnvironment implements ConfigurableEnvironment {
* @see #customizePropertySources(MutablePropertySources)
*/
public AbstractEnvironment() {
String name = this.getClass().getSimpleName();
String name = getClass().getSimpleName();
if (this.logger.isDebugEnabled()) {
this.logger.debug(format("Initializing new %s", name));
}
this.customizePropertySources(this.propertySources);
customizePropertySources(this.propertySources);
if (this.logger.isDebugEnabled()) {
this.logger.debug(format(
"Initialized %s with PropertySources %s", name, this.propertySources));
@@ -245,7 +240,7 @@ public abstract class AbstractEnvironment implements ConfigurableEnvironment {
Assert.notNull(profiles, "Profile array must not be null");
this.activeProfiles.clear();
for (String profile : profiles) {
this.addActiveProfile(profile);
addActiveProfile(profile);
}
}
@@ -253,7 +248,7 @@ public abstract class AbstractEnvironment implements ConfigurableEnvironment {
if (this.logger.isDebugEnabled()) {
this.logger.debug(format("Activating profile '%s'", profile));
}
this.validateProfile(profile);
validateProfile(profile);
this.activeProfiles.add(profile);
}
@@ -274,10 +269,10 @@ public abstract class AbstractEnvironment implements ConfigurableEnvironment {
* @see #getReservedDefaultProfiles()
*/
protected Set<String> doGetDefaultProfiles() {
if (this.defaultProfiles.equals(this.getReservedDefaultProfiles())) {
if (this.defaultProfiles.equals(getReservedDefaultProfiles())) {
String profiles = this.getProperty(DEFAULT_PROFILES_PROPERTY_NAME);
if (StringUtils.hasText(profiles)) {
this.setDefaultProfiles(commaDelimitedListToStringArray(trimAllWhitespace(profiles)));
setDefaultProfiles(commaDelimitedListToStringArray(trimAllWhitespace(profiles)));
}
}
return this.defaultProfiles;
@@ -294,7 +289,7 @@ public abstract class AbstractEnvironment implements ConfigurableEnvironment {
Assert.notNull(profiles, "Profile array must not be null");
this.defaultProfiles.clear();
for (String profile : profiles) {
this.validateProfile(profile);
validateProfile(profile);
this.defaultProfiles.add(profile);
}
}
@@ -303,9 +298,9 @@ public abstract class AbstractEnvironment implements ConfigurableEnvironment {
Assert.notEmpty(profiles, "Must specify at least one profile");
for (String profile : profiles) {
if (profile != null && profile.length() > 0 && profile.charAt(0) == '!') {
return !this.isProfileActive(profile.substring(1));
return !isProfileActive(profile.substring(1));
}
if (this.isProfileActive(profile)) {
if (isProfileActive(profile)) {
return true;
}
}
@@ -316,12 +311,11 @@ public abstract class AbstractEnvironment implements ConfigurableEnvironment {
* Return whether the given profile is active, or if active profiles are empty
* whether the profile should be active by default.
* @throws IllegalArgumentException per {@link #validateProfile(String)}
* @since 3.2
*/
protected boolean isProfileActive(String profile) {
this.validateProfile(profile);
return this.doGetActiveProfiles().contains(profile)
|| (this.doGetActiveProfiles().isEmpty() && this.doGetDefaultProfiles().contains(profile));
validateProfile(profile);
return doGetActiveProfiles().contains(profile) ||
(doGetActiveProfiles().isEmpty() && doGetDefaultProfiles().contains(profile));
}
/**
@@ -482,12 +476,10 @@ public abstract class AbstractEnvironment implements ConfigurableEnvironment {
this.propertyResolver.setPlaceholderPrefix(placeholderPrefix);
}
public void setPlaceholderSuffix(String placeholderSuffix) {
this.propertyResolver.setPlaceholderSuffix(placeholderSuffix);
}
public void setValueSeparator(String valueSeparator) {
this.propertyResolver.setValueSeparator(valueSeparator);
}