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
,io.confound.config.Parameters
public class EnvironmentConfiguration extends io.confound.config.StringMapConfiguration
Configuration implementation backed by environment variables.This implementation provides a facility for converting queried parameter 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(boolean normalNames, io.confound.config.Configuration parentConfiguration)
Parent configuration with system environment constructor and normal names option.EnvironmentConfiguration(io.confound.config.Configuration parentConfiguration)
Parent configuration with system environment constructor.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.EnvironmentConfiguration(java.util.Map<java.lang.String,java.lang.String> env, boolean normalNames, io.confound.config.Configuration parentConfiguration)
Parent configuration and environment map constructor and normal names option.EnvironmentConfiguration(java.util.Map<java.lang.String,java.lang.String> env, io.confound.config.Configuration parentConfiguration)
Parent configuration and environment map constructor.
-
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
findParameterImpl, hasParameterImpl
-
Methods inherited from class io.confound.config.AbstractStringConfiguration
dereferenceString, findParameter, getOptionalBoolean, getOptionalDouble, getOptionalInt, getOptionalLong, getOptionalPath, getOptionalString, getOptionalUri
-
Methods inherited from class io.confound.config.BaseConfiguration
getOptionalParameter, hasParameter
-
-
-
-
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(@Nullable io.confound.config.Configuration parentConfiguration)
Parent configuration with system environment constructor.Requested keys will be normalized to match environment variable naming conventions.
- Parameters:
parentConfiguration
- The parent configuration to use for fallback lookup, ornull
if there is no parent configuration.- Throws:
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 parameters 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(boolean normalNames, @Nullable io.confound.config.Configuration parentConfiguration)
Parent configuration with system environment constructor and normal names option.- Parameters:
normalNames
-true
if requested keys such asfoo.bar
should be normalized to match parameters using environment variable naming convention such asFOO_BAR
.parentConfiguration
- The parent configuration to use for fallback lookup, ornull
if there is no parent configuration.- Throws:
java.lang.NullPointerException
- if the given parent configuration and/or 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, @Nullable io.confound.config.Configuration parentConfiguration)
Parent configuration and environment map constructor.Requested keys will be normalized to match environment variable naming conventions.
- Parameters:
env
- The map representing the environment.parentConfiguration
- The parent configuration to use for fallback lookup, ornull
if there is no parent configuration.- 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 parameters using environment variable naming convention such asFOO_BAR
.- 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, @Nullable io.confound.config.Configuration parentConfiguration)
Parent configuration and environment map constructor and normal names option.- Parameters:
env
- The map representing the environment.normalNames
-true
if requested keys such asfoo.bar
should be normalized to match parameters using environment variable naming convention such asFOO_BAR
.parentConfiguration
- The parent configuration to use for fallback lookup, ornull
if there is no parent configuration.- 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 parameter 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()
-
-