Package org.jvnet.hk2.config
Class VariableResolver
- java.lang.Object
-
- org.jvnet.hk2.config.VariableResolver
-
- All Implemented Interfaces:
Translator
- Direct Known Subclasses:
AttributeResolverHelper
public abstract class VariableResolver extends Object implements Translator
Translator
that does variable resolution in the Ant style.This implementation looks for variables in the string like "${xyz}" or "${abc.DEF.ghi}". The
getVariableValue(String)
method is then used to obtain the actual value for the variable."$$" works as the escape of "$", so for example "$${abc}" expands to "${abc}" where "${abc}" would have expanded to "value-of-abc". A lone "$" is left as-is, so "$abc" expands to "$abc".
- Author:
- Kohsuke Kawaguchi
-
-
Field Summary
-
Fields inherited from interface org.jvnet.hk2.config.Translator
NOOP, SYS_PROP_TR
-
-
Constructor Summary
Constructors Constructor Description VariableResolver()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected abstract String
getVariableValue(String varName)
Returns the value of the variable.String
translate(String str)
-
-
-
Method Detail
-
translate
public String translate(String str) throws TranslationException
- Specified by:
translate
in interfaceTranslator
- Throws:
TranslationException
-
getVariableValue
protected abstract String getVariableValue(String varName) throws TranslationException
Returns the value of the variable. This class will not try to further expand variables in the returned value. If the implementation wants to do so, that is the implementation's responsibility.- Returns:
- null if the variable is not found. The caller will report an error.
When the variable is not found, it's also legal to throw
TranslationException
, which is an useful technique if the implementation would like to report additional errors. - Throws:
TranslationException
-
-