Interface PropertyResolver

All Superinterfaces:
ValueResolver<String>
All Known Subinterfaces:
ApplicationContext, ConditionContext<T>, ConfigurableApplicationContext, Environment, PropertyResolverDelegate
All Known Implementing Classes:
MapPropertyResolver, PropertySourcePropertyResolver

public interface PropertyResolver extends ValueResolver<String>
A property resolver is capable of resolving properties from an underlying property source.
Since:
1.0
Author:
Graeme Rocher
  • Method Details

    • containsProperty

      boolean containsProperty(String name)

      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 containsProperties(String) instead.

      Parameters:
      name - The name of the property
      Returns:
      True if it is
    • containsProperties

      boolean containsProperties(String name)
      Whether the given property or any nested properties exist for the key given key within this resolver.
      Parameters:
      name - The name of the property
      Returns:
      True if it is
    • getProperty

      <T> Optional<T> getProperty(String name, ArgumentConversionContext<T> conversionContext)

      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.

      Type Parameters:
      T - The concrete type
      Parameters:
      name - The name
      conversionContext - The conversion context
      Returns:
      An optional containing the property value if it exists
    • getPropertyEntries

      default Collection<String> getPropertyEntries(String name)
      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.
      Parameters:
      name - The name to resolve
      Returns:
      The property entries.
    • getPropertyEntries

      default Collection<String> getPropertyEntries(String name, PropertyCatalog propertyCatalog)
      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).
      Parameters:
      name - The name to resolve
      propertyCatalog - property catalog to use
      Returns:
      The property entries.
      Since:
      4.7.0
    • getProperty

      default <T> Optional<T> getProperty(String name, Argument<T> argument)

      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.

      Type Parameters:
      T - The concrete type
      Parameters:
      name - The name
      argument - The required type
      Returns:
      An optional containing the property value if it exists
    • getProperties

      default Map<String,Object> getProperties(String name)
      Return all the properties under the given key.
      Parameters:
      name - The name
      Returns:
      The properties
    • getProperties

      default Map<String,Object> getProperties(@Nullable String name, @Nullable StringConvention keyFormat)
      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.
      Parameters:
      name - The name
      keyFormat - The key format to use for the keys. Default is kebab-case.
      Returns:
      The properties
    • getProperty

      default <T> Optional<T> getProperty(String name, Class<T> requiredType, ConversionContext context)

      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.

      Type Parameters:
      T - The concrete type
      Parameters:
      name - The name
      requiredType - The required type
      context - The ConversionContext to apply to any conversion
      Returns:
      An optional containing the property value if it exists
    • get

      default <T> Optional<T> get(String name, ArgumentConversionContext<T> conversionContext)
      Description copied from interface: ValueResolver
      Resolve the given property for the given name.
      Specified by:
      get in interface ValueResolver<String>
      Type Parameters:
      T - The concrete type
      Parameters:
      name - The name
      conversionContext - The conversion context
      Returns:
      An optional containing the property value if it exists and is able to be converted
    • getProperty

      default <T> Optional<T> getProperty(String name, Class<T> requiredType)
      Resolve the given property for the given name.
      Type Parameters:
      T - The concrete type
      Parameters:
      name - The name
      requiredType - The required type
      Returns:
      An optional containing the property value if it exists
    • getProperty

      default <T> @Nullable T getProperty(String name, Class<T> requiredType, @Nullable T defaultValue)
      Resolve the given property for the given name.
      Type Parameters:
      T - The concrete type
      Parameters:
      name - The name
      requiredType - The required type
      defaultValue - The default value
      Returns:
      An optional containing the property value if it exists
    • getRequiredProperty

      default <T> T getRequiredProperty(String name, Class<T> requiredType) throws PropertyNotFoundException
      Resolve the given property for the given name.
      Type Parameters:
      T - The concrete type
      Parameters:
      name - The name of the property
      requiredType - The required type
      Returns:
      The value of the property
      Throws:
      PropertyNotFoundException - exception when property does not exist
    • nameOf

      static String nameOf(String... path)
      Builds a property name for the given property path.
      Parameters:
      path - The path
      Returns:
      The property name
    • getPropertyPathMatches

      Collection<List<String>> getPropertyPathMatches(String pathPattern)
      Will return for a given pattern such as foo.*.bar.* and array of arrays containing the variable names that match the pattern.
      Parameters:
      pathPattern - The path pattern
      Returns:
      An array of arrays.
      Since:
      4.0.0