public class PropertySourcePropertyResolver extends java.lang.Object implements PropertyResolver
A PropertyResolver
that resolves from one or many PropertySource
instances.
Modifier and Type | Class and Description |
---|---|
protected static class |
PropertySourcePropertyResolver.PropertyCatalog
The property catalog to use.
|
Modifier and Type | Field and Description |
---|---|
protected java.util.Map<java.lang.String,java.lang.Object>[] |
catalog |
protected ConversionService<?> |
conversionService |
protected java.util.Map<java.lang.String,java.lang.Object>[] |
nonGenerated |
protected PropertyPlaceholderResolver |
propertyPlaceholderResolver |
protected java.util.Map<java.lang.String,PropertySource> |
propertySources |
protected java.util.Map<java.lang.String,java.lang.Object>[] |
rawCatalog |
Constructor and Description |
---|
PropertySourcePropertyResolver()
Creates a new, initially empty,
PropertySourcePropertyResolver . |
PropertySourcePropertyResolver(ConversionService<?> conversionService)
Creates a new, initially empty,
PropertySourcePropertyResolver for the given ConversionService . |
PropertySourcePropertyResolver(PropertySource... propertySources)
Creates a new
PropertySourcePropertyResolver for the given PropertySource instances. |
Modifier and Type | Method and Description |
---|---|
PropertySourcePropertyResolver |
addPropertySource(PropertySource propertySource)
Add a
PropertySource to this resolver. |
PropertySourcePropertyResolver |
addPropertySource(java.lang.String name,
java.util.Map<java.lang.String,? super java.lang.Object> values)
Add a property source for the given map.
|
boolean |
containsProperties(java.lang.String name)
Whether the given property or any nested properties exist for the key given key within this resolver.
|
boolean |
containsProperty(java.lang.String name)
Whether the given property is contained within this resolver.
|
java.util.Map<java.lang.String,java.lang.Object> |
getAllProperties(StringConvention keyConvention,
MapFormat.MapTransformation transformation)
Returns a combined Map of all properties in the catalog.
|
java.util.Map<java.lang.String,java.lang.Object> |
getProperties(java.lang.String name,
StringConvention keyFormat)
Return all the properties under the given key.
|
<T> java.util.Optional<T> |
getProperty(java.lang.String name,
ArgumentConversionContext<T> conversionContext)
Resolve the given property for the given name, type and generic type arguments.
|
java.util.Collection<java.lang.String> |
getPropertyEntries(java.lang.String name)
Returns a collection of properties entries under the given key.
|
protected void |
processPropertySource(PropertySource properties,
PropertySource.PropertyConvention convention) |
protected void |
resetCaches()
Subclasses can override to reset caches.
|
protected java.util.Map<java.lang.String,java.lang.Object> |
resolveEntriesForKey(java.lang.String name,
boolean allowCreate) |
protected java.util.Map<java.lang.String,java.lang.Object> |
resolveEntriesForKey(java.lang.String name,
boolean allowCreate,
PropertySourcePropertyResolver.PropertyCatalog propertyCatalog) |
protected java.util.Map<java.lang.String,java.lang.Object> |
resolveSubMap(java.lang.String name,
java.util.Map<java.lang.String,java.lang.Object> entries,
ArgumentConversionContext<?> conversionContext) |
protected java.util.Map<java.lang.String,java.lang.Object> |
resolveSubMap(java.lang.String name,
java.util.Map<java.lang.String,java.lang.Object> entries,
ArgumentConversionContext<?> conversionContext,
StringConvention keyConvention,
MapFormat.MapTransformation transformation)
Resolves a submap for the given name and parameters.
|
protected java.util.Properties |
resolveSubProperties(java.lang.String name,
java.util.Map<java.lang.String,java.lang.Object> entries,
ArgumentConversionContext<?> conversionContext) |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
get, getProperties, getProperty, getProperty, getProperty, getProperty, getRequiredProperty, nameOf
get, get, get
protected final ConversionService<?> conversionService
protected final PropertyPlaceholderResolver propertyPlaceholderResolver
protected final java.util.Map<java.lang.String,PropertySource> propertySources
protected final java.util.Map<java.lang.String,java.lang.Object>[] catalog
protected final java.util.Map<java.lang.String,java.lang.Object>[] rawCatalog
protected final java.util.Map<java.lang.String,java.lang.Object>[] nonGenerated
public PropertySourcePropertyResolver(ConversionService<?> conversionService)
PropertySourcePropertyResolver
for the given ConversionService
.conversionService
- The ConversionService
public PropertySourcePropertyResolver()
PropertySourcePropertyResolver
.public PropertySourcePropertyResolver(PropertySource... propertySources)
PropertySourcePropertyResolver
for the given PropertySource
instances.propertySources
- The PropertySource
instancespublic PropertySourcePropertyResolver addPropertySource(@Nullable PropertySource propertySource)
PropertySource
to this resolver.propertySource
- The PropertySource
to addPropertySourcePropertyResolver
public PropertySourcePropertyResolver addPropertySource(java.lang.String name, @Nullable java.util.Map<java.lang.String,? super java.lang.Object> values)
name
- The name of the property sourcevalues
- The valuespublic boolean containsProperty(@Nullable java.lang.String name)
PropertyResolver
Whether the given property is contained within this resolver.
Note that this method will return false for nested properties. In other words given a key of foo.bar this method will
return false for: resolver.containsProperty("foo")
To check for nested properties using PropertyResolver.containsProperties(String)
instead.
containsProperty
in interface PropertyResolver
name
- The name of the propertypublic boolean containsProperties(@Nullable java.lang.String name)
PropertyResolver
containsProperties
in interface PropertyResolver
name
- The name of the property@NonNull public java.util.Collection<java.lang.String> getPropertyEntries(@NonNull java.lang.String name)
PropertyResolver
datasource.default.url=localhost
datasource.another.url=someother
Calling getPropertyEntries(String)
with a value of datasource
will result in a collection
containing default
and other
.getPropertyEntries
in interface PropertyResolver
name
- The name to resolve@NonNull public java.util.Map<java.lang.String,java.lang.Object> getProperties(java.lang.String name, StringConvention keyFormat)
PropertyResolver
StringConvention.RAW
.getProperties
in interface PropertyResolver
name
- The namekeyFormat
- The key format to use for the keys. Default is kebab-case.public <T> java.util.Optional<T> getProperty(@NonNull java.lang.String name, @NonNull ArgumentConversionContext<T> conversionContext)
PropertyResolver
Resolve the given property for the given name, type and generic type arguments.
Implementers can choose to implement more intelligent type conversion by analyzing the typeArgument.
getProperty
in interface PropertyResolver
T
- The concrete typename
- The nameconversionContext
- The conversion contextpublic java.util.Map<java.lang.String,java.lang.Object> getAllProperties(StringConvention keyConvention, MapFormat.MapTransformation transformation)
keyConvention
- The map key conventiontransformation
- The map formatprotected java.util.Properties resolveSubProperties(java.lang.String name, java.util.Map<java.lang.String,java.lang.Object> entries, ArgumentConversionContext<?> conversionContext)
name
- The property nameentries
- The entriesconversionContext
- The conversion contextprotected java.util.Map<java.lang.String,java.lang.Object> resolveSubMap(java.lang.String name, java.util.Map<java.lang.String,java.lang.Object> entries, ArgumentConversionContext<?> conversionContext)
name
- The property nameentries
- The entriesconversionContext
- The conversion context@NonNull protected java.util.Map<java.lang.String,java.lang.Object> resolveSubMap(java.lang.String name, java.util.Map<java.lang.String,java.lang.Object> entries, ArgumentConversionContext<?> conversionContext, @Nullable StringConvention keyConvention, MapFormat.MapTransformation transformation)
name
- The nameentries
- The entriesconversionContext
- The conversion contextkeyConvention
- The key convention to usetransformation
- The map transformation to applyprotected void processPropertySource(PropertySource properties, PropertySource.PropertyConvention convention)
properties
- The property sourceconvention
- The property conventionprotected java.util.Map<java.lang.String,java.lang.Object> resolveEntriesForKey(java.lang.String name, boolean allowCreate)
name
- The nameallowCreate
- Whether allows creationprotected java.util.Map<java.lang.String,java.lang.Object> resolveEntriesForKey(java.lang.String name, boolean allowCreate, @Nullable PropertySourcePropertyResolver.PropertyCatalog propertyCatalog)
name
- The nameallowCreate
- Whether allows creationpropertyCatalog
- The string conventionprotected void resetCaches()