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