01: package org.drools.base.mvel;
02:
03: import java.io.Serializable;
04:
05: import org.drools.WorkingMemory;
06: import org.drools.spi.Salience;
07: import org.drools.spi.Tuple;
08: import org.mvel.MVEL;
09:
10: public class MVELSalienceExpression implements Salience, Serializable {
11:
12: private static final long serialVersionUID = 400L;
13:
14: private final Serializable expr;
15: private final DroolsMVELFactory factory;
16:
17: public MVELSalienceExpression(final Serializable expr,
18: final DroolsMVELFactory factory) {
19: this .expr = expr;
20: this .factory = factory;
21: }
22:
23: public int getValue(final Tuple tuple,
24: final WorkingMemory workingMemory) {
25: this .factory.setContext(tuple, null, null, workingMemory, null);
26: return ((Integer) MVEL.executeExpression(this.expr,
27: this.factory)).intValue();
28: }
29:
30: }
|