Class TemplateEngine.TemplateExpression

java.lang.Object
org.apache.commons.jexl3.internal.TemplateEngine.TemplateExpression
All Implemented Interfaces:
JxltEngine.Expression
Direct Known Subclasses:
TemplateEngine.CompositeExpression, TemplateEngine.ConstantExpression, TemplateEngine.JexlBasedExpression
Enclosing class:
TemplateEngine

abstract class TemplateEngine.TemplateExpression extends Object implements JxltEngine.Expression
The abstract base class for all unified expressions, immediate '${...}' and deferred '#{...}'.
  • Field Details

  • Constructor Details

    • TemplateExpression

      TemplateExpression(TemplateEngine.TemplateExpression src)
      Creates an TemplateExpression.
      Parameters:
      src - the source TemplateExpression if any
  • Method Details

    • isImmediate

      public boolean isImmediate()
      Description copied from interface: JxltEngine.Expression
      Checks whether this expression is immediate.
      Specified by:
      isImmediate in interface JxltEngine.Expression
      Returns:
      true if immediate, false otherwise
    • isDeferred

      public final boolean isDeferred()
      Description copied from interface: JxltEngine.Expression
      Checks whether this expression is deferred.
      Specified by:
      isDeferred in interface JxltEngine.Expression
      Returns:
      true if deferred, false otherwise
    • getType

      abstract TemplateEngine.ExpressionType getType()
      Gets this TemplateExpression type.
      Returns:
      its type
    • getInfo

      JexlInfo getInfo()
      Returns:
      the info
    • toString

      public final String toString()
      Description copied from interface: JxltEngine.Expression
      Formats this expression, adding its source string representation in comments if available: 'expression /*= source *\/'' .
      Specified by:
      toString in interface JxltEngine.Expression
      Overrides:
      toString in class Object
      Returns:
      the formatted expression string
    • asString

      public String asString()
      Description copied from interface: JxltEngine.Expression
      Generates this expression's string representation.
      Specified by:
      asString in interface JxltEngine.Expression
      Returns:
      the string representation
    • getVariables

      public Set<List<String>> getVariables()
      Description copied from interface: JxltEngine.Expression
      Gets the list of variables accessed by this expression.

      This method will visit all nodes of the sub-expressions and extract all variables whether they are written in 'dot' or 'bracketed' notation. (a.b is equivalent to a['b']).

      Specified by:
      getVariables in interface JxltEngine.Expression
      Returns:
      the set of variables, each as a list of strings (ant-ish variables use more than 1 string) or the empty set if no variables are used
    • getSource

      public final TemplateEngine.TemplateExpression getSource()
      Description copied from interface: JxltEngine.Expression
      Retrieves this expression's source expression.

      If this expression was prepared, this allows to retrieve the original expression that lead to it.

      Other expressions return themselves.

      Specified by:
      getSource in interface JxltEngine.Expression
      Returns:
      the source expression
    • getVariables

      protected void getVariables(Engine.VarCollector collector)
      Fills up the list of variables accessed by this unified expression.
      Parameters:
      collector - the variable collector
    • prepare

      public final TemplateEngine.TemplateExpression prepare(JexlContext context)
      Description copied from interface: JxltEngine.Expression
      Evaluates the immediate sub-expressions.

      When the expression is dependant upon immediate and deferred sub-expressions, evaluates the immediate sub-expressions with the context passed as parameter and returns this expression deferred form.

      In effect, this binds the result of the immediate sub-expressions evaluation in the context, allowing to differ evaluation of the remaining (deferred) expression within another context. This only has an effect to nested and composite expressions that contain differed and immediate sub-expressions.

      If the underlying JEXL engine is silent, errors will be logged through its logger as warning.*

      Specified by:
      prepare in interface JxltEngine.Expression
      Parameters:
      context - the context to use for immediate expression evaluations
      Returns:
      an JxltEngine.Expression or null if an error occurs and the JexlEngine is running in silent mode
    • prepare

      protected final TemplateEngine.TemplateExpression prepare(JexlContext context, Frame frame, JexlOptions opts)
      Prepares this expression.
      Parameters:
      frame - the frame storing parameters and local variables
      context - the context storing global variables
      Returns:
      the expression value
      Throws:
      JexlException
    • prepare

      protected TemplateEngine.TemplateExpression prepare(Interpreter interpreter)
      Prepares a sub-expression for interpretation.
      Parameters:
      interpreter - a JEXL interpreter
      Returns:
      a prepared unified expression
      Throws:
      JexlException - (only for nested and composite)
    • evaluate

      public final Object evaluate(JexlContext context)
      Description copied from interface: JxltEngine.Expression
      Evaluates this expression.

      If the underlying JEXL engine is silent, errors will be logged through its logger as warning.

      Specified by:
      evaluate in interface JxltEngine.Expression
      Parameters:
      context - the variable context
      Returns:
      the result of this expression evaluation or null if an error occurs and the JexlEngine is running in silent mode
    • options

      protected JexlOptions options(JexlContext context)
      The options to use during evaluation.
      Parameters:
      context - the context
      Returns:
      the options
    • evaluate

      protected final Object evaluate(JexlContext context, Frame frame, JexlOptions options)
      Evaluates this expression.
      Parameters:
      frame - the frame storing parameters and local variables
      context - the context storing global variables
      Returns:
      the expression value
      Throws:
      JexlException
    • evaluate

      protected abstract Object evaluate(Interpreter interpreter)
      Interprets a sub-expression.
      Parameters:
      interpreter - a JEXL interpreter
      Returns:
      the result of interpretation
      Throws:
      JexlException - (only for nested and composite)