public class ExpressionEvaluator
extends java.lang.Object
In this way you can easily evaluate JoSQL expressions against objects.
Usage:
Use the static methods to evaluate the expression in one call, for instance to find out details about a file:
String exp = "path + ', size: ' + formatNumber(length) + ', last modified: ' + formatDate(lastModified)
String details = ExpressionEvaluator.getValue (exp, new File ('/home/me/myfile.txt'));
| Constructor and Description |
|---|
ExpressionEvaluator(java.lang.String exp,
java.lang.Class cl)
Create a new expression evaluator.
|
ExpressionEvaluator(java.lang.String exp,
java.lang.Class cl,
java.util.List fhs)
Create a new expression evaluator.
|
| Modifier and Type | Method and Description |
|---|---|
Query |
getQuery()
Get the query associated with the expression, use this to setup
bind variables, function handlers and so on, which of course must
be setup prior to evaluating the expression.
|
java.lang.Object |
getValue(java.lang.Object o)
Evaluate the expression against the object passed in and return the
value.
|
static java.lang.Object |
getValue(java.lang.String exp,
java.lang.Object o)
Evaluate the expression against the object passed in and return the
value.
|
java.util.List |
getValues(java.util.List l)
Evaluate the expression against the list of objects passed in and
return the value.
|
static java.util.List |
getValues(java.lang.String exp,
java.util.List l)
Evaluate the expression against the list of objects passed in and
return the value.
|
boolean |
isTrue(java.lang.Object o)
Evaluate the expression against the object passed in.
|
static boolean |
isTrue(java.lang.String exp,
java.lang.Object o)
Evaluate the expression against the object passed in.
|
public ExpressionEvaluator(java.lang.String exp,
java.lang.Class cl)
throws QueryParseException
exp - The expression to be evaluated.cl - The class of the object(s) that the expression will be
evaluated against.QueryParseException - If the expression cannot be parsed.public ExpressionEvaluator(java.lang.String exp,
java.lang.Class cl,
java.util.List fhs)
throws QueryParseException
exp - The expression to be evaluated.cl - The class of the object(s) that the expression will be
evaluated against.fhs - A list of function handlers that contain functions that will
be used by the expression, can be null.QueryParseException - If the expression cannot be parsed.public Query getQuery()
public boolean isTrue(java.lang.Object o)
throws QueryExecutionException
o - The object to evaluate the expression against.QueryExecutionException - If the expression cannot be executed.public java.util.List getValues(java.util.List l)
throws QueryExecutionException
l - The list of objects to evaluate the expression against.QueryExecutionException - If the expression cannot be executed.public java.lang.Object getValue(java.lang.Object o)
throws QueryExecutionException
o - The object to evaluate the expression against.QueryExecutionException - If the expression cannot be executed.public static boolean isTrue(java.lang.String exp,
java.lang.Object o)
throws QueryParseException,
QueryExecutionException
exp - A string representation of the expression to evaluate.o - The object to evaluate the expression against.QueryParseException - If the expression cannot be parsed.QueryExecutionException - If the expression cannot be executed.public static java.util.List getValues(java.lang.String exp,
java.util.List l)
throws QueryParseException,
QueryExecutionException
exp - A string representation of the expression to evaluate.l - The list of objects to evaluate the expression against.QueryParseException - If the expression cannot be parsed.QueryExecutionException - If the expression cannot be executed.public static java.lang.Object getValue(java.lang.String exp,
java.lang.Object o)
throws QueryParseException,
QueryExecutionException
exp - A string representation of the expression to evaluate.o - The object to evaluate the expression against.QueryParseException - If the expression cannot be parsed.QueryExecutionException - If the expression cannot be executed.