Remove unecessary reflection hacks

pull/2071/head
Dave Syer 10 years ago
parent d9ca0869b5
commit 0b19884f58

@ -16,12 +16,9 @@
package org.springframework.boot.actuate.endpoint;
import java.lang.reflect.Field;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.EnvironmentAware;
@ -32,7 +29,6 @@ import org.springframework.core.env.Environment;
import org.springframework.core.env.MutablePropertySources;
import org.springframework.core.env.PropertySource;
import org.springframework.core.env.StandardEnvironment;
import org.springframework.util.ReflectionUtils;
/**
* {@link Endpoint} to expose {@link ConfigurableEnvironment environment} information.
@ -98,8 +94,8 @@ public class EnvironmentEndpoint extends AbstractEndpoint<Map<String, Object>> i
private void extract(String root, Map<String, PropertySource<?>> map,
PropertySource<?> source) {
if (source instanceof CompositePropertySource) {
Set<PropertySource<?>> nested = getNestedPropertySources((CompositePropertySource) source);
for (PropertySource<?> nest : nested) {
for (PropertySource<?> nest : ((CompositePropertySource) source)
.getPropertySources()) {
extract(source.getName() + ":", map, nest);
}
}
@ -108,19 +104,6 @@ public class EnvironmentEndpoint extends AbstractEndpoint<Map<String, Object>> i
}
}
@SuppressWarnings("unchecked")
private Set<PropertySource<?>> getNestedPropertySources(CompositePropertySource source) {
try {
Field field = ReflectionUtils.findField(CompositePropertySource.class,
"propertySources");
field.setAccessible(true);
return (Set<PropertySource<?>>) field.get(source);
}
catch (Exception ex) {
return Collections.emptySet();
}
}
public Object sanitize(String name, Object object) {
return this.sanitizer.sanitize(name, object);
}

@ -16,7 +16,6 @@
package org.springframework.boot.bind;
import java.lang.reflect.Field;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
@ -32,7 +31,6 @@ import org.springframework.core.env.PropertySource;
import org.springframework.core.env.PropertySources;
import org.springframework.core.env.PropertySourcesPropertyResolver;
import org.springframework.core.env.StandardEnvironment;
import org.springframework.util.ReflectionUtils;
import org.springframework.validation.DataBinder;
/**
@ -142,27 +140,11 @@ public class PropertySourcesPropertyValues implements PropertyValues {
private void processCompositePropertySource(CompositePropertySource source,
PropertySourcesPropertyResolver resolver,
PropertyNamePatternsMatcher includes, Collection<String> exacts) {
for (PropertySource<?> nested : extractSources(source)) {
for (PropertySource<?> nested : source.getPropertySources()) {
processPropertySource(nested, resolver, includes, exacts);
}
}
private Collection<PropertySource<?>> extractSources(CompositePropertySource composite) {
Field field = ReflectionUtils.findField(CompositePropertySource.class,
"propertySources");
field.setAccessible(true);
try {
@SuppressWarnings("unchecked")
Collection<PropertySource<?>> collection = (Collection<PropertySource<?>>) field
.get(composite);
return collection;
}
catch (Exception ex) {
throw new IllegalStateException(
"Cannot extract property sources from composite", ex);
}
}
private void processDefaultPropertySource(PropertySource<?> source,
PropertySourcesPropertyResolver resolver,
PropertyNamePatternsMatcher includes, Collection<String> exacts) {

Loading…
Cancel
Save