Class EnvironmentConfiguration
- java.lang.Object
-
- io.confound.config.AbstractConfiguration
-
- io.confound.config.BaseConfiguration<java.lang.String>
-
- io.confound.config.AbstractStringConfiguration
-
- io.confound.config.StringMapConfiguration
-
- io.confound.config.env.EnvironmentConfiguration
-
- All Implemented Interfaces:
io.confound.config.Configuration
public class EnvironmentConfiguration extends io.confound.config.StringMapConfiguration
Configuration implementation backed by environment variables.This implementation provides a facility for converting queried configuration keys to match environment variable conventions. Best practices for Confound configuration variables use lowercase or camelCase names with optional dot separators. Environment variables however are traditionally in uppercase with underscore separators.
By default this implementation considers a query for a key
foo.bar
to be a request for the environment variable namedFOO_BAR
. This allows a consistent pattern for key requests while allowing environment variables to follow traditional naming conventions.- Author:
- Garret Wilson
- See Also:
System.getenv()
-
-
Constructor Summary
Constructors Constructor Description EnvironmentConfiguration()
System environment constructor.EnvironmentConfiguration(boolean normalNames)
System environment constructor with normal names option.EnvironmentConfiguration(java.util.Map<java.lang.String,java.lang.String> env)
Environment map constructor.EnvironmentConfiguration(java.util.Map<java.lang.String,java.lang.String> env, boolean normalNames)
Environment map constructor with normal names option.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
isNormalNames()
Indicates whether environment variables use uppercase/underscore (e.g.protected java.lang.String
normalizeKey(java.lang.String key)
This version normalizes requested keys by replacing'.'
with'_'
and converting the key to uppercase, but only ifisNormalNames()
is enabled.-
Methods inherited from class io.confound.config.StringMapConfiguration
findConfigurationValueImpl, hasConfigurationValueImpl
-
Methods inherited from class io.confound.config.AbstractStringConfiguration
dereferenceString, findBoolean, findConfigurationValue, findDouble, findInt, findLong, findObject, findPath, findString, findUri
-
Methods inherited from class io.confound.config.BaseConfiguration
convertValue, hasConfigurationValue
-
-
-
-
Constructor Detail
-
EnvironmentConfiguration
public EnvironmentConfiguration()
System environment constructor.Requested keys will be normalized to match environment variable naming conventions.
- Throws:
java.lang.NullPointerException
- if the given environment map isnull
.java.lang.SecurityException
- If a security manager exists and it doesn't allow access to environment variables.- See Also:
System.getenv()
-
EnvironmentConfiguration
public EnvironmentConfiguration(boolean normalNames)
System environment constructor with normal names option.- Parameters:
normalNames
-true
if requested keys such asfoo.bar
should be normalized to match configuration keys using environment variable naming convention such asFOO_BAR
.- Throws:
java.lang.NullPointerException
- if the given environment map isnull
.java.lang.SecurityException
- If a security manager exists and it doesn't allow access to environment variables.- See Also:
System.getenv()
-
EnvironmentConfiguration
public EnvironmentConfiguration(@Nonnull java.util.Map<java.lang.String,java.lang.String> env)
Environment map constructor.Requested keys will be normalized to match environment variable naming conventions.
- Parameters:
env
- The map representing the environment.- Throws:
java.lang.NullPointerException
- if the given environment map isnull
.
-
EnvironmentConfiguration
public EnvironmentConfiguration(@Nonnull java.util.Map<java.lang.String,java.lang.String> env, boolean normalNames)
Environment map constructor with normal names option.- Parameters:
env
- The map representing the environment.normalNames
-true
if requested keys such asfoo.bar
should be normalized to match configuration keys using environment variable naming convention such asFOO_BAR
.- Throws:
java.lang.NullPointerException
- if the given environment map isnull
.
-
-
Method Detail
-
isNormalNames
public boolean isNormalNames()
Indicates whether environment variables use uppercase/underscore (e.g.FOO_BAR
) conventions, normalizing requested keys (e.g.foo.bar
). If this is set tofalse
, environment variables will only be retrieved if their names exactly match the requested keys.- Returns:
true
if requested configuration keys will be normalized to match environment variable naming conventions.
-
normalizeKey
protected java.lang.String normalizeKey(java.lang.String key)
This version normalizes requested keys by replacing'.'
with'_'
and converting the key to uppercase, but only ifisNormalNames()
is enabled.- Overrides:
normalizeKey
in classio.confound.config.BaseConfiguration<java.lang.String>
- See Also:
isNormalNames()
,Configuration.KEY_SEGMENT_SEPARATOR
-
-