Package com.randomnoun.common.jexl.eval
Class EvalContext
java.lang.Object
com.randomnoun.common.jexl.eval.EvalContext
Provides variables and functions for an expression to be evaluated with
- Author:
- knoxg
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiongetFunction(String function) Returns the value of a variable (used in the Evaluator class).getVariable(String varName) Returns the value of a variable (used in the Evaluator class).getVariableComponent(Object varObj, String baseName, String componentName) Returns a component of a compound variable (which must currently be a Map object).booleanhasVariable(String varName) Returns true if the variable exists.booleanhasVariableComponent(Object varObj, String baseName, String componentName) DOCUMENT ME!voidsetFunction(String name, EvalFunction function) Set a specific functionvoidsetFunctions(Map<String, EvalFunction> functions) Sets all variables accessible to an expression.voidsetVariable(String name, Object value) Set a specific variable bindingvoidsetVariables(Map<String, Object> variables) Sets all variables accessable to an expression.voidunsetVariable(String name) Removes a specific variable binding
-
Constructor Details
-
EvalContext
public EvalContext()
-
-
Method Details
-
setVariables
Sets all variables accessable to an expression. -
setVariable
Set a specific variable binding -
unsetVariable
Removes a specific variable binding -
getVariable
Returns the value of a variable (used in the Evaluator class). -
hasVariable
Returns true if the variable exists. -
setFunctions
Sets all variables accessible to an expression. -
setFunction
Set a specific function -
getFunction
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 variablecomponentName- the name of the component in varObj to return.- Throws:
EvalException
-
hasVariableComponent
DOCUMENT ME!- Parameters:
varObj- DOCUMENT ME!baseName- DOCUMENT ME!componentName- DOCUMENT ME!- Returns:
- DOCUMENT ME!
-