Class SmallRyeConfig

java.lang.Object
io.smallrye.config.SmallRyeConfig
All Implemented Interfaces:
Serializable, org.eclipse.microprofile.config.Config

public class SmallRyeConfig extends Object implements org.eclipse.microprofile.config.Config, Serializable
Author:
Jeff Mesnil (c) 2017 Red Hat inc.
See Also:
  • Field Details

  • Method Details

    • getValues

      public <T> List<T> getValues(String name, Class<T> propertyType)
      Specified by:
      getValues in interface org.eclipse.microprofile.config.Config
    • getValues

      public <T, C extends Collection<T>> C getValues(String name, Class<T> itemClass, IntFunction<C> collectionFactory)
    • getValues

      public <T, C extends Collection<T>> C getValues(String name, org.eclipse.microprofile.config.spi.Converter<T> converter, IntFunction<C> collectionFactory)
    • getIndexedValues

      public <T, C extends Collection<T>> C getIndexedValues(String name, org.eclipse.microprofile.config.spi.Converter<T> converter, IntFunction<C> collectionFactory)
    • getIndexedProperties

      public List<String> getIndexedProperties(String property)
    • getIndexedPropertiesIndexes

      public List<Integer> getIndexedPropertiesIndexes(String property)
    • getValues

      public <K, V> Map<K,V> getValues(String name, Class<K> keyClass, Class<V> valueClass)
      Return the content of the direct sub properties as the requested type of Map.
      Type Parameters:
      K - the key type
      V - the value type
      Parameters:
      name - The configuration property name
      keyClass - the type into which the keys should be converted
      valueClass - the type into which the values should be converted
      Returns:
      the resolved property value as an instance of the requested Map (not null)
      Throws:
      IllegalArgumentException - if a key or a value cannot be converted to the specified types
      NoSuchElementException - if no direct sub properties could be found.
    • getValues

      public <K, V> Map<K,V> getValues(String name, org.eclipse.microprofile.config.spi.Converter<K> keyConverter, org.eclipse.microprofile.config.spi.Converter<V> valueConverter)
    • getValues

      public <K, V> Map<K,V> getValues(String name, org.eclipse.microprofile.config.spi.Converter<K> keyConverter, org.eclipse.microprofile.config.spi.Converter<V> valueConverter, IntFunction<Map<K,V>> mapFactory)
      Return the content of the direct sub properties as the requested type of Map.
      Type Parameters:
      K - The type of the keys.
      V - The type of the values.
      Parameters:
      name - The configuration property name
      keyConverter - The converter to use for the keys.
      valueConverter - The converter to use for the values.
      Returns:
      the resolved property value as an instance of the requested Map or null if it could not be found.
      Throws:
      IllegalArgumentException - if a key or a value cannot be converted to the specified types
      NoSuchElementException - if no direct sub properties could be found.
    • getValues

      public <K, V, C extends Collection<V>> Map<K,C> getValues(String name, Class<K> keyClass, Class<V> valueClass, IntFunction<C> collectionFactory)
    • getValues

      public <K, V, C extends Collection<V>> Map<K,C> getValues(String name, org.eclipse.microprofile.config.spi.Converter<K> keyConverter, org.eclipse.microprofile.config.spi.Converter<V> valueConverter, IntFunction<Map<K,C>> mapFactory, IntFunction<C> collectionFactory)
    • getMapKeys

      public Map<String,String> getMapKeys(String name)
    • getMapIndexedKeys

      public Map<String,String> getMapIndexedKeys(String name)
    • getValue

      public <T> T getValue(String name, Class<T> propertyType)
      Specified by:
      getValue in interface org.eclipse.microprofile.config.Config
    • getValue

      public <T> T getValue(String name, org.eclipse.microprofile.config.spi.Converter<T> converter)
      This method handles calls from both Config.getValue(java.lang.String, java.lang.Class<T>) and Config.getOptionalValue(java.lang.String, java.lang.Class<T>).
    • convertValue

      public <T> T convertValue(ConfigValue configValue, org.eclipse.microprofile.config.spi.Converter<T> converter)
      This method handles converting values for both CDI injections and programatical calls.

      Calls for converting non-optional values (Config.getValue(java.lang.String, java.lang.Class<T>) and "Injecting Native Values") should throw an Exception for each of the following:
      1. IllegalArgumentException - if the property cannot be converted by the Converter to the specified type
      2. NoSuchElementException - if the property is not defined
      3. NoSuchElementException - if the property is defined as an empty string
      4. NoSuchElementException - if the Converter returns null

      Calls for converting optional values (Config.getOptionalValue(java.lang.String, java.lang.Class<T>) and "Injecting Optional Values") should only throw an Exception for #1 (IllegalArgumentException when the property cannot be converted to the specified type).
    • getConfigValue

      public ConfigValue getConfigValue(String name)
      Specified by:
      getConfigValue in interface org.eclipse.microprofile.config.Config
    • getRawValue

      public String getRawValue(String name)
      Get the raw value of a configuration property.
      Parameters:
      name - the property name (must not be null)
      Returns:
      the raw value, or null if no property value was discovered for the given property name
    • getOptionalValue

      public <T> Optional<T> getOptionalValue(String name, Class<T> aClass)
      Specified by:
      getOptionalValue in interface org.eclipse.microprofile.config.Config
    • getOptionalValue

      public <T> Optional<T> getOptionalValue(String name, org.eclipse.microprofile.config.spi.Converter<T> converter)
    • getOptionalValues

      public <T> Optional<List<T>> getOptionalValues(String propertyName, Class<T> propertyType)
      Specified by:
      getOptionalValues in interface org.eclipse.microprofile.config.Config
    • getOptionalValues

      public <T, C extends Collection<T>> Optional<C> getOptionalValues(String name, Class<T> itemClass, IntFunction<C> collectionFactory)
    • getOptionalValues

      public <T, C extends Collection<T>> Optional<C> getOptionalValues(String name, org.eclipse.microprofile.config.spi.Converter<T> converter, IntFunction<C> collectionFactory)
    • getIndexedOptionalValues

      public <T, C extends Collection<T>> Optional<C> getIndexedOptionalValues(String name, org.eclipse.microprofile.config.spi.Converter<T> converter, IntFunction<C> collectionFactory)
    • getOptionalValues

      public <K, V> Optional<Map<K,V>> getOptionalValues(String name, Class<K> keyClass, Class<V> valueClass)
      Return the content of the direct sub properties as the requested type of Map.
      Type Parameters:
      K - the key type
      V - the value type
      Parameters:
      name - The configuration property name
      keyClass - the type into which the keys should be converted
      valueClass - the type into which the values should be converted
      Returns:
      the resolved property value as an instance of the requested Map (not null)
      Throws:
      IllegalArgumentException - if a key or a value cannot be converted to the specified types
    • getOptionalValues

      public <K, V> Optional<Map<K,V>> getOptionalValues(String name, org.eclipse.microprofile.config.spi.Converter<K> keyConverter, org.eclipse.microprofile.config.spi.Converter<V> valueConverter)
    • getOptionalValues

      public <K, V> Optional<Map<K,V>> getOptionalValues(String name, org.eclipse.microprofile.config.spi.Converter<K> keyConverter, org.eclipse.microprofile.config.spi.Converter<V> valueConverter, IntFunction<Map<K,V>> mapFactory)
    • getOptionalValues

      public <K, V, C extends Collection<V>> Optional<Map<K,C>> getOptionalValues(String name, Class<K> keyClass, Class<V> valueClass, IntFunction<C> collectionFactory)
    • getOptionalValues

      public <K, V, C extends Collection<V>> Optional<Map<K,C>> getOptionalValues(String name, org.eclipse.microprofile.config.spi.Converter<K> keyConverter, org.eclipse.microprofile.config.spi.Converter<V> valueConverter, IntFunction<Map<K,C>> mapFactory, IntFunction<C> collectionFactory)
    • getConfigMapping

      public <T> T getConfigMapping(Class<T> type)
    • getConfigMapping

      public <T> T getConfigMapping(Class<T> type, String prefix)
    • getPropertyNames

      public Iterable<String> getPropertyNames()
      This implementation caches the list of property names collected when SmallRyeConfig is built via SmallRyeConfigBuilder.build().
      Specified by:
      getPropertyNames in interface org.eclipse.microprofile.config.Config
      Returns:
      the cached names of all configured keys of the underlying configuration
      See Also:
    • getLatestPropertyNames

      @Experimental("Retrieve an updated list of all configuration property names") public Iterable<String> getLatestPropertyNames()
      Provides a way to retrieve an updated list of all property names. The updated list replaces the cached list returned by getPropertyNames().
      Returns:
      the names of all configured keys of the underlying configuration
    • isPropertyPresent

      @Experimental("Check if a property is present") public boolean isPropertyPresent(String name)
      Checks if a property is present in the Config instance.
      Because ConfigSource.getPropertyNames() may not include all available properties, it is not possible to reliably determine if the property is present in the properties list. The property needs to be retrieved to make sure it exists. The lookup is done without expression expansion, because the expansion value may not be available, and it is not relevant for the final check.
      Parameters:
      name - the property name.
      Returns:
      true if the property is present or false otherwise.
    • getConfigSources

      public Iterable<org.eclipse.microprofile.config.spi.ConfigSource> getConfigSources()
      Specified by:
      getConfigSources in interface org.eclipse.microprofile.config.Config
    • getConfigSources

      public Iterable<org.eclipse.microprofile.config.spi.ConfigSource> getConfigSources(Class<?> type)
    • getConfigSource

      public Optional<org.eclipse.microprofile.config.spi.ConfigSource> getConfigSource(String name)
    • convert

      public <T> T convert(String value, Class<T> asType)
    • getConverter$$bridge

      @Deprecated public <T> org.eclipse.microprofile.config.spi.Converter<T> getConverter$$bridge(Class<T> asType)
      Deprecated.
    • getConverter

      public <T> Optional<org.eclipse.microprofile.config.spi.Converter<T>> getConverter(Class<T> asType)
      Specified by:
      getConverter in interface org.eclipse.microprofile.config.Config
    • requireConverter

      public <T> org.eclipse.microprofile.config.spi.Converter<T> requireConverter(Class<T> asType)
    • unwrap

      public <T> T unwrap(Class<T> type)
      Specified by:
      unwrap in interface org.eclipse.microprofile.config.Config
    • getProfiles

      public List<String> getProfiles()