1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.krad.datadictionary.validator;
17
18 import org.apache.commons.logging.Log;
19 import org.apache.commons.logging.LogFactory;
20
21 import java.util.ArrayList;
22
23
24
25
26
27
28 public class ErrorReport {
29 private static final Log LOG = LogFactory.getLog(ErrorReport.class);
30
31
32 public static final int ERROR = 1;
33 public static final int WARNING = 2;
34
35 private static final String endl = System.getProperty("line.separator");
36
37
38 private int errorStatus;
39 private String validationFailed;
40 private String beanLocation;
41 private ArrayList<String> currentValues;
42 private ArrayList<String> xmlPages;
43
44
45
46
47
48
49 public ErrorReport(int ErrorStatus) {
50 this.errorStatus = ErrorStatus;
51 this.validationFailed = "";
52 this.beanLocation = "";
53 this.currentValues = new ArrayList<String>();
54 this.xmlPages = new ArrayList<String>();
55 }
56
57
58
59
60
61
62
63
64
65 public ErrorReport(int errorStatus, String validationFailed, String beanLocation, String values[]) {
66 this.errorStatus = errorStatus;
67 this.validationFailed = validationFailed;
68 this.beanLocation = beanLocation;
69 this.currentValues = new ArrayList<String>();
70 this.xmlPages = new ArrayList<String>();
71
72 for (int i = 0; i < values.length; i++) {
73 addCurrentValue(values[i]);
74 }
75 }
76
77
78
79
80
81
82
83
84 public ErrorReport(int errorStatus, String validationFailed, ValidationTrace trace) {
85 this.errorStatus = errorStatus;
86 this.validationFailed = validationFailed;
87 this.xmlPages = trace.getRelatedXmls();
88 this.beanLocation = trace.getBeanLocation();
89 this.currentValues = new ArrayList<String>();
90 }
91
92
93
94
95
96
97
98
99
100 public ErrorReport(int errorStatus, String validationFailed, ValidationTrace trace, String values[]) {
101 this.errorStatus = errorStatus;
102 this.validationFailed = validationFailed;
103 this.beanLocation = trace.getBeanLocation();
104 this.xmlPages = trace.getRelatedXmls();
105 this.currentValues = new ArrayList<String>();
106
107 for (int i = 0; i < values.length; i++) {
108 addCurrentValue(values[i]);
109 }
110 }
111
112
113
114
115
116
117
118
119 public ErrorReport(int errorStatus, String validationFailed, String beanLocation) {
120 this.errorStatus = errorStatus;
121 this.validationFailed = validationFailed;
122 this.beanLocation = beanLocation;
123 this.currentValues = new ArrayList<String>();
124 this.xmlPages = new ArrayList<String>();
125 }
126
127
128
129
130
131
132
133
134 public static ErrorReport createError(String validationFailed, ValidationTrace trace) {
135 return new ErrorReport(ERROR, validationFailed, trace);
136 }
137
138
139
140
141
142
143
144
145 public static ErrorReport createWarning(String validationFailed, ValidationTrace trace) {
146 return new ErrorReport(WARNING, validationFailed, trace);
147 }
148
149
150
151
152
153
154 public void addCurrentValue(String value) {
155 currentValues.add(value);
156 }
157
158
159
160
161
162
163 public void addXmlPage(String page) {
164 xmlPages.add(page);
165 }
166
167
168
169
170
171
172 public void addXmlPages(ArrayList<String> pages) {
173 xmlPages.addAll(pages);
174 }
175
176
177
178
179
180
181 public void removeCurrentValue(int index) {
182 currentValues.remove(index);
183 }
184
185
186
187
188
189
190 public void removeXmlPage(int index) {
191 xmlPages.remove(index);
192 }
193
194
195
196
197
198
199
200 public void modifyCurrentValue(int index, String value) {
201 currentValues.set(index, value);
202 }
203
204
205
206
207
208
209
210 public void modifyXmlPage(int index, String page) {
211 xmlPages.set(index, page);
212 }
213
214
215
216
217
218
219 public String errorMessage() {
220 String message = "";
221
222 if (errorStatus == ERROR) {
223 message = message + ("Dictionary Error Detected: " + getValidationFailed() + endl);
224 } else if (errorStatus == WARNING) {
225 message = message + ("Dictionary Warning Detected: " + getValidationFailed() + endl);
226 }
227
228 message = message + ("Bean: " + getBeanLocation() + endl);
229 message = message + ("Values involved:" + endl);
230 for (int i = 0; i < getCurrentValueSize(); i++) {
231 message = message + (getCurrentValue(i) + endl);
232 }
233
234 return message;
235 }
236
237
238
239
240
241
242 public String errorPageList() {
243 String pages = "Xml Pages Involved" + endl;
244
245 for (int i = 0; i < getXmlPageSize(); i++) {
246 pages = pages + getXmlPage(i) + endl;
247 }
248
249 return pages;
250 }
251
252
253
254
255
256
257 public void setValidationFailed(String validation) {
258 validationFailed = validation;
259 }
260
261
262
263
264
265
266 public void setBeanLocation(String location) {
267 beanLocation = location;
268 }
269
270
271
272
273
274
275 public int getErrorStatus() {
276 return errorStatus;
277 }
278
279
280
281
282
283
284 public String getValidationFailed() {
285 return validationFailed;
286 }
287
288
289
290
291
292
293 public String getBeanLocation() {
294 return beanLocation;
295 }
296
297
298
299
300
301
302
303 public String getCurrentValue(int index) {
304 return currentValues.get(index);
305 }
306
307
308
309
310
311
312
313 public String getXmlPage(int index) {
314 return xmlPages.get(index);
315 }
316
317
318
319
320
321
322 public int getCurrentValueSize() {
323 return currentValues.size();
324 }
325
326
327
328
329
330
331 public int getXmlPageSize() {
332 return xmlPages.size();
333 }
334 }