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_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(String name, String value, 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)ConfigMappingsgetConfigMappings()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.<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)<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> kClass, Class<V> vClass)Return the content of the direct sub properties as the requested type of Map.<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)<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()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> kClass, Class<V> vClass)Return the content of the direct sub properties as the requested type of Map.<T> List<T>getValues(String propertyName, Class<T> propertyType)<T,C extends Collection<T>>
CgetValues(String name, Class<T> itemClass, IntFunction<C> collectionFactory)<T,C extends Collection<T>>
CgetValues(String name, org.eclipse.microprofile.config.spi.Converter<T> converter, IntFunction<C> collectionFactory)<K,V>
Map<K,V>getValuesAsMap(String name, org.eclipse.microprofile.config.spi.Converter<K> keyConverter, org.eclipse.microprofile.config.spi.Converter<V> valueConverter)Return the content of the direct sub properties as the requested type of Map.booleanisPropertyPresent(String name)Checks if a property is present in theConfiginstance.booleanrawValueEquals(String name, String expected)Determine whether the raw value of a configuration property is exactly equal to the expected given value.<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
-
-
Method Detail
-
getValues
public <T> List<T> getValues(String propertyName, 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)
-
getValue
public <T> T getValue(String name, Class<T> aClass)
- Specified by:
getValuein interfaceorg.eclipse.microprofile.config.Config
-
getValues
@Experimental("Extension to retrieve mandatory sub properties as a Map") public <K,V> Map<K,V> getValues(String name, Class<K> kClass, Class<V> vClass)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 namekClass- the type into which the keys should be convertedvClass- 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.
-
getValuesAsMap
public <K,V> Map<K,V> getValuesAsMap(String name, org.eclipse.microprofile.config.spi.Converter<K> keyConverter, org.eclipse.microprofile.config.spi.Converter<V> valueConverter)
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 types
-
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(String name, String value, 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).
-
rawValueEquals
public boolean rawValueEquals(String name, String expected)
Determine whether the raw value of a configuration property is exactly equal to the expected given value.- Parameters:
name- the property name (must not benull)expected- the expected value (may benull)- Returns:
trueif the values are equal,falseotherwise
-
getConfigValue
@Experimental("Extension to the original ConfigSource to allow retrieval of additional metadata on config lookup") 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
-
getOptionalValues
@Experimental("Extension to retrieve non mandatory sub properties as a Map") public <K,V> Optional<Map<K,V>> getOptionalValues(String name, Class<K> kClass, Class<V> vClass)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 namekClass- the type into which the keys should be convertedvClass- 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
-
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)
-
getConfigMappings
public ConfigMappings getConfigMappings()
-
getConfigMapping
@Experimental("ConfigMapping API to group configuration properties") public <T> T getConfigMapping(Class<T> type)
-
getConfigMapping
@Experimental("ConfigMapping API to group configuration properties") public <T> T getConfigMapping(Class<T> type, String prefix)
-
getPropertyNames
public Iterable<String> getPropertyNames()
- Specified by:
getPropertyNamesin interfaceorg.eclipse.microprofile.config.Config
-
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 reliable 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 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
@Experimental("To retrieve a ConfigSource by name") 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
-
-