Class PropertySourcePropertyResolver

java.lang.Object
io.micronaut.context.env.PropertySourcePropertyResolver
All Implemented Interfaces:
PropertyResolver, ValueResolver<String>, AutoCloseable

@Internal 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 Details

    • NULL_ENTRY

      public static final io.micronaut.context.env.DefaultPropertyEntry NULL_ENTRY
    • propertyPlaceholderResolver

      protected final PropertyPlaceholderResolver propertyPlaceholderResolver
  • Constructor Details

  • Method Details

    • diff

      public Map<String,Object> diff(Runnable change)
    • addPropertySource

      public PropertySourcePropertyResolver addPropertySource(@Nullable PropertySource propertySource)
      Add a PropertySource to this resolver.
      Parameters:
      propertySource - The PropertySource to add
      Returns:
      This PropertySourcePropertyResolver
    • addPropertySource

      public PropertySourcePropertyResolver addPropertySource(String name, @Nullable Map<String,? super Object> values)
      Add a property source for the given map.
      Parameters:
      name - The name of the property source
      values - The values
      Returns:
      This environment
    • containsProperty

      public boolean containsProperty(@Nullable String name)
      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 return false for: resolver.containsProperty("foo")

      To check for nested properties using PropertyResolver.containsProperties(String) instead.

      Specified by:
      containsProperty in interface PropertyResolver
      Parameters:
      name - The name of the property
      Returns:
      True if it is
    • containsProperties

      public boolean containsProperties(@Nullable String name)
      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 interface PropertyResolver
      Parameters:
      name - The name of the property
      Returns:
      True if it is
    • getPropertyEntries

      public @NonNull Collection<String> getPropertyEntries(@NonNull String name)
      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
       
      Calling getPropertyEntries(String) with a value of datasource will result in a collection containing default and other.
      Specified by:
      getPropertyEntries in interface PropertyResolver
      Parameters:
      name - The name to resolve
      Returns:
      The property entries.
    • getPropertyEntries

      public @NonNull Collection<String> getPropertyEntries(@NonNull String name, @NonNull PropertyCatalog propertyCatalog)
      Description copied from interface: PropertyResolver
      Returns a collection of properties entries under the given key, but . For example, if you set PropertyCatalog.RAW then the following keys:
       datasource.MyDs-1.url=localhost
       datasource.MyDs-2.url=someother
       
      Calling getPropertyEntries(String) with a value of datasource will result in a collection containing MyDs-1 and MyDs-2 (without normalization).
      Specified by:
      getPropertyEntries in interface PropertyResolver
      Parameters:
      name - The name to resolve
      propertyCatalog - property catalog to use
      Returns:
      The property entries.
    • getPropertyPathMatches

      public Set<List<String>> getPropertyPathMatches(String pathPattern)
      Description copied from interface: PropertyResolver
      Will return for a given pattern such as foo.*.bar.* and array of arrays containing the variable names that match the pattern.
      Specified by:
      getPropertyPathMatches in interface PropertyResolver
      Parameters:
      pathPattern - The path pattern
      Returns:
      An array of arrays.
    • getProperties

      public @NonNull Map<String,Object> getProperties(String name, StringConvention keyFormat)
      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 in StringConvention.RAW.
      Specified by:
      getProperties in interface PropertyResolver
      Parameters:
      name - The name
      keyFormat - The key format to use for the keys. Default is kebab-case.
      Returns:
      The properties
    • getProperty

      public <T> Optional<T> getProperty(@NonNull String name, @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 interface PropertyResolver
      Type Parameters:
      T - The concrete type
      Parameters:
      name - The name
      conversionContext - 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 convention
      transformation - 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 name
      entries - The entries
      conversionContext - 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 name
      entries - The entries
      conversionContext - The conversion context
      Returns:
      The submap
    • resolveSubMap

      protected @NonNull Map<String,Object> 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.
      Parameters:
      name - The name
      entries - The entries
      conversionContext - The conversion context
      keyConvention - The key convention to use
      transformation - The map transformation to apply
      Returns:
      The resulting map
    • processPropertySource

      protected void processPropertySource(PropertySource properties, PropertySource.PropertyConvention convention)
      Parameters:
      properties - The property source
      convention - The property convention
    • resolveEntriesForKey

      protected Map<String,io.micronaut.context.env.DefaultPropertyEntry> resolveEntriesForKey(String name, boolean allowCreate, @Nullable PropertyCatalog propertyCatalog)
      Parameters:
      name - The name
      allowCreate - Whether allows creation
      propertyCatalog - The string convention
      Returns:
      The map with the resolved entries for the name
    • resetCaches

      protected void resetCaches()
      Subclasses can override to reset caches.
    • close

      public void close() throws Exception
      Specified by:
      close in interface AutoCloseable
      Throws:
      Exception