org.jvnet.hk2.config
Class VariableResolver

java.lang.Object
  extended by org.jvnet.hk2.config.VariableResolver
All Implemented Interfaces:
Translator

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
VariableResolver()
           
 
Method Summary
protected abstract  String getVariableValue(String varName)
          Returns the value of the variable.
 String translate(String str)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

VariableResolver

public VariableResolver()
Method Detail

translate

public String translate(String str)
                 throws TranslationException
Specified by:
translate in interface Translator
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


Copyright © 2013 Oracle Corporation. All Rights Reserved.