|
|
|
@ -72,65 +72,67 @@ public class PropertySourcesPropertyValues implements PropertyValues { |
|
|
|
this.propertySources = propertySources; |
|
|
|
this.propertySources = propertySources; |
|
|
|
PropertySourcesPropertyResolver resolver = new PropertySourcesPropertyResolver( |
|
|
|
PropertySourcesPropertyResolver resolver = new PropertySourcesPropertyResolver( |
|
|
|
propertySources); |
|
|
|
propertySources); |
|
|
|
String[] includes = patterns == null ? new String[0] : patterns |
|
|
|
String[] includes = toArray(patterns); |
|
|
|
.toArray(new String[0]); |
|
|
|
String[] exacts = toArray(names); |
|
|
|
String[] exacts = names == null ? new String[0] : names.toArray(new String[0]); |
|
|
|
|
|
|
|
for (PropertySource<?> source : propertySources) { |
|
|
|
for (PropertySource<?> source : propertySources) { |
|
|
|
processPropertySource(source, resolver, includes, exacts); |
|
|
|
processPropertySource(source, resolver, includes, exacts); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private String[] toArray(Collection<String> strings) { |
|
|
|
|
|
|
|
if (strings == null) { |
|
|
|
|
|
|
|
return new String[0]; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return strings.toArray(new String[strings.size()]); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void processPropertySource(PropertySource<?> source, |
|
|
|
private void processPropertySource(PropertySource<?> source, |
|
|
|
PropertySourcesPropertyResolver resolver, String[] includes, String[] exacts) { |
|
|
|
PropertySourcesPropertyResolver resolver, String[] includes, String[] exacts) { |
|
|
|
if (source instanceof EnumerablePropertySource) { |
|
|
|
if (source instanceof EnumerablePropertySource) { |
|
|
|
EnumerablePropertySource<?> enumerable = (EnumerablePropertySource<?>) source; |
|
|
|
processEnumerablePropertySource((EnumerablePropertySource<?>) source, |
|
|
|
if (enumerable.getPropertyNames().length > 0) { |
|
|
|
resolver, includes, exacts); |
|
|
|
for (String propertyName : enumerable.getPropertyNames()) { |
|
|
|
|
|
|
|
if (this.NON_ENUMERABLE_ENUMERABLES.contains(source.getName()) |
|
|
|
|
|
|
|
&& !PatternMatchUtils.simpleMatch(includes, propertyName)) { |
|
|
|
|
|
|
|
continue; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
Object value = source.getProperty(propertyName); |
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
value = resolver.getProperty(propertyName); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
catch (RuntimeException ex) { |
|
|
|
|
|
|
|
// Probably could not resolve placeholders, ignore it here
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (!this.propertyValues.containsKey(propertyName)) { |
|
|
|
|
|
|
|
this.propertyValues.put(propertyName, new PropertyValue( |
|
|
|
|
|
|
|
propertyName, value)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
else if (source instanceof CompositePropertySource) { |
|
|
|
else if (source instanceof CompositePropertySource) { |
|
|
|
CompositePropertySource composite = (CompositePropertySource) source; |
|
|
|
processCompositePropertySource((CompositePropertySource) source, resolver, |
|
|
|
for (PropertySource<?> nested : extractSources(composite)) { |
|
|
|
includes, exacts); |
|
|
|
processPropertySource(nested, resolver, includes, exacts); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
else { |
|
|
|
else { |
|
|
|
// We can only do exact matches for non-enumerable property names, but
|
|
|
|
// We can only do exact matches for non-enumerable property names, but
|
|
|
|
// that's better than nothing...
|
|
|
|
// that's better than nothing...
|
|
|
|
for (String propertyName : exacts) { |
|
|
|
processDefaultPropertySource(source, resolver, includes, exacts); |
|
|
|
Object value; |
|
|
|
} |
|
|
|
value = resolver.getProperty(propertyName); |
|
|
|
} |
|
|
|
if (value != null && !this.propertyValues.containsKey(propertyName)) { |
|
|
|
|
|
|
|
this.propertyValues.put(propertyName, new PropertyValue(propertyName, |
|
|
|
private void processEnumerablePropertySource(EnumerablePropertySource<?> source, |
|
|
|
value)); |
|
|
|
PropertySourcesPropertyResolver resolver, String[] includes, String[] exacts) { |
|
|
|
|
|
|
|
if (source.getPropertyNames().length > 0) { |
|
|
|
|
|
|
|
for (String propertyName : source.getPropertyNames()) { |
|
|
|
|
|
|
|
if (this.NON_ENUMERABLE_ENUMERABLES.contains(source.getName()) |
|
|
|
|
|
|
|
&& !PatternMatchUtils.simpleMatch(includes, propertyName)) { |
|
|
|
continue; |
|
|
|
continue; |
|
|
|
} |
|
|
|
} |
|
|
|
value = source.getProperty(propertyName.toUpperCase()); |
|
|
|
Object value = source.getProperty(propertyName); |
|
|
|
if (value != null && !this.propertyValues.containsKey(propertyName)) { |
|
|
|
try { |
|
|
|
|
|
|
|
value = resolver.getProperty(propertyName); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
catch (RuntimeException ex) { |
|
|
|
|
|
|
|
// Probably could not resolve placeholders, ignore it here
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (!this.propertyValues.containsKey(propertyName)) { |
|
|
|
this.propertyValues.put(propertyName, new PropertyValue(propertyName, |
|
|
|
this.propertyValues.put(propertyName, new PropertyValue(propertyName, |
|
|
|
value)); |
|
|
|
value)); |
|
|
|
continue; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void processCompositePropertySource(CompositePropertySource source, |
|
|
|
|
|
|
|
PropertySourcesPropertyResolver resolver, String[] includes, String[] exacts) { |
|
|
|
|
|
|
|
for (PropertySource<?> nested : extractSources(source)) { |
|
|
|
|
|
|
|
processPropertySource(nested, resolver, includes, exacts); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private Collection<PropertySource<?>> extractSources(CompositePropertySource composite) { |
|
|
|
private Collection<PropertySource<?>> extractSources(CompositePropertySource composite) { |
|
|
|
Field field = ReflectionUtils.findField(CompositePropertySource.class, |
|
|
|
Field field = ReflectionUtils.findField(CompositePropertySource.class, |
|
|
|
"propertySources"); |
|
|
|
"propertySources"); |
|
|
|
@ -141,9 +143,24 @@ public class PropertySourcesPropertyValues implements PropertyValues { |
|
|
|
.get(composite); |
|
|
|
.get(composite); |
|
|
|
return collection; |
|
|
|
return collection; |
|
|
|
} |
|
|
|
} |
|
|
|
catch (Exception e) { |
|
|
|
catch (Exception ex) { |
|
|
|
throw new IllegalStateException( |
|
|
|
throw new IllegalStateException( |
|
|
|
"Cannot extract property sources from composite", e); |
|
|
|
"Cannot extract property sources from composite", ex); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void processDefaultPropertySource(PropertySource<?> source, |
|
|
|
|
|
|
|
PropertySourcesPropertyResolver resolver, String[] includes, String[] exacts) { |
|
|
|
|
|
|
|
for (String propertyName : exacts) { |
|
|
|
|
|
|
|
Object value = resolver.getProperty(propertyName); |
|
|
|
|
|
|
|
if (value == null) { |
|
|
|
|
|
|
|
value = source.getProperty(propertyName.toUpperCase()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (value != null && !this.propertyValues.containsKey(propertyName)) { |
|
|
|
|
|
|
|
this.propertyValues.put(propertyName, new PropertyValue(propertyName, |
|
|
|
|
|
|
|
value)); |
|
|
|
|
|
|
|
continue; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|