Class Environment
java.lang.Object
org.jpos.core.Environment
- All Implemented Interfaces:
Loggeable
Manages environment-specific configuration for jPOS applications.
Environment provides property resolution with support for:
- YAML (
.yml) and properties (.cfg) configuration files - Property expressions:
${property.name} - Default values:
${property.name:default} - Equality tests:
${property.name=expected} - Boolean negation:
${!property.name} - Prefix-specific lookups:
$env{VAR}- OS environment variable only$sys{prop}- Java system property only$cfg{prop}- Configuration file only$verb{text}- Verbatim (no expansion)
- Nested expressions:
${outer:${inner:default}}
The default property resolution order (for ${prop}) is:
- OS environment variable (
prop) - OS environment variable (
PROPwith dots replaced by underscores) - Java system property
- Configuration file property
Configuration is loaded from the directory specified by jpos.envdir
(default: "cfg") with the filename from jpos.env (default: "default").
- See Also:
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionvoiddump(PrintStream p, String indent) static voidFlattens a nested Map structure into a flat Properties object using dot notation.static StringResolves a property expression using the singleton Environment.static StringResolves a property expression using the singleton Environment.Returns the directory where environment configuration files are located.static EnvironmentReturns the singleton Environment instance.Returns any error message from the last configuration load attempt.getName()Returns the name of the current environment.If property name has the pattern${propname}, this method will Attempt to get it from an operating system environment variable called 'propname' If not present, it will try to pick it from the Java system.property If not present either, it will try the target environment (either.ymlor.cfgOtherwise it returns null The special pattern$env{propname}would just try to pick it from the OS environment.getProperty(String p, String def) Resolves a property expression with a default fallback.static Environmentreload()Reloads the environment configuration from disk.static StringResolves the given expression using the currentEnvironmentinstance, applying the standard priority resolution rules.toString()
-
Field Details
-
notMap
-
-
Method Details
-
getName
-
getEnvDir
-
reload
Reloads the environment configuration from disk. Reads thejpos.envandjpos.envdirsystem properties and reloads the corresponding configuration files.- Returns:
- the newly loaded Environment instance
- Throws:
IOException- if an error occurs reading configuration files
-
getEnvironment
Returns the singleton Environment instance.- Returns:
- the current Environment
-
get
Resolves a property expression using the singleton Environment. If the property cannot be resolved, returns the original expression.- Parameters:
p- the property expression to resolve (e.g., "${my.property}")- Returns:
- the resolved value, or the original expression if unresolved
- See Also:
-
resolve
Resolves the given expression using the currentEnvironmentinstance, applying the standard priority resolution rules.- Parameters:
p- the expression or literal value to resolve; may contain placeholders using the${...}syntax- Returns:
- the resolved value after applying environment priority rules.
- See Also:
-
get
Resolves a property expression using the singleton Environment. If the property cannot be resolved, returns the specified default.- Parameters:
p- the property expression to resolvedef- the default value to return if the property is unresolved- Returns:
- the resolved value, or
defif unresolved - See Also:
-
getProperty
Resolves a property expression with a default fallback.- Parameters:
p- the property expression to resolvedef- the default value to return if the property resolves to null- Returns:
- the resolved value, or
defif null - See Also:
-
getErrorString
Returns any error message from the last configuration load attempt. Typically set when YAML parsing fails.- Returns:
- the error message, or null if no error occurred
-
getProperty
If property name has the pattern${propname}, this method will- Attempt to get it from an operating system environment variable called 'propname'
- If not present, it will try to pick it from the Java system.property
- If not present either, it will try the target environment (either
.ymlor.cfg - Otherwise it returns null
$env{propname}would just try to pick it from the OS environment.$sys{propname}will just try to get it from a System.property and$verb{propname}will return a verbatim copy of the value.- Parameters:
s- property name- Returns:
- property value
-
flat
public static void flat(Properties properties, String prefix, Map<String, Object> c, boolean dereference) Flattens a nested Map structure into a flat Properties object using dot notation. For example, a nested structure like{server: {port: 8080}}becomes the propertyserver.port=8080.List values are comma-encoded using
ISOUtil.commaEncode(String[]).- Parameters:
properties- the Properties object to populateprefix- the current key prefix (null for root level)c- the Map to flattendereference- if true, resolve property expressions in string values
-
dump
-
toString
-