- java.lang.Object
-
- de.carne.util.PropertyResolver
-
public final class PropertyResolver extends java.lang.ObjectUtility class providing dynamic property resolution support.
-
-
Constructor Summary
Constructors Constructor Description PropertyResolver()Constructs a new PropertyResolver instance.PropertyResolver(boolean useSystemProperties, boolean useEnvironemnt)Constructs a new PropertyResolver instance.PropertyResolver(java.util.Map<?,?> properties)Constructs a new PropertyResolver instance.PropertyResolver(java.util.Map<?,?> properties, boolean useSystemProperties, boolean useEnvironemnt)Constructs a new PropertyResolver instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.Stringexpand(java.lang.String s)Expands the given string by resolving all embedded property keys.@Nullable java.lang.Stringresolve(java.lang.String key)Resolves the given key by searching the sources selected during instance creation.java.lang.Stringresolve(java.lang.String key, java.lang.String defaultValue)Resolves the given key by searching the sources selected during instance creation.
-
-
-
Constructor Detail
-
PropertyResolver
public PropertyResolver()
Constructs a new PropertyResolver instance.- See Also:
resolve(String)
-
PropertyResolver
public PropertyResolver(java.util.Map<?,?> properties)
Constructs a new PropertyResolver instance.- Parameters:
properties- the custom properties to consider while resolving.- See Also:
resolve(String)
-
PropertyResolver
public PropertyResolver(boolean useSystemProperties, boolean useEnvironemnt)Constructs a new PropertyResolver instance.- Parameters:
useSystemProperties- whether to consider system properties while resolving.useEnvironemnt- whether to consider environment variables while resolving.- See Also:
resolve(String)
-
PropertyResolver
public PropertyResolver(java.util.Map<?,?> properties, boolean useSystemProperties, boolean useEnvironemnt)Constructs a new PropertyResolver instance.- Parameters:
properties- the custom properties to consider while resolving.useSystemProperties- whether to consider system properties while resolving.useEnvironemnt- whether to consider environment variables while resolving.- See Also:
resolve(String)
-
-
Method Detail
-
resolve
public @Nullable java.lang.String resolve(java.lang.String key)
Resolves the given key by searching the sources selected during instance creation.The sources are searched in the following order:
- Custom properties
- System properties
- Environment variables
'.') is replaced by an underscore ('_').- Parameters:
key- the key to resolve.- Returns:
- the resolved value or
nullif the key is undefined.
-
resolve
public java.lang.String resolve(java.lang.String key, java.lang.String defaultValue)Resolves the given key by searching the sources selected during instance creation.- Parameters:
key- the key to resolve.defaultValue- the value to return in case the key is undefined.- Returns:
- the resolved value or
defaultValueif the key is undefined. - See Also:
resolve(String)
-
expand
public java.lang.String expand(java.lang.String s) throws java.text.ParseExceptionExpands the given string by resolving all embedded property keys.- Parameters:
s- the string to expand.- Returns:
- the expanded string.
- Throws:
java.text.ParseException- if a parse or resolve error occurs during expansion.
-
-