01: /*
02: * Copyright 2006 Luca Garulli (luca.garulli@assetdata.it)
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: package org.romaframework.core.validation;
18:
19: import java.util.ArrayList;
20: import java.util.Iterator;
21:
22: public class MultiValidationException extends RuntimeException {
23:
24: public MultiValidationException() {
25: super ();
26: }
27:
28: public MultiValidationException(ValidationException e) {
29: super ();
30: addException(e);
31: }
32:
33: public void addException(ValidationException e) {
34: if (exceptions == null)
35: exceptions = new ArrayList<ValidationException>();
36: exceptions.add(e);
37: }
38:
39: public Iterator<ValidationException> getDetailIterator() {
40: if (exceptions == null)
41: return null;
42:
43: return exceptions.iterator();
44: }
45:
46: public boolean hasExceptions() {
47: return exceptions != null;
48: }
49:
50: /**
51: * Return a string with all exception messages.
52: */
53: @Override
54: public String toString() {
55: StringBuffer buffer = new StringBuffer();
56: for (ValidationException e : exceptions) {
57: buffer.append(e.toString());
58: buffer.append("\n");
59: }
60: return buffer.toString();
61: }
62:
63: private ArrayList<ValidationException> exceptions;
64: }
|