Class Interpreter

    • Field Detail

      • logger

        protected final org.apache.commons.logging.Log logger
        The logger.
      • 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.
      • strict

        protected boolean strict
        Strict interpreter flag. Do not modify; will be made final/private in a later version.
      • silent

        protected boolean silent
        Silent intepreter flag. Do not modify; will be made final/private in a later version.
      • cache

        protected final boolean cache
        Cache executors.
      • registers

        protected java.lang.Object[] registers
        Registers or arguments.
      • EMPTY_PARAMS

        protected static final java.lang.Object[] EMPTY_PARAMS
        Empty parameters for method matching.
    • Constructor Detail

      • Interpreter

        @Deprecated
        public Interpreter​(JexlEngine jexl,
                           JexlContext aContext)
        Deprecated.
        Creates an interpreter.
        Parameters:
        jexl - the engine creating this interpreter
        aContext - the context to evaluate expression
      • Interpreter

        public Interpreter​(JexlEngine jexl,
                           JexlContext aContext,
                           boolean strictFlag,
                           boolean silentFlag)
        Creates an interpreter.
        Parameters:
        jexl - the engine creating this interpreter
        aContext - the context to evaluate expression
        strictFlag - whether this interpreter runs in strict mode
        silentFlag - whether this interpreter runs in silent mode
        Since:
        2.1
      • Interpreter

        protected Interpreter​(Interpreter base)
        Copy constructor.
        Parameters:
        base - the base to copy
        Since:
        2.1
    • Method Detail

      • setStrict

        @Deprecated
        public void setStrict​(boolean flag)
        Deprecated.
        Do not use; will be removed in a later version
        Sets whether this interpreter considers unknown variables, methods and constructors as errors.
        Parameters:
        flag - true for strict, false for lenient
        Since:
        2.1
      • setSilent

        @Deprecated
        public void setSilent​(boolean flag)
        Deprecated.
        Do not use; will be removed in a later version
        Sets whether this interpreter throws JexlException when encountering errors.
        Parameters:
        flag - true for silent, false for verbose
      • isStrict

        public boolean isStrict()
        Checks whether this interpreter considers unknown variables, methods and constructors as errors.
        Returns:
        true if strict, false otherwise
        Since:
        2.1
      • isSilent

        public boolean isSilent()
        Checks whether this interpreter throws JexlException when encountering errors.
        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.
      • setRegisters

        @Deprecated
        protected void setRegisters​(java.lang.Object... theRegisters)
        Deprecated.
        Sets this interpreter registers for bean access/assign expressions.

        Use setFrame(...) instead.

        Parameters:
        theRegisters - the array of registers
      • setFrame

        protected void setFrame​(JexlEngine.Frame frame)
        Sets this interpreter parameters and arguments.
        Parameters:
        frame - the calling frame
        Since:
        2.1
      • 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
      • isCancelled

        protected boolean isCancelled()
        Checks whether this interpreter execution was cancelled due to thread interruption.
        Returns:
        true if cancelled, false otherwise
        Since:
        2.1
      • 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

        @Deprecated
        public java.lang.Object visit​(ASTFloatLiteral node,
                                      java.lang.Object data)
        Deprecated.
        Do not use
      • visit

        @Deprecated
        public java.lang.Object visit​(ASTIntegerLiteral node,
                                      java.lang.Object data)
        Deprecated.
        Do not use
      • 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