Class VariableResolver

java.lang.Object
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
  • Constructor Details

    • VariableResolver

      public VariableResolver()
  • Method Details

    • 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