Class Expression<T>

  • Type Parameters:
    T - expected result type
    Direct Known Subclasses:
    LeftValueExpression

    public class Expression<T>
    extends Object
    An Unified Expression Language expression. Creating an expression is the equivalent to compiling it. Once created, an expression can be evaluated within a supplied scope. An expression can safely be evaluated concurrently in multiple threads.
    • Field Detail

      • valueExpression

        protected final de.odysseus.el.TreeValueExpression valueExpression
        The underlying EL expression that this object represents.
    • Constructor Detail

      • Expression

        protected Expression​(String expression,
                             Class<T> expectedType,
                             Bindings initialBindings)
                      throws ExpressionException
        Constructs an expression for later evaluation.
        Parameters:
        expression - the expression to parse.
        expectedType - The expected result type of the expression.
        initialBindings - The initial bindings used when evaluated this expression
        Throws:
        ExpressionException - if the expression was not syntactically correct.
    • Method Detail

      • valueOf

        public static <T> Expression<T> valueOf​(String expression,
                                                Class<T> expectedType)
                                         throws ExpressionException
        Factory method to create an Expression.
        Type Parameters:
        T - expected result type
        Parameters:
        expression - The expression to parse.
        expectedType - The expected result type of the expression.
        Returns:
        An expression based on the given string.
        Throws:
        ExpressionException - if the expression was not syntactically correct.
      • valueOf

        public static <T> Expression<T> valueOf​(String expression,
                                                Class<T> expectedType,
                                                Bindings initialBindings)
                                         throws ExpressionException
        Factory method to create an Expression.
        Type Parameters:
        T - expected result type
        Parameters:
        expression - The expression to parse.
        expectedType - The expected result type of the expression.
        initialBindings - The initial bindings used when evaluated this expression
        Returns:
        An expression based on the given string.
        Throws:
        ExpressionException - if the expression was not syntactically correct.
      • evalAsync

        public Promise<T,​NeverThrowsException> evalAsync​(Bindings bindings)
        Evaluates asynchronously the expression with the specified bindings and returns a promise of the resulting object if it matches the specified type, or a promise completed with null if it does not resolve or match.

        If this expression requires asynchronous processing (declared using "#{...}"), then the evaluation is triggered on completion of the Bindings.

        Otherwise it's evaluated immediately.

        Parameters:
        bindings - the bindings to evaluate the expression within.
        Returns:
        a promise containing the result of the expression evaluation, or containing null if it does not resolve or match the type.
      • eval

        public T eval​(Bindings bindings)
        Evaluates the expression within the specified bindings and returns the resulting object if it matches the specified type, or null if it does not resolve or match.
        Parameters:
        bindings - the bindings to evaluate the expression within.
        Returns:
        the result of the expression evaluation, or null if it does not resolve or match the type.
      • eval

        public T eval()
        Convenient method to eval an Expression that does not need a scope.
        Returns:
        the result of the expression evaluation, or null if it does not resolve or match the type.
      • toString

        public String toString()
        Returns the original string used to create this expression, unmodified.

        Note to implementors: That returned value must be usable in Expression.valueOf() to create an equivalent Expression(somehow cloning this instance)

        Overrides:
        toString in class Object
        Returns:
        The original string used to create this expression.