| 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 | 0 | private static final ResultLogger LOG = ResultLogger.getInstance(); |
| 26 | |
|
| 27 | |
private String name; |
| 28 | |
private Proposition proposition; |
| 29 | |
private List<Action> actions; |
| 30 | |
|
| 31 | 0 | public BasicRule(String name, Proposition proposition, List<Action> actions) { |
| 32 | 0 | if (proposition == null) { |
| 33 | 0 | throw new IllegalArgumentException("Proposition cannot be null."); |
| 34 | |
} |
| 35 | 0 | this.name = name; |
| 36 | 0 | this.proposition = proposition; |
| 37 | 0 | this.actions = actions; |
| 38 | 0 | } |
| 39 | |
|
| 40 | |
public BasicRule(Proposition proposition, List<Action> actions) { |
| 41 | 0 | this(null, proposition, actions); |
| 42 | 0 | } |
| 43 | |
|
| 44 | |
@Override |
| 45 | |
public boolean evaluate(ExecutionEnvironment environment) { |
| 46 | 0 | boolean result = proposition.evaluate(environment).getResult(); |
| 47 | 0 | if (actions != null) { |
| 48 | 0 | for (Action action : actions) { |
| 49 | 0 | if (shouldExecuteAction(result)) { |
| 50 | 0 | action.execute(environment); |
| 51 | |
} |
| 52 | |
} |
| 53 | |
} |
| 54 | 0 | if (LOG.isEnabled(environment)){ |
| 55 | 0 | LOG.logResult(new BasicResult(ResultEvent.RuleEvaluated, this, environment, result)); |
| 56 | |
} |
| 57 | 0 | return result; |
| 58 | |
} |
| 59 | |
|
| 60 | |
protected boolean shouldExecuteAction(boolean ruleExecutionResult) { |
| 61 | 0 | return ruleExecutionResult; |
| 62 | |
} |
| 63 | |
|
| 64 | |
public String getName() { |
| 65 | 0 | return name; |
| 66 | |
} |
| 67 | |
|
| 68 | |
public String toString(){ |
| 69 | 0 | return name; |
| 70 | |
} |
| 71 | |
} |