Package io.smallrye.config
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:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static StringSMALLRYE_CONFIG_LOCATIONSstatic StringSMALLRYE_CONFIG_LOG_VALUESstatic StringSMALLRYE_CONFIG_MAPPING_VALIDATE_UNKNOWNstatic StringSMALLRYE_CONFIG_PROFILEstatic StringSMALLRYE_CONFIG_PROFILE_PARENT
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description <T> Tconvert(String value, Class<T> asType)<T> TconvertValue(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 anExceptionfor each of the following:
1.<T> TgetConfigMapping(Class<T> type)<T> TgetConfigMapping(Class<T> type, String prefix)Optional<org.eclipse.microprofile.config.spi.ConfigSource>getConfigSource(String name)Iterable<org.eclipse.microprofile.config.spi.ConfigSource>getConfigSources()Iterable<org.eclipse.microprofile.config.spi.ConfigSource>getConfigSources(Class<?> type)ConfigValuegetConfigValue(String name)<T> Optional<org.eclipse.microprofile.config.spi.Converter<T>>getConverter(Class<T> asType)<T> org.eclipse.microprofile.config.spi.Converter<T>getConverter$$bridge(Class<T> asType)Deprecated.org.eclipse.microprofile.config.spi.ConfigSourcegetDefaultValues()<T,C extends Collection<T>>
Optional<C>getIndexedOptionalValues(String name, org.eclipse.microprofile.config.spi.Converter<T> converter, IntFunction<C> collectionFactory)List<String>getIndexedProperties(String property)List<Integer>getIndexedPropertiesIndexes(String property)<T,C extends Collection<T>>
CgetIndexedValues(String name, org.eclipse.microprofile.config.spi.Converter<T> converter, IntFunction<C> collectionFactory)Iterable<String>getLatestPropertyNames()Provides a way to retrieve an updated list of all property names.Map<String,String>getMapIndexedKeys(String name)Map<String,String>getMapKeys(String name)<T> Optional<T>getOptionalValue(String name, Class<T> aClass)<T> Optional<T>getOptionalValue(String name, org.eclipse.microprofile.config.spi.Converter<T> converter)<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.<K,V,C extends Collection<V>>
Optional<Map<K,C>>getOptionalValues(String name, Class<K> keyClass, Class<V> valueClass, IntFunction<C> collectionFactory)<T> Optional<List<T>>getOptionalValues(String propertyName, Class<T> propertyType)<T,C extends Collection<T>>
Optional<C>getOptionalValues(String name, Class<T> itemClass, IntFunction<C> collectionFactory)<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)<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)<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)<T,C extends Collection<T>>
Optional<C>getOptionalValues(String name, org.eclipse.microprofile.config.spi.Converter<T> converter, IntFunction<C> collectionFactory)List<String>getProfiles()Iterable<String>getPropertyNames()This implementation caches the list of property names collected whenSmallRyeConfigis built viaSmallRyeConfigBuilder.build().StringgetRawValue(String name)Get the raw value of a configuration property.<T> TgetValue(String name, Class<T> aClass)<T> TgetValue(String name, org.eclipse.microprofile.config.spi.Converter<T> converter)This method handles calls from bothConfig.getValue(java.lang.String, java.lang.Class<T>)andConfig.getOptionalValue(java.lang.String, java.lang.Class<T>).<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.<K,V,C extends Collection<V>>
Map<K,C>getValues(String name, Class<K> keyClass, Class<V> valueClass, IntFunction<C> collectionFactory)<T> List<T>getValues(String name, Class<T> propertyType)<T,C extends Collection<T>>
CgetValues(String name, Class<T> itemClass, IntFunction<C> collectionFactory)<K,V>
Map<K,V>getValues(String name, org.eclipse.microprofile.config.spi.Converter<K> keyConverter, org.eclipse.microprofile.config.spi.Converter<V> valueConverter)<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)<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.<T,C extends Collection<T>>
CgetValues(String name, org.eclipse.microprofile.config.spi.Converter<T> converter, IntFunction<C> collectionFactory)booleanisPropertyPresent(String name)Checks if a property is present in theConfiginstance.<T> org.eclipse.microprofile.config.spi.Converter<T>requireConverter(Class<T> asType)<T> Tunwrap(Class<T> type)
-
-
-
Field Detail
-
SMALLRYE_CONFIG_PROFILE
public static final String SMALLRYE_CONFIG_PROFILE
- See Also:
- Constant Field Values
-
SMALLRYE_CONFIG_PROFILE_PARENT
public static final String SMALLRYE_CONFIG_PROFILE_PARENT
- See Also:
- Constant Field Values
-
SMALLRYE_CONFIG_LOCATIONS
public static final String SMALLRYE_CONFIG_LOCATIONS
- See Also:
- Constant Field Values
-
SMALLRYE_CONFIG_MAPPING_VALIDATE_UNKNOWN
public static final String SMALLRYE_CONFIG_MAPPING_VALIDATE_UNKNOWN
- See Also:
- Constant Field Values
-
SMALLRYE_CONFIG_LOG_VALUES
public static final String SMALLRYE_CONFIG_LOG_VALUES
- See Also:
- Constant Field Values
-
-
Method Detail
-
getValues
public <T> List<T> getValues(String name, Class<T> propertyType)
- Specified by:
getValuesin interfaceorg.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)
-
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 typeV- the value type- Parameters:
name- The configuration property namekeyClass- the type into which the keys should be convertedvalueClass- 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 typesNoSuchElementException- 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 namekeyConverter- 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
nullif it could not be found. - Throws:
IllegalArgumentException- if a key or a value cannot be converted to the specified typesNoSuchElementException- 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)
-
getValue
public <T> T getValue(String name, Class<T> aClass)
- Specified by:
getValuein interfaceorg.eclipse.microprofile.config.Config
-
getValue
public <T> T getValue(String name, org.eclipse.microprofile.config.spi.Converter<T> converter)
This method handles calls from bothConfig.getValue(java.lang.String, java.lang.Class<T>)andConfig.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 anExceptionfor each of the following:
1.IllegalArgumentException- if the property cannot be converted by theConverterto 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 theConverterreturnsnull
Calls for converting optional values (Config.getOptionalValue(java.lang.String, java.lang.Class<T>)and "Injecting Optional Values") should only throw anExceptionfor #1 (IllegalArgumentExceptionwhen the property cannot be converted to the specified type).
-
getConfigValue
public ConfigValue getConfigValue(String name)
- Specified by:
getConfigValuein interfaceorg.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 benull)- Returns:
- the raw value, or
nullif no property value was discovered for the given property name
-
getOptionalValue
public <T> Optional<T> getOptionalValue(String name, Class<T> aClass)
- Specified by:
getOptionalValuein interfaceorg.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:
getOptionalValuesin interfaceorg.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 typeV- the value type- Parameters:
name- The configuration property namekeyClass- the type into which the keys should be convertedvalueClass- 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)
-
getPropertyNames
public Iterable<String> getPropertyNames()
This implementation caches the list of property names collected whenSmallRyeConfigis built viaSmallRyeConfigBuilder.build().- Specified by:
getPropertyNamesin interfaceorg.eclipse.microprofile.config.Config- Returns:
- the cached names of all configured keys of the underlying configuration
- See Also:
getLatestPropertyNames()
-
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 bygetPropertyNames().- 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 theConfiginstance.
BecauseConfigSource.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:
getConfigSourcesin interfaceorg.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)
-
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:
getConverterin interfaceorg.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:
unwrapin interfaceorg.eclipse.microprofile.config.Config
-
getDefaultValues
public org.eclipse.microprofile.config.spi.ConfigSource getDefaultValues()
-
-