KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > dom4j > DocumentException


1 /*
2  * Copyright 2001-2005 (C) MetaStuff, Ltd. All Rights Reserved.
3  *
4  * This software is open source.
5  * See the bottom of this file for the licence.
6  */

7
8 package org.dom4j;
9
10 import java.io.PrintStream JavaDoc;
11 import java.io.PrintWriter JavaDoc;
12
13 /**
14  * <p>
15  * <code>DocumentException</code> is a nested Exception which may be thrown
16  * during the processing of a DOM4J document.
17  * </p>
18  *
19  * @author <a HREF="mailto:james.strachan@metastuff.com">James Strachan </a>
20  * @version $Revision: 1.7 $
21  */

22 public class DocumentException extends Exception JavaDoc {
23     /** A wrapped <code>Throwable</code> */
24     private Throwable JavaDoc nestedException;
25
26     public DocumentException() {
27         super("Error occurred in DOM4J application.");
28     }
29
30     public DocumentException(String JavaDoc message) {
31         super(message);
32     }
33
34     public DocumentException(Throwable JavaDoc nestedException) {
35         super(nestedException.getMessage());
36         this.nestedException = nestedException;
37     }
38
39     public DocumentException(String JavaDoc message, Throwable JavaDoc nestedException) {
40         super(message);
41         this.nestedException = nestedException;
42     }
43
44     public Throwable JavaDoc getNestedException() {
45         return nestedException;
46     }
47
48     public String JavaDoc getMessage() {
49         if (nestedException != null) {
50             return super.getMessage() + " Nested exception: "
51                     + nestedException.getMessage();
52         } else {
53             return super.getMessage();
54         }
55     }
56
57     public void printStackTrace() {
58         super.printStackTrace();
59
60         if (nestedException != null) {
61             System.err.print("Nested exception: ");
62             nestedException.printStackTrace();
63         }
64     }
65
66     public void printStackTrace(PrintStream JavaDoc out) {
67         super.printStackTrace(out);
68
69         if (nestedException != null) {
70             out.println("Nested exception: ");
71             nestedException.printStackTrace(out);
72         }
73     }
74
75     public void printStackTrace(PrintWriter JavaDoc writer) {
76         super.printStackTrace(writer);
77
78         if (nestedException != null) {
79             writer.println("Nested exception: ");
80             nestedException.printStackTrace(writer);
81         }
82     }
83 }
84
85 /*
86  * Redistribution and use of this software and associated documentation
87  * ("Software"), with or without modification, are permitted provided that the
88  * following conditions are met:
89  *
90  * 1. Redistributions of source code must retain copyright statements and
91  * notices. Redistributions must also contain a copy of this document.
92  *
93  * 2. Redistributions in binary form must reproduce the above copyright notice,
94  * this list of conditions and the following disclaimer in the documentation
95  * and/or other materials provided with the distribution.
96  *
97  * 3. The name "DOM4J" must not be used to endorse or promote products derived
98  * from this Software without prior written permission of MetaStuff, Ltd. For
99  * written permission, please contact dom4j-info@metastuff.com.
100  *
101  * 4. Products derived from this Software may not be called "DOM4J" nor may
102  * "DOM4J" appear in their names without prior written permission of MetaStuff,
103  * Ltd. DOM4J is a registered trademark of MetaStuff, Ltd.
104  *
105  * 5. Due credit should be given to the DOM4J Project - http://www.dom4j.org
106  *
107  * THIS SOFTWARE IS PROVIDED BY METASTUFF, LTD. AND CONTRIBUTORS ``AS IS'' AND
108  * ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
109  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
110  * ARE DISCLAIMED. IN NO EVENT SHALL METASTUFF, LTD. OR ITS CONTRIBUTORS BE
111  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
112  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
113  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
114  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
115  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
116  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
117  * POSSIBILITY OF SUCH DAMAGE.
118  *
119  * Copyright 2001-2005 (C) MetaStuff, Ltd. All Rights Reserved.
120  */

121
Popular Tags