KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > oracle > toplink > essentials > exceptions > IntegrityException


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the "License"). You may not use this file except
5  * in compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * glassfish/bootstrap/legal/CDDLv1.0.txt or
9  * https://glassfish.dev.java.net/public/CDDLv1.0.html.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * HEADER in each file and include the License file at
15  * glassfish/bootstrap/legal/CDDLv1.0.txt. If applicable,
16  * add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your
18  * own identifying information: Portions Copyright [yyyy]
19  * [name of copyright owner]
20  */

21 // Copyright (c) 1998, 2005, Oracle. All rights reserved.
22
package oracle.toplink.essentials.exceptions;
23
24 import java.io.*;
25 import java.util.*;
26 import oracle.toplink.essentials.exceptions.i18n.ExceptionMessageGenerator;
27
28 /**
29  * <p><b>Purpose</b>: IntegrityExceptions is used to throw all the Descriptors exceptions.
30  *
31  */

32 public class IntegrityException extends ValidationException {
33     protected IntegrityChecker integrityChecker;
34
35     /**
36      * INTERNAL:
37      * IntegrityExceptions is used to throw all the descriptor exceptions.
38      */

39     public IntegrityException() {
40         super();
41     }
42
43     /**
44      * INTERNAL:
45      * To throw all the descriptor exceptions.
46      */

47     public IntegrityException(IntegrityChecker integrityChecker) {
48         super();
49         this.integrityChecker = integrityChecker;
50     }
51
52     /**
53      * PUBLIC:
54      * Return Integrity Checker.
55      */

56     public IntegrityChecker getIntegrityChecker() {
57         return integrityChecker;
58     }
59
60     /**
61      * PUBLIC:
62      * This method is used to print out all the descriptor exceptions.
63      */

64     public String JavaDoc getMessage() {
65         String JavaDoc cr = oracle.toplink.essentials.internal.helper.Helper.cr();
66         java.io.StringWriter JavaDoc swriter = new java.io.StringWriter JavaDoc();
67         java.io.PrintWriter JavaDoc writer = new java.io.PrintWriter JavaDoc(swriter);
68         writer.println(cr + ExceptionMessageGenerator.getHeader("DescriptorExceptionsHeader"));
69         writer.println("---------------------------------------------------------");
70         for (Enumeration enumtr = getIntegrityChecker().getCaughtExceptions().elements();
71                  enumtr.hasMoreElements();) {
72             Exception JavaDoc e = (Exception JavaDoc)enumtr.nextElement();
73             if (e instanceof DescriptorException) {
74                 writer.println(cr + e);
75             }
76         }
77
78         if (getIntegrityChecker().hasRuntimeExceptions()) {
79             writer.println(cr + ExceptionMessageGenerator.getHeader("RuntimeExceptionsHeader"));
80             writer.println("---------------------------------------------------------");
81             for (Enumeration enumtr = getIntegrityChecker().getCaughtExceptions().elements();
82                      enumtr.hasMoreElements();) {
83                 Exception JavaDoc e = (Exception JavaDoc)enumtr.nextElement();
84                 if (!(e instanceof DescriptorException)) {
85                     writer.println(cr + e);
86                 }
87             }
88         }
89
90         writer.flush();
91         swriter.flush();
92         return swriter.toString();
93     }
94
95     /**
96      * PUBLIC:
97      * Print both the normal and internal stack traces.
98      */

99     public void printStackTrace(PrintWriter writer) {
100         super.printStackTrace(writer);
101         String JavaDoc cr = oracle.toplink.essentials.internal.helper.Helper.cr();
102         writer.println(cr + ExceptionMessageGenerator.getHeader("DescriptorExceptionsHeader"));
103         writer.println("---------------------------------------------------------");
104         for (Enumeration enumtr = getIntegrityChecker().getCaughtExceptions().elements();
105                  enumtr.hasMoreElements();) {
106             Exception JavaDoc e = (Exception JavaDoc)enumtr.nextElement();
107             if (e instanceof DescriptorException) {
108                 writer.println(cr);
109                 e.printStackTrace(writer);
110             }
111         }
112
113         if (getIntegrityChecker().hasRuntimeExceptions()) {
114             writer.println(cr + ExceptionMessageGenerator.getHeader("RuntimeExceptionsHeader"));
115             writer.println("---------------------------------------------------------");
116             for (Enumeration enumtr = getIntegrityChecker().getCaughtExceptions().elements();
117                      enumtr.hasMoreElements();) {
118                 Exception JavaDoc e = (Exception JavaDoc)enumtr.nextElement();
119                 if (!(e instanceof DescriptorException)) {
120                     writer.println(cr);
121                     e.printStackTrace(writer);
122                 }
123             }
124         }
125
126         writer.flush();
127     }
128 }
129
Popular Tags