diff --git a/spring-core/src/main/java/org/springframework/core/env/EnumerablePropertySource.java b/spring-core/src/main/java/org/springframework/core/env/EnumerablePropertySource.java index bcd220e6dd..e63a3c733d 100644 --- a/spring-core/src/main/java/org/springframework/core/env/EnumerablePropertySource.java +++ b/spring-core/src/main/java/org/springframework/core/env/EnumerablePropertySource.java @@ -16,10 +16,7 @@ package org.springframework.core.env; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -import org.springframework.util.Assert; +import org.springframework.util.ObjectUtils; /** * A {@link PropertySource} implementation capable of interrogating its @@ -41,24 +38,16 @@ import org.springframework.util.Assert; * or not. * * @author Chris Beams + * @author Juergen Hoeller * @since 3.1 */ public abstract class EnumerablePropertySource extends PropertySource { - protected final Log logger = LogFactory.getLog(getClass()); - - public EnumerablePropertySource(String name, T source) { super(name, source); } - /** - * 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. *

This implementation checks for the presence of the given name within the @@ -67,19 +56,13 @@ public abstract class EnumerablePropertySource extends PropertySource { */ @Override public boolean containsProperty(String name) { - Assert.notNull(name, "Property name must not be null"); - for (String candidate : getPropertyNames()) { - if (candidate.equals(name)) { - if (logger.isDebugEnabled()) { - logger.debug(String.format("PropertySource [%s] contains '%s'", getName(), name)); - } - return true; - } - } - if (logger.isTraceEnabled()) { - logger.trace(String.format("PropertySource [%s] does not contain '%s'", getName(), name)); - } - return false; + return ObjectUtils.containsElement(getPropertyNames(), name); } + /** + * Return the names of all properties contained by the + * {@linkplain #getSource() source} object (never {@code null}). + */ + public abstract String[] getPropertyNames(); + } diff --git a/spring-core/src/main/java/org/springframework/core/env/MapPropertySource.java b/spring-core/src/main/java/org/springframework/core/env/MapPropertySource.java index 9f9863dc43..0a4a173fa0 100644 --- a/spring-core/src/main/java/org/springframework/core/env/MapPropertySource.java +++ b/spring-core/src/main/java/org/springframework/core/env/MapPropertySource.java @@ -18,13 +18,13 @@ package org.springframework.core.env; import java.util.Map; -import org.springframework.util.Assert; import org.springframework.util.StringUtils; /** * {@link PropertySource} that reads keys and values from a {@code Map} object. * * @author Chris Beams + * @author Juergen Hoeller * @since 3.1 * @see PropertiesPropertySource */ @@ -34,25 +34,20 @@ public class MapPropertySource extends EnumerablePropertySourceThis 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,23 +101,24 @@ public class SystemEnvironmentPropertySource extends MapPropertySource { * found or otherwise the original name. Never returns {@code null}. */ private String resolvePropertyName(String name) { - if (super.containsProperty(name)) { + Assert.notNull(name, "Property name must not be null"); + if (ObjectUtils.containsElement(getPropertyNames(), name)) { return name; } String usName = name.replace('.', '_'); - if (!name.equals(usName) && super.containsProperty(usName)) { + if (!name.equals(usName) && ObjectUtils.containsElement(getPropertyNames(), usName)) { return usName; } String ucName = name.toUpperCase(); if (!name.equals(ucName)) { - if (super.containsProperty(ucName)) { + if (ObjectUtils.containsElement(getPropertyNames(), ucName)) { return ucName; } else { String usUcName = ucName.replace('.', '_'); - if (!ucName.equals(usUcName) && super.containsProperty(usUcName)) { + if (!ucName.equals(usUcName) && ObjectUtils.containsElement(getPropertyNames(), usUcName)) { return usUcName; } } @@ -125,4 +126,5 @@ public class SystemEnvironmentPropertySource extends MapPropertySource { return name; } + }