View Javadoc

1   /*
2    * Copyright 2010 The Kuali Foundation Licensed under the Educational Community License, Version 2.0 (the "License"); you may
3    * not use this file except in compliance with the License. You may obtain a copy of the License at
4    * http://www.osedu.org/licenses/ECL-2.0 Unless required by applicable law or agreed to in writing, software distributed
5    * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
6    * implied. See the License for the specific language governing permissions and limitations under the License.
7    */
8   package org.kuali.student.contract.model.test.source;
9   
10  import java.io.Serializable;
11  import java.util.List;
12  
13  import javax.xml.bind.annotation.XmlAccessType;
14  import javax.xml.bind.annotation.XmlAccessorType;
15  import javax.xml.bind.annotation.XmlAnyElement;
16  import javax.xml.bind.annotation.XmlElement;
17  import javax.xml.bind.annotation.XmlType;
18  
19  import org.kuali.student.contract.model.test.source.ModelBuilder;
20  import org.kuali.student.contract.model.test.source.ValidationResult;
21  import org.w3c.dom.Element;
22  
23  @XmlAccessorType(XmlAccessType.FIELD)
24  @XmlType(name = "ValidationResultInfo", propOrder = {"element", "level", "message", "_futureElements"})
25  public class ValidationResultInfo implements ValidationResult, Serializable {
26  
27      private static final long serialVersionUID = 1L;
28  
29      @XmlElement
30      private String element;
31      @XmlElement
32      private Integer level;
33      @XmlElement
34      private String message;
35      private transient Object invalidData;
36      @XmlAnyElement
37      private final List<Element> _futureElements;    
38  
39      private ValidationResultInfo() {
40          this.level = null;
41          this.message = null;
42          this.invalidData = null;
43          this._futureElements = null;
44      }
45  
46      private ValidationResultInfo(ValidationResult builder) {
47          this.level = builder.getLevel();
48          this.element = builder.getElement();
49          this.message = builder.getMessage();
50          this.invalidData = builder.getInvalidData();
51          this._futureElements = null;
52      }
53  
54      /**
55       * Convenience method. Returns true if getErrorLevel() == ErrorLevel.OK
56       * 
57       * @return true if getErrorLevel() == ErrorLevel.OK
58       */
59      @Override
60      public boolean isOk() {
61          return getLevel() == ErrorLevel.OK.getLevel();
62      }
63  
64      /**
65       * Convenience method. Returns true if getErrorLevel() == ErrorLevel.WARN
66       * 
67       * @return true if getErrorLevel() == ErrorLevel.WARN
68       */
69      @Override
70      public boolean isWarn() {
71          return getLevel() == ErrorLevel.WARN.getLevel();
72      }
73  
74      /**
75       * Convenience method. Returns true if getErrorLevel() == ErrorLevel.ERROR
76       * 
77       * @return true if getErrorLevel() == ErrorLevel.ERROR
78       */
79      @Override
80      public boolean isError() {
81          return getLevel() == ErrorLevel.ERROR.getLevel();
82      }
83  
84      @Override
85      public String toString() {
86          return "[" + level + "] Path: [" + element + "] - " + message + " data=[" + invalidData + "]";
87      }
88  
89      @Override
90      public String getMessage() {
91          return message;
92      }
93  
94      @Override
95      public String getElement() {
96          return element;
97      }
98  
99      @Override
100     public Integer getLevel() {
101         return level;
102     }
103 
104     @Override
105     public Object getInvalidData() {
106         return invalidData;
107     }
108     
109         
110     public static class Builder implements ModelBuilder<ValidationResultInfo>, ValidationResult {
111 
112         private String element;
113         private Integer level = ErrorLevel.OK.getLevel();
114         private String message;
115         private Object invalidData = null;
116         
117         public Builder() {}
118         
119         public Builder(ValidationResult validationResultInfo) {
120             this.element = validationResultInfo.getElement();
121             this.level = validationResultInfo.getLevel();
122             this.message = validationResultInfo.getMessage();
123             this.invalidData = validationResultInfo.getInvalidData();            
124         }
125         
126         @Override
127         public ValidationResultInfo build() {
128             return new ValidationResultInfo(this);
129         }              
130         
131         public String getElement() {
132             return element;
133         }
134 
135         public void setElement(String element) {
136             this.element = element;
137         }
138 
139         public Integer getLevel() {
140             return level;
141         }
142 
143         public void setLevel(Integer level) {
144             this.level = level;
145         }
146 
147         public String getMessage() {
148             return message;
149         }
150 
151         public void setMessage(String message) {
152             this.message = message;
153         }
154 
155         public Object getInvalidData() {
156             return invalidData;
157         }
158 
159         public void setInvalidData(Object invalidData) {
160             this.invalidData = invalidData;
161         }
162 
163         public void setError(String message) {
164             this.level = ErrorLevel.ERROR.getLevel();
165             this.message = message;
166         }
167 
168         public void setWarn(String message) {
169             this.level = ErrorLevel.WARN.getLevel();
170             this.message = message;
171         }
172         
173         @Override
174         public boolean isOk() {
175             return getLevel() == ErrorLevel.OK.getLevel();
176         }
177         
178         @Override
179         public boolean isWarn() {
180             return getLevel() == ErrorLevel.WARN.getLevel();
181         }
182         
183         @Override
184         public boolean isError() {
185             return getLevel() == ErrorLevel.ERROR.getLevel();
186         }        
187     }
188 }