1 /** 2 * Copyright 2005-2016 The Kuali Foundation 3 * 4 * Licensed under the Educational Community License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.opensource.org/licenses/ecl2.php 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 package org.kuali.rice.kew.rule; 17 18 import java.util.ArrayList; 19 import java.util.Collections; 20 import java.util.List; 21 22 import org.apache.commons.lang.builder.ToStringBuilder; 23 24 /** 25 * Result of a {@link RuleExpression} evaluation 26 * @author Kuali Rice Team (rice.collab@kuali.org) 27 */ 28 public class RuleExpressionResult { 29 /** 30 * The rule whose evaluation yielded this result 31 */ 32 private final Rule rule; 33 /** 34 * Whether the expression succeeded 35 */ 36 private final boolean success; 37 /** 38 * Any responsibilities generated from a successful evaluation 39 */ 40 private final List<org.kuali.rice.kew.api.rule.RuleResponsibility> responsibilities; 41 42 /** 43 * Constructs a rule expression result with a success indicator but no responsibilities 44 * @param success whether the expression succeeded 45 */ 46 public RuleExpressionResult(Rule rule, boolean success) { 47 this.rule = rule; 48 this.success = success; 49 this.responsibilities = null; 50 } 51 52 /** 53 * Constructs a rule expression result with both a success indicator and a list of responsibilities 54 * @param success whether the expression succeeded 55 * @param responsibilities any responsibilities generated from a successful evaluation 56 */ 57 public RuleExpressionResult(Rule rule, boolean success, List<org.kuali.rice.kew.api.rule.RuleResponsibility> responsibilities) { 58 this.rule = rule; 59 this.success = success; 60 this.responsibilities = responsibilities; 61 } 62 63 /** 64 * Constructs a rule expression result with both a success indicator and a single responsibilities 65 * @param success whether the expression succeeded 66 * @param responsibility a single responsibility generated from a successful evaluation 67 */ 68 public RuleExpressionResult(Rule rule, boolean success, org.kuali.rice.kew.api.rule.RuleResponsibility responsibility) { 69 this.rule = rule; 70 this.success = success; 71 if (responsibility != null) { 72 responsibilities = Collections.singletonList(responsibility); 73 } else { 74 responsibilities = null; 75 } 76 } 77 78 /** 79 * @return the rule that this expression result is associated with 80 */ 81 public Rule getRule() { 82 return rule; 83 } 84 85 /** 86 * @return whether the evaluation was successful 87 */ 88 public boolean isSuccess() { 89 return success; 90 } 91 92 /** 93 * @return any responsibilities generated from a successful evaluation 94 */ 95 public List<org.kuali.rice.kew.api.rule.RuleResponsibility> getResponsibilities() { 96 return responsibilities; 97 } 98 99 public String toString() { 100 return new ToStringBuilder(this).append("rule", rule) 101 .append("success", success) 102 .append("responsibilities", responsibilities).toString(); 103 } 104 }