Class Expression<T>

java.lang.Object
org.forgerock.openig.el.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 Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
    The key of the Clock when it is added to bindings.
    protected final de.odysseus.el.TreeValueExpression
    The underlying EL expression that this object represents.
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    Expression(String expression, Class<T> expectedType, Bindings initialBindings)
    Constructs an expression for later evaluation.
  • Method Summary

    Modifier and Type
    Method
    Description
    Convenient method to eval an Expression that does not need a scope.
    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.
    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.
    Returns the original string used to create this expression, unmodified.
    static <T> Expression<T>
    valueOf(String expression, Class<T> expectedType)
    Factory method to create an Expression.
    static <T> Expression<T>
    valueOf(String expression, Class<T> expectedType, Bindings initialBindings)
    Factory method to create an Expression.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

    • CLOCK_BINDING_KEY

      public static final String CLOCK_BINDING_KEY
      The key of the Clock when it is added to bindings.
      See Also:
    • valueExpression

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

    • 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 Details

    • 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.