01: /*
02: * Copyright 2006 Davide Deidda
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
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:
17: /*
18: * ValidationReport.java
19: *
20: * Created on 26 novembre 2003, 21.45
21: */
22:
23: package it.biobytes.ammentos.validation;
24:
25: import java.util.*;
26:
27: /**
28: * Contains results about a validation
29: * @author davide
30: */
31: public class ValidationReport {
32: private List m_errors; // Errors list
33:
34: /**
35: * Adds an error report
36: */
37: public void addError(String error) {
38: if (m_errors == null) {
39: m_errors = new ArrayList(2);
40: }
41: m_errors.add(error);
42: }
43:
44: /**
45: * Returns the list of the errors in the report
46: */
47: public String[] getErrors() {
48: String[] res = null;
49: if (m_errors != null) {
50: res = (String[]) m_errors.toArray(new String[0]);
51: }
52:
53: return res;
54: }
55:
56: /**
57: * Tells if the report is empty
58: */
59: public boolean isEmpty() {
60: return ((m_errors == null) || (m_errors.size() == 0));
61: }
62:
63: /**
64: * Adds a validation report to this one
65: */
66: public void add(ValidationReport report) {
67: if (report == null)
68: return;
69:
70: String[] errors = report.getErrors();
71: if (errors != null) {
72: for (int i = 0; i < errors.length; i++) {
73: addError(errors[i]);
74: }
75: }
76: }
77:
78: }
|