1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.krms.framework.engine;
17
18 import java.util.List;
19
20 import org.kuali.rice.krms.api.engine.ExecutionEnvironment;
21 import org.kuali.rice.krms.api.engine.ResultEvent;
22 import org.kuali.rice.krms.framework.engine.result.BasicResult;
23
24 public class BasicRule implements Rule {
25 private static final ResultLogger LOG = ResultLogger.getInstance();
26
27 private String name;
28 private Proposition proposition;
29 private List<Action> actions;
30
31 public BasicRule(String name, Proposition proposition, List<Action> actions) {
32 if (proposition == null) {
33 throw new IllegalArgumentException("Proposition cannot be null.");
34 }
35 this.name = name;
36 this.proposition = proposition;
37 this.actions = actions;
38 }
39
40 public BasicRule(Proposition proposition, List<Action> actions) {
41 this(null, proposition, actions);
42 }
43
44 @Override
45 public boolean evaluate(ExecutionEnvironment environment) {
46 boolean result = proposition.evaluate(environment).getResult();
47 if (actions != null) {
48 for (Action action : actions) {
49 if (shouldExecuteAction(result)) {
50 action.execute(environment);
51 }
52 }
53 }
54 if (LOG.isEnabled(environment)){
55 LOG.logResult(new BasicResult(ResultEvent.RuleEvaluated, this, environment, result));
56 }
57 return result;
58 }
59
60 protected boolean shouldExecuteAction(boolean ruleExecutionResult) {
61 return ruleExecutionResult;
62 }
63
64 public String getName() {
65 return name;
66 }
67
68 public String toString(){
69 return name;
70 }
71 }