|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object net.sf.jec.ExpressionEval
ExpressionEval is an expression evaluator.
It works caching class+expr pairs with their associated compiled operator.
Whenever someone calls ExpressionEval for evaluating a 'get' or 'set'
expression on a context 'ctx', it checks for the pair (cxt.getClass() + expr)
in the operator cache. If there's nothing, the expression is compiled on the
context using a ExpressionCompiler
and a new entry is created within
the cache.
So, ExpressionEval grows over the time, filled with pairs of class plus expression, and its associated operator trees.
WARNING:Be careful with using ExpressionEval as a singleton in your
application. For expressions that evaluate on fixed clases, an expression
evaluated on a given context will have always the same operator tree. But
that isn't true for classes with dynamic properties, as those returning
java.util.Map
. Anyway, I'm not absolutely sure about this and
it would be great to have a criteria for choosing the singleton option when
possible.
Constructor Summary | |
ExpressionEval(boolean throwExceptions)
Creates a new instance of ExpressionEval |
|
ExpressionEval(ExpressionCompiler expComp)
Creates a new instance of ExpressionEval |
Method Summary | |
void |
clearOperatorCache()
Removes all stored operators, so the garbage collector can collect them. |
void |
clearOperatorCache(java.lang.Class clazz)
Removes all stored operator for objects of the given class |
java.lang.Object |
get(java.lang.Object ctx,
java.lang.String expr)
Evaluates expression expr over the context ctx |
Operator |
getCachedOperator(java.lang.Object ctx,
java.lang.String expr)
This method completely encapsulates the internal data representation. |
static ExpressionEval |
getDefaultInstance(boolean throwExceptions)
Returns a default expression evaluator that uses a default expression compiler (see ExpressionCompiler.getDefaultInstance(boolean) ). |
void |
set(java.lang.Object ctx,
java.lang.String expr,
java.lang.Object value)
Sets the expression expr over the context ctx
to the specified value value , so
assert(value==get(ctx, expr)) |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public ExpressionEval(boolean throwExceptions)
throwExceptions
- True if evaluation exceptions are desirablepublic ExpressionEval(ExpressionCompiler expComp)
expComp
- The ExpressionCompiler
used to compile
expressions into Operator
objects.Method Detail |
public static ExpressionEval getDefaultInstance(boolean throwExceptions)
ExpressionCompiler.getDefaultInstance(boolean)
).
throwExceptions
-
public java.lang.Object get(java.lang.Object ctx, java.lang.String expr) throws ParseException, EvaluationException
expr
over the context ctx
ctx
- Expression contextexpr
- Expression to evaluate
ParseException
- Thrown when the expression is not well formed
EvaluationException
- Thrown when, although the expression is
valid, the evaluation cannot be performed.public void set(java.lang.Object ctx, java.lang.String expr, java.lang.Object value) throws ParseException, EvaluationException
expr
over the context ctx
to the specified value value
, so
assert(value==get(ctx, expr))
ctx
- Expression contextexpr
- Expression to evaluatevalue
- New expression value
ParseException
- Thrown when the expression is not well formed
EvaluationException
- Thrown when, although the expression is
valid, the evaluation cannot be performed.public Operator getCachedOperator(java.lang.Object ctx, java.lang.String expr) throws ParseException
f(ctx, expr) --> Operator
ParseException
public void clearOperatorCache()
public void clearOperatorCache(java.lang.Class clazz)
clazz
- The class whose Operator objects must be cleared
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |