diff --git a/spring-core/src/main/java/org/springframework/core/env/AbstractEnvironment.java b/spring-core/src/main/java/org/springframework/core/env/AbstractEnvironment.java index aa6da2d2d5..9366080ef6 100644 --- a/spring-core/src/main/java/org/springframework/core/env/AbstractEnvironment.java +++ b/spring-core/src/main/java/org/springframework/core/env/AbstractEnvironment.java @@ -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 activeProfiles = new LinkedHashSet(); - private Set defaultProfiles = - new LinkedHashSet(this.getReservedDefaultProfiles()); + private Set defaultProfiles = new LinkedHashSet(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 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); }