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.PredicateExpression;
08: import org.drools.spi.Tuple;
09: import org.mvel.MVEL;
10:
11: public class MVELPredicateExpression implements PredicateExpression,
12: Serializable {
13: private static final long serialVersionUID = 400L;
14:
15: private final Serializable expr;
16: private final DroolsMVELFactory factory;
17:
18: public MVELPredicateExpression(final Serializable expr,
19: final DroolsMVELFactory factory) {
20: this .expr = expr;
21: this .factory = factory;
22: }
23:
24: public boolean evaluate(final Object object, final Tuple tuple,
25: final Declaration[] previousDeclarations,
26: final Declaration[] requiredDeclarations,
27: final WorkingMemory workingMemory) throws Exception {
28: this .factory.setContext(tuple, null, object, workingMemory,
29: null);
30: final Boolean result = (Boolean) MVEL.executeExpression(
31: this.expr, object, this.factory);
32: return result.booleanValue();
33: }
34:
35: }
|