Statistics
| Revision:

root / import / ext3D / trunk / install-extension3d / IzPack / src / lib / net / n3 / nanoxml / XMLException.java @ 15280

History | View | Annotate | Download (6.37 KB)

1
/* XMLException.java                                               NanoXML/Java
2
 *
3
 * $Revision: 1.1 $
4
 * $Date: 2006/06/14 07:29:07 $
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;
32
import java.io.PrintWriter;
33

    
34

    
35
/**
36
 * An XMLException is thrown when an exception occurred while processing the
37
 * XML data.
38
 *
39
 * @author Marc De Scheemaecker
40
 * @version $Name:  $, $Revision: 1.1 $
41
 */
42
public class XMLException
43
    extends Exception
44
{
45

    
46
    /**
47
     * The system ID of the XML data where the exception occurred.
48
     */
49
    private String systemID;
50
    
51
    
52
    /**
53
     * The line number in the XML data where the exception occurred.
54
     */
55
    private int lineNr;
56
    
57
    
58
    /**
59
     * Encapsulated exception.
60
     */
61
    private Exception encapsulatedException;
62
    
63
    
64
    /**
65
     * Creates a new exception.
66
     *
67
     * @param msg the message of the exception.
68
     */
69
    public XMLException(String msg)
70
    {
71
        this(null, -1, null, msg, false);
72
    }
73
    
74
    
75
    /**
76
     * Creates a new exception.
77
     *
78
     * @param e the encapsulated exception.
79
     */
80
    public XMLException(Exception e)
81
    {
82
        this(null, -1, e, e.getMessage(), false);
83
    }
84
    
85
    
86
    /**
87
     * Creates a new exception.
88
     *
89
     * @param systemID the system ID of the XML data where the exception
90
     *                 occurred
91
     * @param lineNr   the line number in the XML data where the exception 
92
     *                 occurred.
93
     * @param e        the encapsulated exception.
94
     */
95
    public XMLException(String systemID,
96
                        int    lineNr,
97
                        Exception e)
98
    {
99
        this(systemID, lineNr, e, "Nested Exception", true);
100
    }
101
    
102
    
103
    /**
104
     * Creates a new exception.
105
     *
106
     * @param systemID the system ID of the XML data where the exception
107
     *                 occurred
108
     * @param lineNr   the line number in the XML data where the exception 
109
     *                 occurred.
110
     * @param msg      the message of the exception.
111
     */
112
    public XMLException(String systemID,
113
                        int    lineNr,
114
                        String msg)
115
    {
116
        this(systemID, lineNr, null, msg, true);
117
    }
118
    
119
    
120
    /**
121
     * Creates a new exception.
122
     *
123
     * @param systemID     the system ID from where the data came
124
     * @param lineNr       the line number in the XML data where the exception 
125
     *                     occurred.
126
     * @param e            the encapsulated exception.
127
     * @param msg          the message of the exception.
128
     * @param reportParams true if the systemID, lineNr and e params need to be
129
     *                     appended to the message
130
     */
131
    public XMLException(String    systemID,
132
                        int       lineNr,
133
                        Exception e,
134
                        String    msg,
135
                        boolean   reportParams)
136
    {
137
        super(msg
138
              + (reportParams
139
                 ? (((systemID == null) ? ""
140
                                        : (", SystemID='" + systemID + "'")) 
141
                    + ((lineNr == -1) ? "" : (", Line=" + lineNr))
142
                    + ((e == null) ? "" : (", Exception: " + e)))
143
                 : ""));
144
        this.systemID = systemID;
145
        this.lineNr = lineNr;
146
        this.encapsulatedException = e;
147
    }
148
    
149
    
150
    /**
151
     * Cleans up the object when it's destroyed.
152
     */
153
    protected void finalize()
154
        throws Throwable
155
    {
156
        this.systemID = null;
157
        this.encapsulatedException = null;
158
        super.finalize();
159
    }
160
    
161
    
162
    /**
163
     * Returns the system ID of the XML data where the exception occurred.
164
     * If there is no system ID known, null is returned.
165
     */
166
    public String getSystemID()
167
    {
168
        return this.systemID;
169
    }
170
    
171
    
172
    /**
173
     * Returns the line number in the XML data where the exception occurred.
174
     * If there is no line number known, -1 is returned.
175
     */
176
    public int getLineNr()
177
    {
178
        return this.lineNr;
179
    }
180
    
181
    
182
    /**
183
     * Returns the encapsulated exception, or null if no exception is
184
     * encapsulated.
185
     */
186
    public Exception getException()
187
    {
188
        return this.encapsulatedException;
189
    }
190
    
191
    
192
    /**
193
     * Dumps the exception stack to a print writer.
194
     *
195
     * @param writer the print writer
196
     */
197
    public void printStackTrace(PrintWriter writer)
198
    {
199
        if (this.encapsulatedException != null) {
200
            this.encapsulatedException.printStackTrace(writer);
201
        }
202
        
203
        super.printStackTrace(writer);
204
    }
205
     
206
    
207
    /**
208
     * Dumps the exception stack to an output stream.
209
     *
210
     * @param stream the output stream
211
     */
212
    public void printStackTrace(PrintStream stream)
213
    {
214
        if (this.encapsulatedException != null) {
215
            this.encapsulatedException.printStackTrace(stream);
216
        }
217
        
218
        super.printStackTrace(stream);
219
    }
220
        
221
    
222
    /**
223
     * Dumps the exception stack to System.err.
224
     */
225
    public void printStackTrace()
226
    {
227
        if (this.encapsulatedException != null) {
228
            this.encapsulatedException.printStackTrace();
229
        }
230
        
231
        super.printStackTrace();
232
    }
233

    
234
}