Class EvalContext

java.lang.Object
com.randomnoun.common.jexl.eval.EvalContext

public class EvalContext extends Object
Provides variables and functions for an expression to be evaluated with
Author:
knoxg
  • Constructor Details

  • Method Details

    • setVariables

      public void setVariables(Map<String,Object> variables)
      Sets all variables accessable to an expression.
    • setVariable

      public void setVariable(String name, Object value)
      Set a specific variable binding
    • unsetVariable

      public void unsetVariable(String name)
      Removes a specific variable binding
    • getVariable

      public Object getVariable(String varName)
      Returns the value of a variable (used in the Evaluator class).
    • hasVariable

      public boolean hasVariable(String varName)
      Returns true if the variable exists.
    • setFunctions

      public void setFunctions(Map<String,EvalFunction> functions)
      Sets all variables accessible to an expression.
    • setFunction

      public void setFunction(String name, EvalFunction function)
      Set a specific function
    • getFunction

      public Object getFunction(String function)
      Returns the value of a variable (used in the Evaluator class).
    • getVariableComponent

      public Object getVariableComponent(Object varObj, String baseName, String componentName) throws EvalException
      Returns a component of a compound variable (which must currently be a Map object). The component name is the key of the map. e.g. if a Map variable called 'x' contains a key 'y' with the value 'z', then the following code could be used to retrieve this value:
         x = evalContext.getVariable("x")
         value = evalContext.getVariableComponent(x, "x", "y")  // evaluates to 'z'
       

      Note that this is only useful in the Evaluator to retrieve compound variables, outside the evaluator you should be just be evaluating the value "x.y" directly.

      Parameters:
      varObj - the compound variable value that is being evaluated (as returned by the getVariable() method)
      baseName - the name of the variable
      componentName - the name of the component in varObj to return.
      Throws:
      EvalException
    • hasVariableComponent

      public boolean hasVariableComponent(Object varObj, String baseName, String componentName)
      DOCUMENT ME!
      Parameters:
      varObj - DOCUMENT ME!
      baseName - DOCUMENT ME!
      componentName - DOCUMENT ME!
      Returns:
      DOCUMENT ME!