01: /*
02: * Copyright 2006 Sun Microsystems, Inc. All Rights Reserved.
03: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
04: *
05: * This code is free software; you can redistribute it and/or modify it
06: * under the terms of the GNU General Public License version 2 only, as
07: * published by the Free Software Foundation. Sun designates this
08: * particular file as subject to the "Classpath" exception as provided
09: * by Sun in the LICENSE file that accompanied this code.
10: *
11: * This code is distributed in the hope that it will be useful, but WITHOUT
12: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14: * version 2 for more details (a copy is included in the LICENSE file that
15: * accompanied this code).
16: *
17: * You should have received a copy of the GNU General Public License version
18: * 2 along with this work; if not, write to the Free Software Foundation,
19: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20: *
21: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
22: * CA 95054 USA or visit www.sun.com if you need additional information or
23: * have any questions.
24: */
25:
26: package com.sun.xml.internal.bind.v2.runtime;
27:
28: import java.util.ArrayList;
29: import java.util.Collections;
30: import java.util.List;
31:
32: import javax.xml.bind.JAXBContext;
33: import javax.xml.bind.JAXBException;
34:
35: import com.sun.xml.internal.bind.v2.model.core.ErrorHandler;
36:
37: /**
38: * A list of {@link IllegalAnnotationException} wrapped in one exception.
39: *
40: * <p>
41: * This exception is used to report all the errors to the client application
42: * through {@link JAXBContext#newInstance}.
43: *
44: * @since JAXB 2.0 EA1
45: * @author Kohsuke Kawaguchi
46: */
47: public class IllegalAnnotationsException extends JAXBException {
48: private final List<IllegalAnnotationException> errors;
49:
50: private static final long serialVersionUID = 1L;
51:
52: public IllegalAnnotationsException(
53: List<IllegalAnnotationException> errors) {
54: super (errors.size() + " counts of IllegalAnnotationExceptions");
55: assert !errors.isEmpty() : "there must be at least one error";
56: this .errors = Collections
57: .unmodifiableList(new ArrayList<IllegalAnnotationException>(
58: errors));
59: }
60:
61: public String toString() {
62: StringBuilder sb = new StringBuilder(super .toString());
63: sb.append('\n');
64:
65: for (IllegalAnnotationException error : errors)
66: sb.append(error.toString()).append('\n');
67:
68: return sb.toString();
69: }
70:
71: /**
72: * Returns a read-only list of {@link IllegalAnnotationException}s
73: * wrapped in this exception.
74: *
75: * @return
76: * a non-null list.
77: */
78: public List<IllegalAnnotationException> getErrors() {
79: return errors;
80: }
81:
82: public static class Builder implements ErrorHandler {
83: private final List<IllegalAnnotationException> list = new ArrayList<IllegalAnnotationException>();
84:
85: public void error(IllegalAnnotationException e) {
86: list.add(e);
87: }
88:
89: /**
90: * If an error was reported, throw the exception.
91: * Otherwise exit normally.
92: */
93: public void check() throws IllegalAnnotationsException {
94: if (list.isEmpty())
95: return;
96: throw new IllegalAnnotationsException(list);
97: }
98: }
99: }
|