01: package org.drools.base.mvel;
02:
03: import java.io.Serializable;
04:
05: import org.drools.WorkingMemory;
06: import org.drools.rule.Declaration;
07: import org.drools.spi.EvalExpression;
08: import org.drools.spi.Tuple;
09: import org.mvel.MVEL;
10:
11: public class MVELEvalExpression implements EvalExpression, Serializable {
12:
13: private static final long serialVersionUID = 400L;
14:
15: private final Serializable expr;
16: private final DroolsMVELFactory factory;
17:
18: public MVELEvalExpression(final Serializable expr,
19: final DroolsMVELFactory factory) {
20: this .expr = expr;
21: this .factory = factory;
22: }
23:
24: public boolean evaluate(final Tuple tuple,
25: final Declaration[] requiredDeclarations,
26: final WorkingMemory workingMemory) throws Exception {
27: this .factory.setContext(tuple, null, null, workingMemory, null);
28: final Boolean result = (Boolean) MVEL.executeExpression(
29: this .expr, new Object(), this.factory);
30: return result.booleanValue();
31: }
32:
33: }
|