001 /**
002 * Copyright 2005-2012 The Kuali Foundation
003 *
004 * Licensed under the Educational Community License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.opensource.org/licenses/ecl2.php
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016 package org.kuali.rice.kew.rule;
017
018 import java.util.ArrayList;
019 import java.util.Collections;
020 import java.util.List;
021
022 import org.apache.commons.lang.builder.ToStringBuilder;
023
024 /**
025 * Result of a {@link RuleExpression} evaluation
026 * @author Kuali Rice Team (rice.collab@kuali.org)
027 */
028 public class RuleExpressionResult {
029 /**
030 * The rule whose evaluation yielded this result
031 */
032 private final Rule rule;
033 /**
034 * Whether the expression succeeded
035 */
036 private final boolean success;
037 /**
038 * Any responsibilities generated from a successful evaluation
039 */
040 private final List<org.kuali.rice.kew.api.rule.RuleResponsibility> responsibilities;
041
042 /**
043 * Constructs a rule expression result with a success indicator but no responsibilities
044 * @param success whether the expression succeeded
045 */
046 public RuleExpressionResult(Rule rule, boolean success) {
047 this.rule = rule;
048 this.success = success;
049 this.responsibilities = null;
050 }
051
052 /**
053 * Constructs a rule expression result with both a success indicator and a list of responsibilities
054 * @param success whether the expression succeeded
055 * @param responsibilities any responsibilities generated from a successful evaluation
056 */
057 public RuleExpressionResult(Rule rule, boolean success, List<org.kuali.rice.kew.api.rule.RuleResponsibility> responsibilities) {
058 this.rule = rule;
059 this.success = success;
060 this.responsibilities = responsibilities;
061 }
062
063 /**
064 * Constructs a rule expression result with both a success indicator and a single responsibilities
065 * @param success whether the expression succeeded
066 * @param responsibility a single responsibility generated from a successful evaluation
067 */
068 public RuleExpressionResult(Rule rule, boolean success, org.kuali.rice.kew.api.rule.RuleResponsibility responsibility) {
069 this.rule = rule;
070 this.success = success;
071 if (responsibility != null) {
072 responsibilities = Collections.singletonList(responsibility);
073 } else {
074 responsibilities = null;
075 }
076 }
077
078 /**
079 * @return the rule that this expression result is associated with
080 */
081 public Rule getRule() {
082 return rule;
083 }
084
085 /**
086 * @return whether the evaluation was successful
087 */
088 public boolean isSuccess() {
089 return success;
090 }
091
092 /**
093 * @return any responsibilities generated from a successful evaluation
094 */
095 public List<org.kuali.rice.kew.api.rule.RuleResponsibility> getResponsibilities() {
096 return responsibilities;
097 }
098
099 public String toString() {
100 return new ToStringBuilder(this).append("rule", rule)
101 .append("success", success)
102 .append("responsibilities", responsibilities).toString();
103 }
104 }