com.holonplatform.core.config

## Interface ConfigPropertyProvider

- All Known Subinterfaces:
    EnvironmentConfigPropertyProvider

      public interface ConfigPropertyProvider

  Base interface to access config properties.
  Since:
    5.0.0

- - ### Method Summary

    All Methods Static Methods Instance Methods Abstract Methods Default Methods
    Modifier and Type | Method and Description
    --- | ---
    `boolean` | `containsProperty(String key)` Return whether the given property key is available, i.e. the property key is present and the value for the given key is not `null`.
    `<T> T` | `getProperty(String key, Class<T> targetType)` Return the property value associated with the given key and try to convert property value to given target type.
    `Stream<String>` | `getPropertyNames()` Returns a Stream of all available property names
    `static ConfigPropertyProvider` | `prefixed(ConfigPropertyProvider provider, String prefix)` Create a ConfigPropertyProvider that filters property names from given concrete `provider`, returning only property names which starts with given `prefix`.
    `static ConfigPropertyProvider` | `using(InputStream propertySource)` Build a `ConfigPropertyProvider` using given `InputStream` as `Properties` property source.
    `static ConfigPropertyProvider` | `using(Map<String,Object> propertyMap)` Build a `ConfigPropertyProvider` using given Map as property source.
    `static ConfigPropertyProvider` | `using(Properties properties)` Build a `ConfigPropertyProvider` using given `Properties` as property source.
    `static ConfigPropertyProvider` | `using(String sourceFileName, ClassLoader classLoader)` Build a `ConfigPropertyProvider` using given `sourceFileName` as property source.
    `static ConfigPropertyProvider` | `using(String sourceFileName, ClassLoader classLoader, boolean lenient)` Build a `ConfigPropertyProvider` using given `sourceFileName` as property source.
    `static ConfigPropertyProvider` | `usingSystemProperties()` Build a `ConfigPropertyProvider` using `System` properties as property source.

- - ### Method Detail

    - #### containsProperty

          boolean containsProperty(String key)

      Return whether the given property key is available, i.e. the property key is present and the value for the given key is not `null`.
      Parameters:
        `key` - Property key (not null)
      Returns:
        `true` if property exists and has not `null` value

    - #### getProperty

          <T> T getProperty(String key,
                            Class<T> targetType)
                     throws IllegalArgumentException

      Return the property value associated with the given key and try to convert property value to given target type.
      Type Parameters:
        `T` - Expected property and result type
      Parameters:
        `key` - the property name to resolve (not null)
        `targetType` - the expected type of the property value
      Returns:
        Property value or `null` if the key cannot be resolved
      Throws:
        `IllegalArgumentException` - If property value cannot be converted to target type

    - #### getPropertyNames

          Stream<String> getPropertyNames()
                                   throws UnsupportedOperationException

      Returns a Stream of all available property names
      Returns:
        Property names stream
      Throws:
        `UnsupportedOperationException` - If this operation is not supported by concrete implementation

    - #### usingSystemProperties

          static ConfigPropertyProvider usingSystemProperties()

      Build a `ConfigPropertyProvider` using `System` properties as property source.
      Returns:
        System properties ConfigPropertyProvider

    - #### using

          static ConfigPropertyProvider using(Map<String,Object> propertyMap)

      Build a `ConfigPropertyProvider` using given Map as property source.
      Parameters:
        `propertyMap` - Property key-value map
      Returns:
        ConfigPropertyProvider with given `propertyMap` as property source.

    - #### using

          static ConfigPropertyProvider using(Properties properties)

      Build a `ConfigPropertyProvider` using given `Properties` as property source.
      Parameters:
        `properties` - Source Properties
      Returns:
        ConfigPropertyProvider with given `properties` as property source.

    - #### using

          static ConfigPropertyProvider using(InputStream propertySource)
                                       throws IOException

      Build a `ConfigPropertyProvider` using given `InputStream` as `Properties` property source.
      Parameters:
        `propertySource` - Source properties input stream
      Returns:
        ConfigPropertyProvider with given `propertySource` as property source.
      Throws:
        `IOException` - Inout stream read error

    - #### using

          static ConfigPropertyProvider using(String sourceFileName,
                                              ClassLoader classLoader,
                                              boolean lenient)
                                       throws IOException

      Build a `ConfigPropertyProvider` using given `sourceFileName` as property source.

      This method uses `ClassLoader.getResourceAsStream(String)` method to load the property stream, using the same conventions to locate the resource to load.

      Parameters:
        `sourceFileName` - Property file name
        `classLoader` - ClassLoader to use. If `null`, the default current classloader is used
        `lenient` - `true` to ignore source loading errors and return a provider with an empty set of properties
      Returns:
        ConfigPropertyProvider with given `sourceFileName` as property source.
      Throws:
        `IOException` - File not found or read error

    - #### using

          static ConfigPropertyProvider using(String sourceFileName,
                                              ClassLoader classLoader)
                                       throws IOException

      Build a `ConfigPropertyProvider` using given `sourceFileName` as property source.

      This method uses `ClassLoader.getResourceAsStream(String)` method to load the property stream, using the same conventions to locate the resource to load.

      Parameters:
        `sourceFileName` - Property file name
        `classLoader` - ClassLoader to use. If `null`, the default current classloader is used
      Returns:
        ConfigPropertyProvider with given `sourceFileName` as property source.
      Throws:
        `IOException` - File not found or read error

    - #### prefixed

          static ConfigPropertyProvider prefixed(ConfigPropertyProvider provider,
                                                 String prefix)

      Create a ConfigPropertyProvider that filters property names from given concrete `provider`, returning only property names which starts with given `prefix`.
      Parameters:
        `provider` - Concrete provider (not null)
        `prefix` - Prefix to use (not null)
      Returns:
        Prefixed property provider

Copyright © 2019 The Holon Platform. All rights reserved.