KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > n3 > nanoxml > XMLException


1 /* XMLException.java NanoXML/Java
2  *
3  * $Revision: 1421 $
4  * $Date: 2006-03-12 17:32:32 +0100 (Sun, 12 Mar 2006) $
5  * $Name$
6  *
7  * This file is part of NanoXML 2 for Java.
8  * Copyright (C) 2001 Marc De Scheemaecker, All Rights Reserved.
9  *
10  * This software is provided 'as-is', without any express or implied warranty.
11  * In no event will the authors be held liable for any damages arising from the
12  * use of this software.
13  *
14  * Permission is granted to anyone to use this software for any purpose,
15  * including commercial applications, and to alter it and redistribute it
16  * freely, subject to the following restrictions:
17  *
18  * 1. The origin of this software must not be misrepresented; you must not
19  * claim that you wrote the original software. If you use this software in
20  * a product, an acknowledgment in the product documentation would be
21  * appreciated but is not required.
22  *
23  * 2. Altered source versions must be plainly marked as such, and must not be
24  * misrepresented as being the original software.
25  *
26  * 3. This notice may not be removed or altered from any source distribution.
27  */

28
29 package net.n3.nanoxml;
30
31 import java.io.PrintStream JavaDoc;
32 import java.io.PrintWriter JavaDoc;
33
34 /**
35  * An XMLException is thrown when an exception occurred while processing the XML data.
36  *
37  * @author Marc De Scheemaecker
38  * @version $Name$, $Revision: 1421 $
39  */

40 public class XMLException extends Exception JavaDoc
41 {
42
43     /**
44      *
45      */

46     private static final long serialVersionUID = 3256727298916299056L;
47
48     /**
49      * The system ID of the XML data where the exception occurred.
50      */

51     private String JavaDoc systemID;
52
53     /**
54      * The line number in the XML data where the exception occurred.
55      */

56     private int lineNr;
57
58     /**
59      * Encapsulated exception.
60      */

61     private Exception JavaDoc encapsulatedException;
62
63     /**
64      * Creates a new exception.
65      *
66      * @param msg the message of the exception.
67      */

68     public XMLException(String JavaDoc msg)
69     {
70         this(null, -1, null, msg, false);
71     }
72
73     /**
74      * Creates a new exception.
75      *
76      * @param e the encapsulated exception.
77      */

78     public XMLException(Exception JavaDoc e)
79     {
80         this(null, -1, e, e.getMessage(), false);
81     }
82
83     /**
84      * Creates a new exception.
85      *
86      * @param systemID the system ID of the XML data where the exception occurred
87      * @param lineNr the line number in the XML data where the exception occurred.
88      * @param e the encapsulated exception.
89      */

90     public XMLException(String JavaDoc systemID, int lineNr, Exception JavaDoc e)
91     {
92         this(systemID, lineNr, e, "Nested Exception", true);
93     }
94
95     /**
96      * Creates a new exception.
97      *
98      * @param systemID the system ID of the XML data where the exception occurred
99      * @param lineNr the line number in the XML data where the exception occurred.
100      * @param msg the message of the exception.
101      */

102     public XMLException(String JavaDoc systemID, int lineNr, String JavaDoc msg)
103     {
104         this(systemID, lineNr, null, msg, true);
105     }
106
107     /**
108      * Creates a new exception.
109      *
110      * @param systemID the system ID from where the data came
111      * @param lineNr the line number in the XML data where the exception occurred.
112      * @param e the encapsulated exception.
113      * @param msg the message of the exception.
114      * @param reportParams true if the systemID, lineNr and e params need to be appended to the
115      * message
116      */

117     public XMLException(String JavaDoc systemID, int lineNr, Exception JavaDoc e, String JavaDoc msg, boolean reportParams)
118     {
119         super(msg
120                 + (reportParams ? (((systemID == null) ? "" : (", SystemID='" + systemID + "'"))
121                         + ((lineNr == -1) ? "" : (", Line=" + lineNr)) + ((e == null) ? ""
122                         : (", Exception: " + e))) : ""));
123         this.systemID = systemID;
124         this.lineNr = lineNr;
125         this.encapsulatedException = e;
126     }
127
128     /**
129      * Cleans up the object when it's destroyed.
130      */

131     protected void finalize() throws Throwable JavaDoc
132     {
133         this.systemID = null;
134         this.encapsulatedException = null;
135         super.finalize();
136     }
137
138     /**
139      * Returns the system ID of the XML data where the exception occurred. If there is no system ID
140      * known, null is returned.
141      */

142     public String JavaDoc getSystemID()
143     {
144         return this.systemID;
145     }
146
147     /**
148      * Returns the line number in the XML data where the exception occurred. If there is no line
149      * number known, -1 is returned.
150      */

151     public int getLineNr()
152     {
153         return this.lineNr;
154     }
155
156     /**
157      * Returns the encapsulated exception, or null if no exception is encapsulated.
158      */

159     public Exception JavaDoc getException()
160     {
161         return this.encapsulatedException;
162     }
163
164     /**
165      * Dumps the exception stack to a print writer.
166      *
167      * @param writer the print writer
168      */

169     public void printStackTrace(PrintWriter JavaDoc writer)
170     {
171         if (this.encapsulatedException != null)
172         {
173             this.encapsulatedException.printStackTrace(writer);
174         }
175
176         super.printStackTrace(writer);
177     }
178
179     /**
180      * Dumps the exception stack to an output stream.
181      *
182      * @param stream the output stream
183      */

184     public void printStackTrace(PrintStream JavaDoc stream)
185     {
186         if (this.encapsulatedException != null)
187         {
188             this.encapsulatedException.printStackTrace(stream);
189         }
190
191         super.printStackTrace(stream);
192     }
193
194     /**
195      * Dumps the exception stack to System.err.
196      */

197     public void printStackTrace()
198     {
199         if (this.encapsulatedException != null)
200         {
201             this.encapsulatedException.printStackTrace();
202         }
203
204         super.printStackTrace();
205     }
206
207 }
208
Popular Tags