public class LoaderEnvironmentBuilder extends Object implements LoaderEnvironment
LoaderEnvironment.| Modifier and Type | Field and Description |
|---|---|
protected List<String> |
_cmdLineArgs |
protected Map<String,String> |
_envVars |
protected Map<String,Object> |
_fixedNamedValues |
protected List<PropertyValue<?>> |
_fixedPropertyValues |
protected Supplier<JndiContextWrapper> |
_jndiContextSupplier |
protected boolean |
_replaceEnvVars |
protected boolean |
_replaceSysProps |
protected Map<String,String> |
_sysProps |
| Constructor and Description |
|---|
LoaderEnvironmentBuilder() |
| Modifier and Type | Method and Description |
|---|---|
<T> void |
addFixedValue(Property<T> property,
T value)
Sets a fixed, non-configurable value for a Property.
|
void |
addFixedValue(String propertyNameOrAlias,
Object value)
Sets a fixed, non-configurable value for a named Property.
|
protected static Map<String,String> |
buildPropertyMap(Properties props) |
List<String> |
getCmdLineArgs()
Returns the command line argument strings passed to the
main(String[] args) method,
as a List, if they are available. |
Map<String,String> |
getEnvVars()
Returns the Map of overridden environment variables, if any.
|
Map<String,Object> |
getFixedNamedValues()
Returns a Map of hard-coded / fixed values for some properties referenced by name and set by
application code prior to AndHow initialization.
|
List<PropertyValue<?>> |
getFixedPropertyValues()
Returns a List of hard-coded / fixed values for some properties in the form of a List of
PropertyValues, set application code prior to AndHow initialization. |
JndiContextWrapper |
getJndiContext()
Returns a JNDI Context that can be used by loaders to load from JNDI.
|
Supplier<JndiContextWrapper> |
getJndiContextSupplier() |
Map<String,String> |
getSysProps()
Returns the Map of overridden system properties, if any.
|
boolean |
isEnvVarsReplaced()
Returns true if the normal
System.getenv() values are being replaced
by the contents of getEnvVars(). |
boolean |
isSysPropsReplaced()
Returns true if the normal
System.getProperties() values are being replaced
by the contents of getSysProps(). |
Object |
removeFixedValue(Property<?> property)
Removes a fixed Property value set only via addFixedValue(Property
setFixedPropertyValues(List). |
Object |
removeFixedValue(String propertyNameOrAlias)
Removes a Property value set only via addFixedValue(String name, Object value)
or
setFixedNamedValues(Map). |
void |
resetToActualEnvVars()
Forces any previous env.
|
void |
resetToActualSysProps()
Forces any previous sys.
|
void |
setCmdLineArgs(String[] commandLineArgs)
Set the commandline arguments, overriding any previously set values.
|
void |
setEnvVars(Map<String,String> envVars)
Set the environment vars that the Loaders see, overriding the actual env.
|
void |
setFixedNamedValues(Map<String,Object> fixedVals)
Set the fixed / hardcoded named property values, overriding any previously set values.
|
void |
setFixedPropertyValues(List<PropertyValue<?>> fixedVals)
Set the fixed / hardcoded property values, overriding any previously set values.
|
void |
setJndiContextSupplier(Supplier<JndiContextWrapper> jndiContextSupplier) |
void |
setSysProps(Map<String,String> sysProps)
Set the java system properties that the Loaders see, overriding the actual sys.
|
LoaderEnvironmentImm |
toImmutable() |
protected final List<PropertyValue<?>> _fixedPropertyValues
protected boolean _replaceEnvVars
protected boolean _replaceSysProps
protected Supplier<JndiContextWrapper> _jndiContextSupplier
public void setEnvVars(Map<String,String> envVars)
Calling this method causes the passed Map to completely replace the values that Loaders would have seen coming from the OS provided environment variables. Passing a null or empty Map results in the loaders seeing no env vars. Values are overwritten each time this method is called.
envVars - The new env vars to use. Null and empty both result in the zero env vars.public void resetToActualEnvVars()
setEnvVars(Map) to be dumped and the actual
OS provided env. vars. will be used instead.
Note that calling getEnvVars() will return an empty collection after this
method is called. The real env. vars. will be injected when toImmutable() is called.
public boolean isEnvVarsReplaced()
System.getenv() values are being replaced
by the contents of getEnvVars().
This is set to true by calling setEnvVars(Map), false by calling
resetToActualEnvVars().public void setSysProps(Map<String,String> sysProps)
Calling this method causes the passed Map to completely replace the values that
Loaders would have seen coming from System.getProperties(). Passing a null or
empty Map results in the loaders seeing no sys. props.
Values are overwritten each time this method is called.
sysProps - The new sys props to use. Null and empty both result in the zero sys. props.public void resetToActualSysProps()
setSysProps(Map)} to be dumped and the actual
System.getProperties() will be used instead.
Note that calling getSysProps() will return an empty collection after this
method is called. The real sys. props. will be injected when toImmutable() is called.
public boolean isSysPropsReplaced()
System.getProperties() values are being replaced
by the contents of getSysProps().
This is set to true by calling setSysProps(Map), false by calling
resetToActualSysProps().public void setCmdLineArgs(String[] commandLineArgs)
commandLineArgs - The new cmd line args to usepublic void setFixedNamedValues(Map<String,Object> fixedVals)
FixedNamedValues and FixedPropertyValues are handled separately, but accomplish the same
thing. Both result in setting the value of the reference Property to a value in code.
setFixedNamedValues will only affect named values (it does not overwrite
FixedPropertyValues). See LoaderEnvironment.getFixedNamedValues().
fixedVals - A map of fixed values, using either canonical or alias names for keys
and correctly typed objects or Strings that can be parsed to the correct type for
the referenced Property. If null or empty, the resulting fixedNamedValue map will be empty.public <T> void addFixedValue(Property<T> property, T value)
T - The type of Property and valueproperty - The property to set a value forvalue - The value to set.public Object removeFixedValue(Property<?> property)
setFixedPropertyValues(List).
It is not an error to attempt to remove a property that is not in this fixed value list.property - A non-null property.public void addFixedValue(String propertyNameOrAlias, Object value)
propertyNameOrAlias - The canonical or alias name of Property, which is trimmed to null.value - The Object value to set, which must match the type of the Property.IllegalArgumentException - if the name trims to null, the value is null,
or the name is already associated w/ a value (use remove).public Object removeFixedValue(String propertyNameOrAlias)
setFixedNamedValues(Map).
Note that to successfully remove a fixed value from this list, the name must exactly
match the name used to set the property via addFixedValue(String, Object). Since
Properties can have aliases, you must know the exact name to set the property.
It is not an error to attempt to remove a property that is not in this fixed value list, or to attempt to remove a property value that does not exist - these are just no-ops.
propertyNameOrAlias - The name or alias of a property.public Supplier<JndiContextWrapper> getJndiContextSupplier()
public void setJndiContextSupplier(Supplier<JndiContextWrapper> jndiContextSupplier)
public void setFixedPropertyValues(List<PropertyValue<?>> fixedVals)
FixedNamedValues and FixedPropertyValues are handled separately, but accomplish the same
thing. Both result in setting the value of the reference Property to a value in code.
setFixedPropertyValues will only affect PropertyValues (it does not overwrite
FixedNamedValues). See LoaderEnvironment.getFixedPropertyValues().
fixedVals - A list of fixed PropertyValue's. If null or empty, the resulting
fixedPropertyValue list will be empty.public LoaderEnvironmentImm toImmutable()
protected static Map<String,String> buildPropertyMap(Properties props)
public Map<String,String> getEnvVars()
If isEnvVarsReplaced() is true, then the values returned here will be used
as the env vars when loading configuration values. If false, the actual
System.getenv() will be used. See setEnvVars(Map) and
resetToActualEnvVars() for setting and unsetting these values.
getEnvVars in interface LoaderEnvironmentpublic Map<String,String> getSysProps()
If isSysPropsReplaced() is true, then the values returned here will be used
as the system properties when loading configuration values. If false, the actual
System.getProperties() will be used. See setSysProps(Map) and
resetToActualSysProps() for setting and unsetting these values.
getSysProps in interface LoaderEnvironmentpublic List<String> getCmdLineArgs()
LoaderEnvironmentmain(String[] args) method,
as a List, if they are available.
Its possible that cmd line arguments are passed to the application but not available here.
This is because AndHow has no way to intercept cmd line arguments, so application code needs
to pass them in to AndHow, which may not have been done
(See how-to details in StdMainStringArgsLoader).
Nominally this returns the same as the cmd line arguments converted to a List, but may be customized for testing.
getCmdLineArgs in interface LoaderEnvironmentpublic Map<String,Object> getFixedNamedValues()
LoaderEnvironment
The referenced Properties and values returned by this method and LoaderEnvironment.getFixedPropertyValues()
are intended to be loaded by the StdFixedValueLoader, which nominally loads prior to any
other loader, effectively making the value non-configurable.
getFixedNamedValues in interface LoaderEnvironmentpublic List<PropertyValue<?>> getFixedPropertyValues()
LoaderEnvironmentPropertyValues, set application code prior to AndHow initialization.
The referenced Properties and values returned by this method and LoaderEnvironment.getFixedNamedValues()
are intended to be loaded by the StdFixedValueLoader, which nominally loads prior to any
other loader, effectively making the value non-configurable.
getFixedPropertyValues in interface LoaderEnvironmentpublic JndiContextWrapper getJndiContext()
LoaderEnvironmentgetJndiContext in interface LoaderEnvironmentCopyright © 2022. All rights reserved.