View Javadoc

1   /**
2    * Copyright 2005-2012 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.krad.datadictionary.validation.result;
17  
18  import org.kuali.rice.krad.datadictionary.validation.AttributeValueReader;
19  import org.kuali.rice.krad.datadictionary.validation.capability.Constrainable;
20  import org.kuali.rice.krad.datadictionary.validation.constraint.Constraint;
21  
22  import java.util.Arrays;
23  import java.util.Collections;
24  import java.util.List;
25  
26  /**
27   * 
28   * @author Kuali Rice Team (rice.collab@kuali.org)
29   */
30  public class ProcessorResult {
31  
32  	private final transient List<Constraint> constraints;
33  	private final transient Constrainable definition;
34  	private final transient AttributeValueReader attributeValueReader;
35  	
36  	private final List<ConstraintValidationResult> constraintValidationResults;
37  	
38  	public ProcessorResult(ConstraintValidationResult constraintValidationResult) {
39  		this(constraintValidationResult, null, null);
40  	}
41  	
42  	public ProcessorResult(ConstraintValidationResult constraintValidationResult, Constrainable definition, AttributeValueReader attributeValueReader, Constraint... constraints) {
43  		this.constraintValidationResults = Collections.singletonList(constraintValidationResult);
44  		this.definition = definition;
45  		this.attributeValueReader = attributeValueReader;
46  		this.constraints = Arrays.asList(constraints);
47  	}
48      
49      public ProcessorResult(ConstraintValidationResult constraintValidationResult, Constrainable definition, AttributeValueReader attributeValueReader, List<Constraint> constraints) {
50          this.constraintValidationResults = Collections.singletonList(constraintValidationResult);
51          this.definition = definition;
52          this.attributeValueReader = attributeValueReader;
53          this.constraints = constraints;
54      }
55  	
56  	public ProcessorResult(List<ConstraintValidationResult> constraintValidationResults) {
57  		this(constraintValidationResults, null, null);
58  	}
59  	
60  	public ProcessorResult(List<ConstraintValidationResult> constraintValidationResults, Constrainable definition, AttributeValueReader attributeValueReader, Constraint... constraints) {
61  		this.constraintValidationResults = constraintValidationResults;
62  		this.definition = definition;
63  		this.attributeValueReader = attributeValueReader;
64  		this.constraints = Arrays.asList(constraints);
65  	}
66  	
67  	public boolean isSingleConstraintResult() {
68  		return this.constraintValidationResults.size() == 1;
69  	}
70  
71  	public boolean isDefinitionProvided() {
72  		return definition != null;
73  	}
74  	
75  	public boolean isAttributeValueReaderProvided() {
76  		return attributeValueReader != null;
77  	}
78  	
79  	public ConstraintValidationResult getFirstConstraintValidationResult() {
80  		return this.constraintValidationResults.isEmpty() ? null : this.constraintValidationResults.get(0);
81  	}
82  	
83  	/**
84  	 * @return the constraintValidationResults
85  	 */
86  	public List<ConstraintValidationResult> getConstraintValidationResults() {
87  		return this.constraintValidationResults;
88  	}
89  
90  	/**
91  	 * @return the definition
92  	 */
93  	public Constrainable getDefinition() {
94  		return this.definition;
95  	}
96  
97  	/**
98  	 * @return the attributeValueReader
99  	 */
100 	public AttributeValueReader getAttributeValueReader() {
101 		return this.attributeValueReader;
102 	}
103 
104 	/**
105 	 * @return the constraints
106 	 */
107 	public List<Constraint> getConstraints() {
108 		return this.constraints;
109 	}
110 		
111 }