Class Interpreter
java.lang.Object
org.apache.commons.jexl2.Interpreter
- All Implemented Interfaces:
ParserVisitor
An interpreter of JEXL syntax.
- Since:
- 2.0
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final JexlArithmeticThe arithmetic handler.protected final booleanCache executors.protected final JexlContextThe context to store/retrieve variables.protected static final Object[]Empty parameters for method matching.The map of registered functions.The map of registered functions.protected final org.apache.commons.logging.LogThe logger.protected Object[]Registers or arguments.protected booleanSilent intepreter flag.protected booleanStrict interpreter flag.protected final UberspectThe uberspect. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedInterpreter(Interpreter base) Copy constructor.Interpreter(JexlEngine jexl, JexlContext aContext) Deprecated.Interpreter(JexlEngine jexl, JexlContext aContext, boolean strictFlag, boolean silentFlag) Creates an interpreter. -
Method Summary
Modifier and TypeMethodDescriptionprotected JexlNodefindNullOperand(RuntimeException xrt, JexlNode node, Object left, Object right) Finds the node causing a NPE for diadic operators.getAttribute(Object object, Object attribute) Gets an attribute of an object.protected ObjectgetAttribute(Object object, Object attribute, JexlNode node) Gets an attribute of an object.protected JexlContextGets the context.protected UberspectGets the uberspect.Interpret the given script/expression.protected ObjectinvocationFailed(JexlException xjexl) Triggered when method, function or constructor invocation fails.protected booleanChecks whether this interpreter execution was cancelled due to thread interruption.booleanisSilent()Checks whether this interpreter throws JexlException when encountering errors.booleanisStrict()Checks whether this interpreter considers unknown variables, methods and constructors as errors.protected ObjectresolveNamespace(String prefix, JexlNode node) Resolves a namespace, eventually allocating an instance using context as constructor argument.voidsetAttribute(Object object, Object attribute, Object value) Sets an attribute of an object.protected voidsetAttribute(Object object, Object attribute, Object value, JexlNode node) Sets an attribute of an object.protected voidsetFrame(JexlEngine.Frame frame) Sets this interpreter parameters and arguments.protected voidsetRegisters(Object... theRegisters) Deprecated.voidsetSilent(boolean flag) Deprecated.Do not use; will be removed in a later versionvoidsetStrict(boolean flag) Deprecated.Do not use; will be removed in a later versionprotected ObjectunknownVariable(JexlException xjexl) Triggered when variable can not be resolved.visit(ASTAdditiveNode node, Object data) visit(ASTAdditiveOperator node, Object data) visit(ASTAmbiguous node, Object data) Unused, should throw in Parser.visit(ASTAndNode node, Object data) visit(ASTArrayAccess node, Object data) visit(ASTArrayLiteral node, Object data) visit(ASTAssignment node, Object data) visit(ASTBitwiseAndNode node, Object data) visit(ASTBitwiseComplNode node, Object data) visit(ASTBitwiseOrNode node, Object data) visit(ASTBitwiseXorNode node, Object data) visit(ASTConstructorNode node, Object data) visit(ASTDivNode node, Object data) visit(ASTEmptyFunction node, Object data) visit(ASTFalseNode node, Object data) visit(ASTFloatLiteral node, Object data) Deprecated.Do not usevisit(ASTForeachStatement node, Object data) visit(ASTFunctionNode node, Object data) visit(ASTIdentifier node, Object data) visit(ASTIfStatement node, Object data) visit(ASTIntegerLiteral node, Object data) Deprecated.Do not usevisit(ASTJexlScript node, Object data) visit(ASTMapEntry node, Object data) visit(ASTMapLiteral node, Object data) visit(ASTMethodNode node, Object data) visit(ASTModNode node, Object data) visit(ASTMulNode node, Object data) visit(ASTNotNode node, Object data) visit(ASTNullLiteral node, Object data) visit(ASTNumberLiteral node, Object data) visit(ASTReferenceExpression node, Object data) visit(ASTReference node, Object data) visit(ASTReturnStatement node, Object data) visit(ASTSizeFunction node, Object data) visit(ASTSizeMethod node, Object data) visit(ASTStringLiteral node, Object data) visit(ASTTernaryNode node, Object data) visit(ASTTrueNode node, Object data) visit(ASTUnaryMinusNode node, Object data) visit(ASTWhileStatement node, Object data) visit(SimpleNode node, Object data) Unused, satisfy ParserVisitor interface.
-
Field Details
-
logger
The logger. -
uberspect
-
arithmetic
The arithmetic handler. -
functions
-
functors
-
context
The context to store/retrieve variables. -
strict
Strict interpreter flag. Do not modify; will be made final/private in a later version. -
silent
Silent intepreter flag. Do not modify; will be made final/private in a later version. -
cache
Cache executors. -
registers
-
EMPTY_PARAMS
Empty parameters for method matching.
-
-
Constructor Details
-
Interpreter
Deprecated.Creates an interpreter.- Parameters:
jexl- the engine creating this interpreteraContext- the context to evaluate expression
-
Interpreter
Creates an interpreter.- Parameters:
jexl- the engine creating this interpreteraContext- the context to evaluate expressionstrictFlag- whether this interpreter runs in strict modesilentFlag- whether this interpreter runs in silent mode- Since:
- 2.1
-
Interpreter
Copy constructor.- Parameters:
base- the base to copy- Since:
- 2.1
-
-
Method Details
-
setStrict
Deprecated.Do not use; will be removed in a later versionSets whether this interpreter considers unknown variables, methods and constructors as errors.- Parameters:
flag- true for strict, false for lenient- Since:
- 2.1
-
setSilent
Deprecated.Do not use; will be removed in a later versionSets whether this interpreter throws JexlException when encountering errors.- Parameters:
flag- true for silent, false for verbose
-
isStrict
Checks whether this interpreter considers unknown variables, methods and constructors as errors.- Returns:
- true if strict, false otherwise
- Since:
- 2.1
-
isSilent
Checks whether this interpreter throws JexlException when encountering errors.- Returns:
- true if silent, false otherwise
-
interpret
Interpret the given script/expression.If the underlying JEXL engine is silent, errors will be logged through its logger as info.
- Parameters:
node- the script or expression to interpret.- Returns:
- the result of the interpretation.
- Throws:
JexlException- if any error occurs during interpretation.
-
getContext
Gets the context.- Returns:
- the
JexlContextused for evaluation. - Since:
- 2.1
-
getUberspect
-
setRegisters
Deprecated.Sets this interpreter registers for bean access/assign expressions.Use setFrame(...) instead.
- Parameters:
theRegisters- the array of registers
-
setFrame
Sets this interpreter parameters and arguments.- Parameters:
frame- the calling frame- Since:
- 2.1
-
findNullOperand
Finds the node causing a NPE for diadic operators.- Parameters:
xrt- the RuntimeExceptionnode- the parent nodeleft- the left argumentright- the right argument- Returns:
- the left, right or parent node
-
unknownVariable
Triggered when variable can not be resolved.- Parameters:
xjexl- the JexlException ("undefined variable " + variable)- Returns:
- throws JexlException if strict, null otherwise
-
invocationFailed
Triggered when method, function or constructor invocation fails.- Parameters:
xjexl- the JexlException wrapping the original error- Returns:
- throws JexlException if strict, null otherwise
-
isCancelled
Checks whether this interpreter execution was cancelled due to thread interruption.- Returns:
- true if cancelled, false otherwise
- Since:
- 2.1
-
resolveNamespace
Resolves a namespace, eventually allocating an instance using context as constructor argument. The lifetime of such instances span the current expression or script evaluation.- Parameters:
prefix- the prefix name (may be null for global namespace)node- the AST node- Returns:
- the namespace instance
-
visit
- Specified by:
visitin interfaceParserVisitor
-
visit
- Specified by:
visitin interfaceParserVisitor
-
visit
- Specified by:
visitin interfaceParserVisitor
-
visit
- Specified by:
visitin interfaceParserVisitor
-
visit
- Specified by:
visitin interfaceParserVisitor
-
visit
- Specified by:
visitin interfaceParserVisitor
-
visit
- Specified by:
visitin interfaceParserVisitor
-
visit
- Specified by:
visitin interfaceParserVisitor
-
visit
- Specified by:
visitin interfaceParserVisitor
-
visit
- Specified by:
visitin interfaceParserVisitor
-
visit
-
visit
- Specified by:
visitin interfaceParserVisitor
-
visit
- Specified by:
visitin interfaceParserVisitor
-
visit
-
visit
- Specified by:
visitin interfaceParserVisitor
-
visit
- Specified by:
visitin interfaceParserVisitor
-
visit
-
visit
-
visit
-
visit
- Specified by:
visitin interfaceParserVisitor
-
visit
Deprecated.Do not use -
visit
Deprecated.Do not use -
visit
-
visit
- Specified by:
visitin interfaceParserVisitor
-
visit
- Specified by:
visitin interfaceParserVisitor
-
visit
- Specified by:
visitin interfaceParserVisitor
-
visit
-
visit
-
visit
- Specified by:
visitin interfaceParserVisitor
-
visit
- Specified by:
visitin interfaceParserVisitor
-
visit
- Specified by:
visitin interfaceParserVisitor
-
visit
- Specified by:
visitin interfaceParserVisitor
-
visit
- Specified by:
visitin interfaceParserVisitor
-
visit
- Specified by:
visitin interfaceParserVisitor
-
visit
- Specified by:
visitin interfaceParserVisitor
-
visit
-
visit
-
visit
- Specified by:
visitin interfaceParserVisitor
-
visit
- Specified by:
visitin interfaceParserVisitor
-
visit
-
visit
- Specified by:
visitin interfaceParserVisitor
-
visit
- Specified by:
visitin interfaceParserVisitor- Since:
- 2.1
-
visit
- Specified by:
visitin interfaceParserVisitor- Since:
- 2.1
-
visit
- Specified by:
visitin interfaceParserVisitor
-
visit
- Specified by:
visitin interfaceParserVisitor
-
visit
- Specified by:
visitin interfaceParserVisitor
-
visit
- Specified by:
visitin interfaceParserVisitor
-
visit
- Specified by:
visitin interfaceParserVisitor
-
visit
- Specified by:
visitin interfaceParserVisitor
-
visit
- Specified by:
visitin interfaceParserVisitor
-
getAttribute
Gets an attribute of an object.- Parameters:
object- to retrieve value fromattribute- the attribute of the object, e.g. an index (1, 0, 2) or key for a map- Returns:
- the attribute value
-
getAttribute
Gets an attribute of an object.- Parameters:
object- to retrieve value fromattribute- the attribute of the object, e.g. an index (1, 0, 2) or key for a mapnode- the node that evaluated as the object- Returns:
- the attribute value
-
setAttribute
Sets an attribute of an object.- Parameters:
object- to set the value toattribute- the attribute of the object, e.g. an index (1, 0, 2) or key for a mapvalue- the value to assign to the object's attribute
-
setAttribute
Sets an attribute of an object.- Parameters:
object- to set the value toattribute- the attribute of the object, e.g. an index (1, 0, 2) or key for a mapvalue- the value to assign to the object's attributenode- the node that evaluated as the object
-
visit
Unused, satisfy ParserVisitor interface.- Specified by:
visitin interfaceParserVisitor- Parameters:
node- a nodedata- the data- Returns:
- does not return
-
visit
Unused, should throw in Parser.- Specified by:
visitin interfaceParserVisitor- Parameters:
node- a nodedata- the data- Returns:
- does not return
-