Package org.jmxtrans.agent.util
Class PropertyPlaceholderResolver
java.lang.Object
org.jmxtrans.agent.util.PropertyPlaceholderResolver
- All Implemented Interfaces:
Serializable
public class PropertyPlaceholderResolver extends Object implements Serializable
Inspired by Spring Property placeholder mechanism.
Placeholders are delimited by '{' and '}' and support default value with ':'. Sample : '
{graphite.host}'
or '{graphite.port:2003}'.
If the placeholder is not found in the system properties, it is searched in the environment variables and then
converted to underscore delimited upper case and searched in environment variables.
Sample for '{graphite.port:2003}':
System.getProperty("graphite.port")System.getenv("graphite.port")System.getenv("GRAPHITE_PORT")- default to
2003
- Author:
- Cyrille Le Clerc
- See Also:
- Serialized Form
-
Constructor Summary
Constructors Constructor Description PropertyPlaceholderResolver()PropertyPlaceholderResolver(Map<String,String> externalProperties) -
Method Summary
Modifier and Type Method Description protected StringresolvePlaceholder(String property, String defaultValue)Search for the given placeholder in system properties then in environment variables.StringresolveString(String string)Parse the givenstringresolving property placeholders (${my-property[:default-value]})
-
Constructor Details
-
PropertyPlaceholderResolver
-
PropertyPlaceholderResolver
public PropertyPlaceholderResolver()
-
-
Method Details
-
resolveString
Parse the givenstringresolving property placeholders (${my-property[:default-value]})- Parameters:
string- the string to parse.- Returns:
- the parsed string. Non
null. - Throws:
IllegalStateException- a property placeholder could not be resolved and no default value has been defined.
-
resolvePlaceholder
protected String resolvePlaceholder(String property, String defaultValue) throws IllegalStateExceptionSearch for the given placeholder in system properties then in environment variables.- Parameters:
property- property to resolvedefaultValue- Default value if the placeholder is not found.nullmeans not default value is defined and the placeholder must exist- Returns:
- the resolved property or the default value if the placeholder is not found and the default value is defined. Non null.
- Throws:
IllegalStateException- if the placeholder is not found and the givendefaultValueis not defined (null)
-