Package io.micronaut.context.env
Class PropertySourcePropertyResolver
java.lang.Object
io.micronaut.context.env.PropertySourcePropertyResolver
- All Implemented Interfaces:
PropertyResolver
,ValueResolver<String>
,AutoCloseable
- Direct Known Subclasses:
DefaultEnvironment
public class PropertySourcePropertyResolver
extends Object
implements PropertyResolver, AutoCloseable
A PropertyResolver
that resolves from one or many PropertySource
instances.
- Since:
- 1.0
- Author:
- Graeme Rocher
-
Nested Class Summary
Modifier and TypeClassDescriptionprotected static enum
The property catalog to use. -
Field Summary
Modifier and TypeFieldDescriptionprotected final ConversionService
protected org.slf4j.Logger
protected final PropertyPlaceholderResolver
protected final Map<String,
PropertySource> -
Constructor Summary
ConstructorDescriptionCreates a new, initially empty,PropertySourcePropertyResolver
.PropertySourcePropertyResolver
(PropertySource... propertySources) Creates a newPropertySourcePropertyResolver
for the givenPropertySource
instances.PropertySourcePropertyResolver
(ConversionService conversionService) Creates a new, initially empty,PropertySourcePropertyResolver
for the givenConversionService
.PropertySourcePropertyResolver
(ConversionService conversionService, boolean logEnabled) Creates a new, initially empty,PropertySourcePropertyResolver
for the givenConversionService
. -
Method Summary
Modifier and TypeMethodDescriptionaddPropertySource
(@Nullable PropertySource propertySource) Add aPropertySource
to this resolver.Add a property source for the given map.void
close()
boolean
Whether the given property or any nested properties exist for the key given key within this resolver.boolean
containsProperty
(@Nullable String name) Whether the given property is contained within this resolver.getAllProperties
(StringConvention keyConvention, MapFormat.MapTransformation transformation) Returns a combined Map of all properties in the catalog.getProperties
(String name, StringConvention keyFormat) Return all the properties under the given key.<T> Optional<T>
getProperty
(@NonNull String name, @NonNull ArgumentConversionContext<T> conversionContext) Resolve the given property for the given name, type and generic type arguments.getPropertyEntries
(@NonNull String name) Returns a collection of properties entries under the given key.getPropertyPathMatches
(String pathPattern) Will return for a given pattern such asfoo.*.bar.*
and array of arrays containing the variable names that match the pattern.protected void
processPropertySource
(PropertySource properties, PropertySource.PropertyConvention convention) protected void
Subclasses can override to reset caches.resolveEntriesForKey
(String name, boolean allowCreate, @Nullable PropertySourcePropertyResolver.PropertyCatalog propertyCatalog) resolveSubMap
(String name, Map<String, Object> entries, ArgumentConversionContext<?> conversionContext) resolveSubMap
(String name, Map<String, Object> entries, ArgumentConversionContext<?> conversionContext, @Nullable StringConvention keyConvention, MapFormat.MapTransformation transformation) Resolves a submap for the given name and parameters.protected Properties
resolveSubProperties
(String name, Map<String, Object> entries, ArgumentConversionContext<?> conversionContext) Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface io.micronaut.core.value.PropertyResolver
get, getProperties, getProperty, getProperty, getProperty, getProperty, getRequiredProperty
Methods inherited from interface io.micronaut.core.value.ValueResolver
get, get, get
-
Field Details
-
conversionService
-
propertyPlaceholderResolver
-
propertySources
-
catalog
-
rawCatalog
-
nonGenerated
-
log
protected org.slf4j.Logger log
-
-
Constructor Details
-
PropertySourcePropertyResolver
Creates a new, initially empty,PropertySourcePropertyResolver
for the givenConversionService
.- Parameters:
conversionService
- TheConversionService
logEnabled
- flag to enable or disable logger
-
PropertySourcePropertyResolver
Creates a new, initially empty,PropertySourcePropertyResolver
for the givenConversionService
.- Parameters:
conversionService
- TheConversionService
-
PropertySourcePropertyResolver
public PropertySourcePropertyResolver()Creates a new, initially empty,PropertySourcePropertyResolver
. -
PropertySourcePropertyResolver
Creates a newPropertySourcePropertyResolver
for the givenPropertySource
instances.- Parameters:
propertySources
- ThePropertySource
instances
-
-
Method Details
-
addPropertySource
public PropertySourcePropertyResolver addPropertySource(@Nullable @Nullable PropertySource propertySource) Add aPropertySource
to this resolver.- Parameters:
propertySource
- ThePropertySource
to add- Returns:
- This
PropertySourcePropertyResolver
-
addPropertySource
public PropertySourcePropertyResolver addPropertySource(String name, @Nullable @Nullable Map<String, ? super Object> values) Add a property source for the given map.- Parameters:
name
- The name of the property sourcevalues
- The values- Returns:
- This environment
-
containsProperty
Description copied from interface: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 returnfalse
for:resolver.containsProperty("foo")
To check for nested properties using
PropertyResolver.containsProperties(String)
instead.- Specified by:
containsProperty
in interfacePropertyResolver
- Parameters:
name
- The name of the property- Returns:
- True if it is
-
containsProperties
Description copied from interface:PropertyResolver
Whether the given property or any nested properties exist for the key given key within this resolver.- Specified by:
containsProperties
in interfacePropertyResolver
- Parameters:
name
- The name of the property- Returns:
- True if it is
-
getPropertyEntries
Description copied from interface:PropertyResolver
Returns a collection of properties entries under the given key. For example given the following keys:datasource.default.url=localhost datasource.another.url=someother
getPropertyEntries(String)
with a value ofdatasource
will result in a collection containingdefault
andother
.- Specified by:
getPropertyEntries
in interfacePropertyResolver
- Parameters:
name
- The name to resolve- Returns:
- The property entries.
-
getPropertyPathMatches
Description copied from interface:PropertyResolver
Will return for a given pattern such asfoo.*.bar.*
and array of arrays containing the variable names that match the pattern.- Specified by:
getPropertyPathMatches
in interfacePropertyResolver
- Parameters:
pathPattern
- The path pattern- Returns:
- An array of arrays.
-
getProperties
Description copied from interface:PropertyResolver
Return all the properties under the given key. By default, Micronaut stores keys in keb-case, such that normalized lookups are more efficient. You can obtain the raw key values by passing inStringConvention.RAW
.- Specified by:
getProperties
in interfacePropertyResolver
- Parameters:
name
- The namekeyFormat
- The key format to use for the keys. Default is kebab-case.- Returns:
- The properties
-
getProperty
public <T> Optional<T> getProperty(@NonNull @NonNull String name, @NonNull @NonNull ArgumentConversionContext<T> conversionContext) Description copied from interface: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.
- Specified by:
getProperty
in interfacePropertyResolver
- Type Parameters:
T
- The concrete type- Parameters:
name
- The nameconversionContext
- The conversion context- Returns:
- An optional containing the property value if it exists
-
getAllProperties
public Map<String,Object> getAllProperties(StringConvention keyConvention, MapFormat.MapTransformation transformation) Returns a combined Map of all properties in the catalog.- Parameters:
keyConvention
- The map key conventiontransformation
- The map format- Returns:
- Map of all properties
-
resolveSubProperties
protected Properties resolveSubProperties(String name, Map<String, Object> entries, ArgumentConversionContext<?> conversionContext) - Parameters:
name
- The property nameentries
- The entriesconversionContext
- The conversion context- Returns:
- The subproperties
-
resolveSubMap
protected Map<String,Object> resolveSubMap(String name, Map<String, Object> entries, ArgumentConversionContext<?> conversionContext) - Parameters:
name
- The property nameentries
- The entriesconversionContext
- The conversion context- Returns:
- The submap
-
resolveSubMap
@NonNull protected @NonNull Map<String,Object> resolveSubMap(String name, Map<String, Object> entries, ArgumentConversionContext<?> conversionContext, @Nullable @Nullable StringConvention keyConvention, MapFormat.MapTransformation transformation) Resolves a submap for the given name and parameters.- Parameters:
name
- The nameentries
- The entriesconversionContext
- The conversion contextkeyConvention
- The key convention to usetransformation
- The map transformation to apply- Returns:
- The resulting map
-
processPropertySource
protected void processPropertySource(PropertySource properties, PropertySource.PropertyConvention convention) - Parameters:
properties
- The property sourceconvention
- The property convention
-
resolveEntriesForKey
protected Map<String,Object> resolveEntriesForKey(String name, boolean allowCreate, @Nullable @Nullable PropertySourcePropertyResolver.PropertyCatalog propertyCatalog) - Parameters:
name
- The nameallowCreate
- Whether allows creationpropertyCatalog
- The string convention- Returns:
- The map with the resolved entries for the name
-
resetCaches
protected void resetCaches()Subclasses can override to reset caches. -
close
- Specified by:
close
in interfaceAutoCloseable
- Throws:
Exception
-