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
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final ConversionServiceprotected org.slf4j.Loggerstatic final io.micronaut.context.env.DefaultPropertyEntryprotected final PropertyPlaceholderResolverprotected final Map<String,PropertySource> -
Constructor Summary
ConstructorsConstructorDescriptionCreates a new, initially empty,PropertySourcePropertyResolver.PropertySourcePropertyResolver(PropertySource... propertySources) Creates a newPropertySourcePropertyResolverfor the givenPropertySourceinstances.PropertySourcePropertyResolver(ConversionService conversionService) Creates a new, initially empty,PropertySourcePropertyResolverfor the givenConversionService.PropertySourcePropertyResolver(ConversionService conversionService, boolean logEnabled) Creates a new, initially empty,PropertySourcePropertyResolverfor the givenConversionService. -
Method Summary
Modifier and TypeMethodDescriptionaddPropertySource(@Nullable PropertySource propertySource) Add aPropertySourceto this resolver.Add a property source for the given map.voidclose()booleanWhether the given property or any nested properties exist for the key given key within this resolver.booleancontainsProperty(@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.getPropertyEntries(@NonNull String name, PropertyCatalog propertyCatalog) Returns a collection of properties entries under the given key, but .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 voidprocessPropertySource(PropertySource properties, PropertySource.PropertyConvention convention) protected voidSubclasses can override to reset caches.resolveEntriesForKey(String name, boolean allowCreate, @Nullable PropertyCatalog propertyCatalog) resolveSubMap(String name, Map<String, io.micronaut.context.env.DefaultPropertyEntry> entries, ArgumentConversionContext<?> conversionContext) resolveSubMap(String name, Map<String, io.micronaut.context.env.DefaultPropertyEntry> entries, ArgumentConversionContext<?> conversionContext, @Nullable StringConvention keyConvention, MapFormat.MapTransformation transformation) Resolves a submap for the given name and parameters.protected PropertiesresolveSubProperties(String name, Map<String, io.micronaut.context.env.DefaultPropertyEntry> entries, ArgumentConversionContext<?> conversionContext) Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface io.micronaut.core.value.PropertyResolver
get, getProperties, getProperty, getProperty, getProperty, getProperty, getRequiredPropertyMethods inherited from interface io.micronaut.core.value.ValueResolver
get, get, get
-
Field Details
-
NULL_ENTRY
public static final io.micronaut.context.env.DefaultPropertyEntry NULL_ENTRY -
conversionService
-
propertyPlaceholderResolver
-
propertySources
-
catalog
-
rawCatalog
-
nonGenerated
-
log
protected org.slf4j.Logger log
-
-
Constructor Details
-
PropertySourcePropertyResolver
Creates a new, initially empty,PropertySourcePropertyResolverfor the givenConversionService.- Parameters:
conversionService- TheConversionServicelogEnabled- flag to enable or disable logger
-
PropertySourcePropertyResolver
Creates a new, initially empty,PropertySourcePropertyResolverfor the givenConversionService.- Parameters:
conversionService- TheConversionService
-
PropertySourcePropertyResolver
public PropertySourcePropertyResolver()Creates a new, initially empty,PropertySourcePropertyResolver. -
PropertySourcePropertyResolver
Creates a newPropertySourcePropertyResolverfor the givenPropertySourceinstances.- Parameters:
propertySources- ThePropertySourceinstances
-
-
Method Details
-
addPropertySource
public PropertySourcePropertyResolver addPropertySource(@Nullable @Nullable PropertySource propertySource) Add aPropertySourceto this resolver.- Parameters:
propertySource- ThePropertySourceto 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:PropertyResolverWhether 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.barthis method will returnfalsefor:resolver.containsProperty("foo")To check for nested properties using
PropertyResolver.containsProperties(String)instead.- Specified by:
containsPropertyin interfacePropertyResolver- Parameters:
name- The name of the property- Returns:
- True if it is
-
containsProperties
Description copied from interface:PropertyResolverWhether the given property or any nested properties exist for the key given key within this resolver.- Specified by:
containsPropertiesin interfacePropertyResolver- Parameters:
name- The name of the property- Returns:
- True if it is
-
getPropertyEntries
Description copied from interface:PropertyResolverReturns a collection of properties entries under the given key. For example given the following keys:
Callingdatasource.default.url=localhost datasource.another.url=someothergetPropertyEntries(String)with a value ofdatasourcewill result in a collection containingdefaultandother.- Specified by:
getPropertyEntriesin interfacePropertyResolver- Parameters:
name- The name to resolve- Returns:
- The property entries.
-
getPropertyEntries
@NonNull public @NonNull Collection<String> getPropertyEntries(@NonNull @NonNull String name, @NonNull PropertyCatalog propertyCatalog) Description copied from interface:PropertyResolverReturns a collection of properties entries under the given key, but . For example, if you setPropertyCatalog.RAWthen the following keys:
Callingdatasource.MyDs-1.url=localhost datasource.MyDs-2.url=someothergetPropertyEntries(String)with a value ofdatasourcewill result in a collection containingMyDs-1andMyDs-2(without normalization).- Specified by:
getPropertyEntriesin interfacePropertyResolver- Parameters:
name- The name to resolvepropertyCatalog- property catalog to use- Returns:
- The property entries.
-
getPropertyPathMatches
Description copied from interface:PropertyResolverWill return for a given pattern such asfoo.*.bar.*and array of arrays containing the variable names that match the pattern.- Specified by:
getPropertyPathMatchesin interfacePropertyResolver- Parameters:
pathPattern- The path pattern- Returns:
- An array of arrays.
-
getProperties
Description copied from interface:PropertyResolverReturn 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:
getPropertiesin 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:PropertyResolverResolve 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:
getPropertyin 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, io.micronaut.context.env.DefaultPropertyEntry> 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, io.micronaut.context.env.DefaultPropertyEntry> 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, io.micronaut.context.env.DefaultPropertyEntry> 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,io.micronaut.context.env.DefaultPropertyEntry> resolveEntriesForKey(String name, boolean allowCreate, @Nullable @Nullable 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:
closein interfaceAutoCloseable- Throws:
Exception
-