Package org.forgerock.openig.el
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 protected javax.el.ValueExpression
valueExpression
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
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description T
eval()
Convenient method to eval an Expression that does not need a scope.T
eval(Bindings bindings)
Evaluates the expression within the specified bindings and returns the resulting object if it matches the specified type, ornull
if it does not resolve or match.String
toString()
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.
-
-
-
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.
-
eval
public T eval(Bindings bindings)
Evaluates the expression within the specified bindings and returns the resulting object if it matches the specified type, ornull
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)
-
-