1 | |
package org.kuali.rice.krms.framework.engine; |
2 | |
|
3 | |
import java.util.List; |
4 | |
|
5 | |
import org.kuali.rice.krms.api.ExecutionEnvironment; |
6 | |
import org.kuali.rice.krms.api.Rule; |
7 | |
|
8 | |
public class AgendaTree { |
9 | |
|
10 | |
private List<Rule> rules; |
11 | |
private AgendaTree ifTrue; |
12 | |
private AgendaTree ifFalse; |
13 | |
private AgendaTree afterAgenda; |
14 | |
|
15 | 0 | public AgendaTree(List<Rule> rules, AgendaTree ifTrue, AgendaTree ifFalse, AgendaTree afterAgenda) { |
16 | 0 | this.rules = rules; |
17 | 0 | this.ifTrue = ifTrue; |
18 | 0 | this.ifFalse = ifFalse; |
19 | 0 | this.afterAgenda = afterAgenda; |
20 | 0 | if (rules.isEmpty()) { |
21 | 0 | throw new IllegalArgumentException("The rule list must contain at least one rule, but list is empty."); |
22 | |
} |
23 | 0 | } |
24 | |
|
25 | |
public void execute(ExecutionEnvironment environment) { |
26 | 0 | boolean lastRuleResult = true; |
27 | 0 | for (Rule rule : rules) { |
28 | 0 | lastRuleResult = rule.evaluate(environment); |
29 | |
} |
30 | 0 | if (lastRuleResult && ifTrue != null) { |
31 | 0 | ifTrue.execute(environment); |
32 | |
} |
33 | 0 | if (!lastRuleResult && ifFalse != null) { |
34 | 0 | ifFalse.execute(environment); |
35 | |
} |
36 | 0 | if (afterAgenda != null) { |
37 | 0 | afterAgenda.execute(environment); |
38 | |
} |
39 | 0 | } |
40 | |
|
41 | |
} |