Package org.jmxtrans.agent.util
Class PropertyPlaceholderResolver
java.lang.Object
org.jmxtrans.agent.util.PropertyPlaceholderResolver
- All Implemented Interfaces:
java.io.Serializable
public class PropertyPlaceholderResolver
extends java.lang.Object
implements java.io.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(java.util.Map<java.lang.String,java.lang.String> externalProperties) -
Method Summary
Modifier and Type Method Description protected java.lang.StringresolvePlaceholder(java.lang.String property, java.lang.String defaultValue)Search for the given placeholder in system properties then in environment variables.java.lang.StringresolveString(java.lang.String string)Parse the givenstringresolving property placeholders (${my-property[:default-value]})Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Constructor Details
-
PropertyPlaceholderResolver
public PropertyPlaceholderResolver(java.util.Map<java.lang.String,java.lang.String> externalProperties) -
PropertyPlaceholderResolver
public PropertyPlaceholderResolver()
-
-
Method Details
-
resolveString
public java.lang.String resolveString(java.lang.String string) throws java.lang.IllegalStateExceptionParse the givenstringresolving property placeholders (${my-property[:default-value]})- Parameters:
string- the string to parse.- Returns:
- the parsed string. Non
null. - Throws:
java.lang.IllegalStateException- a property placeholder could not be resolved and no default value has been defined.
-
resolvePlaceholder
protected java.lang.String resolvePlaceholder(java.lang.String property, java.lang.String defaultValue) throws java.lang.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:
java.lang.IllegalStateException- if the placeholder is not found and the givendefaultValueis not defined (null)
-