Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.apache.commons.jexl2
Class Interpreter

    java.lang.Object
      org.apache.commons.jexl2.Interpreter

All Implemented Interfaces:
  ParserVisitor

    public class Interpreter

extends java.lang.Object
implements ParserVisitor

An interpreter of JEXL syntax.

Since:
  2.0

Field Summary
`protected JexlArithmetic` | `arithmetic` The arithmetic handler.
`protected boolean` | `cache` Cache executors.
`protected JexlContext` | `context` The context to store/retrieve variables.
`protected static java.lang.Object[]` | `EMPTY_PARAMS` Empty parameters for method matching.
`protected java.util.Map<java.lang.String,java.lang.Object>` | `functions` The map of registered functions.
`protected java.util.Map<java.lang.String,java.lang.Object>` | `functors` The map of registered functions.
`protected org.apache.commons.logging.Log` | `logger` The logger.
`protected java.lang.Object[]` | `registers` Registers made of 2 pairs of {register-name, value}.
`protected boolean` | `silent` Silent intepreter flag.
`protected boolean` | `strict` Strict interpreter flag.
`protected Uberspect` | `uberspect` The uberspect.

Constructor Summary
`Interpreter(JexlEngine jexl, JexlContext aContext)` Creates an interpreter.

Method Summary
`protected JexlNode` | `findNullOperand(java.lang.RuntimeException xrt, JexlNode node, java.lang.Object left, java.lang.Object right)` Finds the node causing a NPE for diadic operators.
`java.lang.Object` | `getAttribute(java.lang.Object object, java.lang.Object attribute)` Gets an attribute of an object.
`protected java.lang.Object` | `getAttribute(java.lang.Object object, java.lang.Object attribute, JexlNode node)` Gets an attribute of an object.
`protected Uberspect` | `getUberspect()` Gets the uberspect.
`java.lang.Object` | `interpret(JexlNode node)` Interpret the given script/expression.
`protected java.lang.Object` | `invocationFailed(JexlException xjexl)` Triggered when method, function or constructor invocation fails.
`boolean` | `isSilent()` Checks whether this interpreter throws JexlException during evaluation.
`protected java.lang.Object` | `resolveNamespace(java.lang.String prefix, JexlNode node)` Resolves a namespace, eventually allocating an instance using context as constructor argument.
`void` | `setAttribute(java.lang.Object object, java.lang.Object attribute, java.lang.Object value)` Sets an attribute of an object.
`protected void` | `setAttribute(java.lang.Object object, java.lang.Object attribute, java.lang.Object value, JexlNode node)` Sets an attribute of an object.
`protected void` | `setRegisters(java.lang.Object... theRegisters)` Sets this interpreter registers for bean access/assign expressions.
`void` | `setSilent(boolean flag)` Sets whether this interpreter throws JexlException during evaluation.
`protected java.lang.Object` | `unknownVariable(JexlException xjexl)` Triggered when variable can not be resolved.
`java.lang.Object` | `visit(ASTAdditiveNode node, java.lang.Object data)`
`java.lang.Object` | `visit(ASTAdditiveOperator node, java.lang.Object data)`
`java.lang.Object` | `visit(ASTAmbiguous node, java.lang.Object data)` Unused, should throw in Parser.
`java.lang.Object` | `visit(ASTAndNode node, java.lang.Object data)`
`java.lang.Object` | `visit(ASTArrayAccess node, java.lang.Object data)`
`java.lang.Object` | `visit(ASTArrayLiteral node, java.lang.Object data)`
`java.lang.Object` | `visit(ASTAssignment node, java.lang.Object data)`
`java.lang.Object` | `visit(ASTBitwiseAndNode node, java.lang.Object data)`
`java.lang.Object` | `visit(ASTBitwiseComplNode node, java.lang.Object data)`
`java.lang.Object` | `visit(ASTBitwiseOrNode node, java.lang.Object data)`
`java.lang.Object` | `visit(ASTBitwiseXorNode node, java.lang.Object data)`
`java.lang.Object` | `visit(ASTBlock node, java.lang.Object data)`
`java.lang.Object` | `visit(ASTConstructorNode node, java.lang.Object data)`
`java.lang.Object` | `visit(ASTDivNode node, java.lang.Object data)`
`java.lang.Object` | `visit(ASTEmptyFunction node, java.lang.Object data)`
`java.lang.Object` | `visit(ASTEQNode node, java.lang.Object data)`
`java.lang.Object` | `visit(ASTERNode node, java.lang.Object data)`
`java.lang.Object` | `visit(ASTFalseNode node, java.lang.Object data)`
`java.lang.Object` | `visit(ASTFloatLiteral node, java.lang.Object data)`
`java.lang.Object` | `visit(ASTForeachStatement node, java.lang.Object data)`
`java.lang.Object` | `visit(ASTFunctionNode node, java.lang.Object data)`
`java.lang.Object` | `visit(ASTGENode node, java.lang.Object data)`
`java.lang.Object` | `visit(ASTGTNode node, java.lang.Object data)`
`java.lang.Object` | `visit(ASTIdentifier node, java.lang.Object data)`
`java.lang.Object` | `visit(ASTIfStatement node, java.lang.Object data)`
`java.lang.Object` | `visit(ASTIntegerLiteral node, java.lang.Object data)`
`java.lang.Object` | `visit(ASTJexlScript node, java.lang.Object data)`
`java.lang.Object` | `visit(ASTLENode node, java.lang.Object data)`
`java.lang.Object` | `visit(ASTLTNode node, java.lang.Object data)`
`java.lang.Object` | `visit(ASTMapEntry node, java.lang.Object data)`
`java.lang.Object` | `visit(ASTMapLiteral node, java.lang.Object data)`
`java.lang.Object` | `visit(ASTMethodNode node, java.lang.Object data)`
`java.lang.Object` | `visit(ASTModNode node, java.lang.Object data)`
`java.lang.Object` | `visit(ASTMulNode node, java.lang.Object data)`
`java.lang.Object` | `visit(ASTNENode node, java.lang.Object data)`
`java.lang.Object` | `visit(ASTNotNode node, java.lang.Object data)`
`java.lang.Object` | `visit(ASTNRNode node, java.lang.Object data)`
`java.lang.Object` | `visit(ASTNullLiteral node, java.lang.Object data)`
`java.lang.Object` | `visit(ASTOrNode node, java.lang.Object data)`
`java.lang.Object` | `visit(ASTReference node, java.lang.Object data)`
`java.lang.Object` | `visit(ASTSizeFunction node, java.lang.Object data)`
`java.lang.Object` | `visit(ASTSizeMethod node, java.lang.Object data)`
`java.lang.Object` | `visit(ASTStringLiteral node, java.lang.Object data)`
`java.lang.Object` | `visit(ASTTernaryNode node, java.lang.Object data)`
`java.lang.Object` | `visit(ASTTrueNode node, java.lang.Object data)`
`java.lang.Object` | `visit(ASTUnaryMinusNode node, java.lang.Object data)`
`java.lang.Object` | `visit(ASTWhileStatement node, java.lang.Object data)`
`java.lang.Object` | `visit(SimpleNode node, java.lang.Object data)` Unused, satisfy ParserVisitor interface.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### logger

    protected final org.apache.commons.logging.Log logger

  The logger.

### uberspect

    protected final Uberspect uberspect

  The uberspect.

### arithmetic

    protected final JexlArithmetic arithmetic

  The arithmetic handler.

### functions

    protected final java.util.Map<java.lang.String,java.lang.Object> functions

  The map of registered functions.

### functors

    protected java.util.Map<java.lang.String,java.lang.Object> functors

  The map of registered functions.

### context

    protected final JexlContext context

  The context to store/retrieve variables.

### strict

    protected final boolean strict

  Strict interpreter flag.

### silent

    protected boolean silent

  Silent intepreter flag.

### cache

    protected final boolean cache

  Cache executors.

### registers

    protected java.lang.Object[] registers

  Registers made of 2 pairs of {register-name, value}.

### EMPTY_PARAMS

    protected static final java.lang.Object[] EMPTY_PARAMS

  Empty parameters for method matching.

Constructor Detail

### Interpreter

    public Interpreter(JexlEngine jexl,
                       JexlContext aContext)

  Creates an interpreter.

  Parameters:
    `jexl` - the engine creating this interpreter
    `aContext` - the context to evaluate expression

Method Detail

### setSilent

    public void setSilent(boolean flag)

  Sets whether this interpreter throws JexlException during evaluation.

  Parameters:
    `flag` - true means no JexlException will be thrown but will be logged as info through the Jexl engine logger, false allows them to be thrown.

### isSilent

    public boolean isSilent()

  Checks whether this interpreter throws JexlException during evaluation.

  Returns:
    true if silent, false otherwise

### interpret

    public java.lang.Object interpret(JexlNode node)

  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.

### getUberspect

    protected Uberspect getUberspect()

  Gets the uberspect.

  Returns:
    an `Uberspect`

### setRegisters

    protected void setRegisters(java.lang.Object... theRegisters)

  Sets this interpreter registers for bean access/assign expressions.

  Parameters:
    `theRegisters` - the array of registers

### findNullOperand

    protected JexlNode findNullOperand(java.lang.RuntimeException xrt,
                                       JexlNode node,
                                       java.lang.Object left,
                                       java.lang.Object right)

  Finds the node causing a NPE for diadic operators.

  Parameters:
    `xrt` - the RuntimeException
    `node` - the parent node
    `left` - the left argument
    `right` - the right argument
  Returns:
    the left, right or parent node

### unknownVariable

    protected java.lang.Object unknownVariable(JexlException xjexl)

  Triggered when variable can not be resolved.

  Parameters:
    `xjexl` - the JexlException ("undefined variable " + variable)
  Returns:
    throws JexlException if strict, null otherwise

### invocationFailed

    protected java.lang.Object invocationFailed(JexlException xjexl)

  Triggered when method, function or constructor invocation fails.

  Parameters:
    `xjexl` - the JexlException wrapping the original error
  Returns:
    throws JexlException if strict, null otherwise

### resolveNamespace

    protected java.lang.Object resolveNamespace(java.lang.String prefix,
                                                JexlNode node)

  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

    public java.lang.Object visit(ASTAdditiveNode node,
                                  java.lang.Object data)

  Specified by:
    `visit` in interface `ParserVisitor`

### visit

    public java.lang.Object visit(ASTAdditiveOperator node,
                                  java.lang.Object data)

  Specified by:
    `visit` in interface `ParserVisitor`

### visit

    public java.lang.Object visit(ASTAndNode node,
                                  java.lang.Object data)

  Specified by:
    `visit` in interface `ParserVisitor`

### visit

    public java.lang.Object visit(ASTArrayAccess node,
                                  java.lang.Object data)

  Specified by:
    `visit` in interface `ParserVisitor`

### visit

    public java.lang.Object visit(ASTArrayLiteral node,
                                  java.lang.Object data)

  Specified by:
    `visit` in interface `ParserVisitor`

### visit

    public java.lang.Object visit(ASTAssignment node,
                                  java.lang.Object data)

  Specified by:
    `visit` in interface `ParserVisitor`

### visit

    public java.lang.Object visit(ASTBitwiseAndNode node,
                                  java.lang.Object data)

  Specified by:
    `visit` in interface `ParserVisitor`

### visit

    public java.lang.Object visit(ASTBitwiseComplNode node,
                                  java.lang.Object data)

  Specified by:
    `visit` in interface `ParserVisitor`

### visit

    public java.lang.Object visit(ASTBitwiseOrNode node,
                                  java.lang.Object data)

  Specified by:
    `visit` in interface `ParserVisitor`

### visit

    public java.lang.Object visit(ASTBitwiseXorNode node,
                                  java.lang.Object data)

  Specified by:
    `visit` in interface `ParserVisitor`

### visit

    public java.lang.Object visit(ASTBlock node,
                                  java.lang.Object data)

  Specified by:
    `visit` in interface `ParserVisitor`

### visit

    public java.lang.Object visit(ASTDivNode node,
                                  java.lang.Object data)

  Specified by:
    `visit` in interface `ParserVisitor`

### visit

    public java.lang.Object visit(ASTEmptyFunction node,
                                  java.lang.Object data)

  Specified by:
    `visit` in interface `ParserVisitor`

### visit

    public java.lang.Object visit(ASTEQNode node,
                                  java.lang.Object data)

  Specified by:
    `visit` in interface `ParserVisitor`

### visit

    public java.lang.Object visit(ASTFalseNode node,
                                  java.lang.Object data)

  Specified by:
    `visit` in interface `ParserVisitor`

### visit

    public java.lang.Object visit(ASTFloatLiteral node,
                                  java.lang.Object data)

  Specified by:
    `visit` in interface `ParserVisitor`

### visit

    public java.lang.Object visit(ASTForeachStatement node,
                                  java.lang.Object data)

  Specified by:
    `visit` in interface `ParserVisitor`

### visit

    public java.lang.Object visit(ASTGENode node,
                                  java.lang.Object data)

  Specified by:
    `visit` in interface `ParserVisitor`

### visit

    public java.lang.Object visit(ASTGTNode node,
                                  java.lang.Object data)

  Specified by:
    `visit` in interface `ParserVisitor`

### visit

    public java.lang.Object visit(ASTERNode node,
                                  java.lang.Object data)

  Specified by:
    `visit` in interface `ParserVisitor`

### visit

    public java.lang.Object visit(ASTIdentifier node,
                                  java.lang.Object data)

  Specified by:
    `visit` in interface `ParserVisitor`

### visit

    public java.lang.Object visit(ASTIfStatement node,
                                  java.lang.Object data)

  Specified by:
    `visit` in interface `ParserVisitor`

### visit

    public java.lang.Object visit(ASTIntegerLiteral node,
                                  java.lang.Object data)

  Specified by:
    `visit` in interface `ParserVisitor`

### visit

    public java.lang.Object visit(ASTJexlScript node,
                                  java.lang.Object data)

  Specified by:
    `visit` in interface `ParserVisitor`

### visit

    public java.lang.Object visit(ASTLENode node,
                                  java.lang.Object data)

  Specified by:
    `visit` in interface `ParserVisitor`

### visit

    public java.lang.Object visit(ASTLTNode node,
                                  java.lang.Object data)

  Specified by:
    `visit` in interface `ParserVisitor`

### visit

    public java.lang.Object visit(ASTMapEntry node,
                                  java.lang.Object data)

  Specified by:
    `visit` in interface `ParserVisitor`

### visit

    public java.lang.Object visit(ASTMapLiteral node,
                                  java.lang.Object data)

  Specified by:
    `visit` in interface `ParserVisitor`

### visit

    public java.lang.Object visit(ASTMethodNode node,
                                  java.lang.Object data)

  Specified by:
    `visit` in interface `ParserVisitor`

### visit

    public java.lang.Object visit(ASTConstructorNode node,
                                  java.lang.Object data)

  Specified by:
    `visit` in interface `ParserVisitor`

### visit

    public java.lang.Object visit(ASTFunctionNode node,
                                  java.lang.Object data)

  Specified by:
    `visit` in interface `ParserVisitor`

### visit

    public java.lang.Object visit(ASTModNode node,
                                  java.lang.Object data)

  Specified by:
    `visit` in interface `ParserVisitor`

### visit

    public java.lang.Object visit(ASTMulNode node,
                                  java.lang.Object data)

  Specified by:
    `visit` in interface `ParserVisitor`

### visit

    public java.lang.Object visit(ASTNENode node,
                                  java.lang.Object data)

  Specified by:
    `visit` in interface `ParserVisitor`

### visit

    public java.lang.Object visit(ASTNRNode node,
                                  java.lang.Object data)

  Specified by:
    `visit` in interface `ParserVisitor`

### visit

    public java.lang.Object visit(ASTNotNode node,
                                  java.lang.Object data)

  Specified by:
    `visit` in interface `ParserVisitor`

### visit

    public java.lang.Object visit(ASTNullLiteral node,
                                  java.lang.Object data)

  Specified by:
    `visit` in interface `ParserVisitor`

### visit

    public java.lang.Object visit(ASTOrNode node,
                                  java.lang.Object data)

  Specified by:
    `visit` in interface `ParserVisitor`

### visit

    public java.lang.Object visit(ASTReference node,
                                  java.lang.Object data)

  Specified by:
    `visit` in interface `ParserVisitor`

### visit

    public java.lang.Object visit(ASTSizeFunction node,
                                  java.lang.Object data)

  Specified by:
    `visit` in interface `ParserVisitor`

### visit

    public java.lang.Object visit(ASTSizeMethod node,
                                  java.lang.Object data)

  Specified by:
    `visit` in interface `ParserVisitor`

### visit

    public java.lang.Object visit(ASTStringLiteral node,
                                  java.lang.Object data)

  Specified by:
    `visit` in interface `ParserVisitor`

### visit

    public java.lang.Object visit(ASTTernaryNode node,
                                  java.lang.Object data)

  Specified by:
    `visit` in interface `ParserVisitor`

### visit

    public java.lang.Object visit(ASTTrueNode node,
                                  java.lang.Object data)

  Specified by:
    `visit` in interface `ParserVisitor`

### visit

    public java.lang.Object visit(ASTUnaryMinusNode node,
                                  java.lang.Object data)

  Specified by:
    `visit` in interface `ParserVisitor`

### visit

    public java.lang.Object visit(ASTWhileStatement node,
                                  java.lang.Object data)

  Specified by:
    `visit` in interface `ParserVisitor`

### getAttribute

    public java.lang.Object getAttribute(java.lang.Object object,
                                         java.lang.Object attribute)

  Gets an attribute of an object.

  Parameters:
    `object` - to retrieve value from
    `attribute` - the attribute of the object, e.g. an index (1, 0, 2) or key for a map
  Returns:
    the attribute value

### getAttribute

    protected java.lang.Object getAttribute(java.lang.Object object,
                                            java.lang.Object attribute,
                                            JexlNode node)

  Gets an attribute of an object.

  Parameters:
    `object` - to retrieve value from
    `attribute` - the attribute of the object, e.g. an index (1, 0, 2) or key for a map
    `node` - the node that evaluated as the object
  Returns:
    the attribute value

### setAttribute

    public void setAttribute(java.lang.Object object,
                             java.lang.Object attribute,
                             java.lang.Object value)

  Sets an attribute of an object.

  Parameters:
    `object` - to set the value to
    `attribute` - the attribute of the object, e.g. an index (1, 0, 2) or key for a map
    `value` - the value to assign to the object's attribute

### setAttribute

    protected void setAttribute(java.lang.Object object,
                                java.lang.Object attribute,
                                java.lang.Object value,
                                JexlNode node)

  Sets an attribute of an object.

  Parameters:
    `object` - to set the value to
    `attribute` - the attribute of the object, e.g. an index (1, 0, 2) or key for a map
    `value` - the value to assign to the object's attribute
    `node` - the node that evaluated as the object

### visit

    public java.lang.Object visit(SimpleNode node,
                                  java.lang.Object data)

  Unused, satisfy ParserVisitor interface.

  Specified by:
    `visit` in interface `ParserVisitor`
  Parameters:
    `node` - a node
    `data` - the data
  Returns:
    does not return

### visit

    public java.lang.Object visit(ASTAmbiguous node,
                                  java.lang.Object data)

  Unused, should throw in Parser.

  Specified by:
    `visit` in interface `ParserVisitor`
  Parameters:
    `node` - a node
    `data` - the data
  Returns:
    does not return

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright © 2001-2010 The Apache Software Foundation. All Rights Reserved.