001 /*
002 * Copyright 2000-2005 Sun Microsystems, Inc. All Rights Reserved.
003 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004 *
005 * This code is free software; you can redistribute it and/or modify it
006 * under the terms of the GNU General Public License version 2 only, as
007 * published by the Free Software Foundation. Sun designates this
008 * particular file as subject to the "Classpath" exception as provided
009 * by Sun in the LICENSE file that accompanied this code.
010 *
011 * This code is distributed in the hope that it will be useful, but WITHOUT
012 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
014 * version 2 for more details (a copy is included in the LICENSE file that
015 * accompanied this code).
016 *
017 * You should have received a copy of the GNU General Public License version
018 * 2 along with this work; if not, write to the Free Software Foundation,
019 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020 *
021 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022 * CA 95054 USA or visit www.sun.com if you need additional information or
023 * have any questions.
024 */
025
026 // SAX exception class.
027 // http://www.saxproject.org
028 // No warranty; no copyright -- use this as you will.
029 // $Id: SAXParseException.java,v 1.2 2004/11/03 22:55:32 jsuttor Exp $
030 package org.xml.sax;
031
032 /**
033 * Encapsulate an XML parse error or warning.
034 *
035 * <blockquote>
036 * <em>This module, both source code and documentation, is in the
037 * Public Domain, and comes with <strong>NO WARRANTY</strong>.</em>
038 * See <a href='http://www.saxproject.org'>http://www.saxproject.org</a>
039 * for further information.
040 * </blockquote>
041 *
042 * <p>This exception may include information for locating the error
043 * in the original XML document, as if it came from a {@link Locator}
044 * object. Note that although the application
045 * will receive a SAXParseException as the argument to the handlers
046 * in the {@link org.xml.sax.ErrorHandler ErrorHandler} interface,
047 * the application is not actually required to throw the exception;
048 * instead, it can simply read the information in it and take a
049 * different action.</p>
050 *
051 * <p>Since this exception is a subclass of {@link org.xml.sax.SAXException
052 * SAXException}, it inherits the ability to wrap another exception.</p>
053 *
054 * @since SAX 1.0
055 * @author David Megginson
056 * @version 2.0.1 (sax2r2)
057 * @see org.xml.sax.SAXException
058 * @see org.xml.sax.Locator
059 * @see org.xml.sax.ErrorHandler
060 */
061 public class SAXParseException extends SAXException {
062
063 //////////////////////////////////////////////////////////////////////
064 // Constructors.
065 //////////////////////////////////////////////////////////////////////
066
067 /**
068 * Create a new SAXParseException from a message and a Locator.
069 *
070 * <p>This constructor is especially useful when an application is
071 * creating its own exception from within a {@link org.xml.sax.ContentHandler
072 * ContentHandler} callback.</p>
073 *
074 * @param message The error or warning message.
075 * @param locator The locator object for the error or warning (may be
076 * null).
077 * @see org.xml.sax.Locator
078 */
079 public SAXParseException(String message, Locator locator) {
080 super (message);
081 if (locator != null) {
082 init(locator.getPublicId(), locator.getSystemId(), locator
083 .getLineNumber(), locator.getColumnNumber());
084 } else {
085 init(null, null, -1, -1);
086 }
087 }
088
089 /**
090 * Wrap an existing exception in a SAXParseException.
091 *
092 * <p>This constructor is especially useful when an application is
093 * creating its own exception from within a {@link org.xml.sax.ContentHandler
094 * ContentHandler} callback, and needs to wrap an existing exception that is not a
095 * subclass of {@link org.xml.sax.SAXException SAXException}.</p>
096 *
097 * @param message The error or warning message, or null to
098 * use the message from the embedded exception.
099 * @param locator The locator object for the error or warning (may be
100 * null).
101 * @param e Any exception.
102 * @see org.xml.sax.Locator
103 */
104 public SAXParseException(String message, Locator locator,
105 Exception e) {
106 super (message, e);
107 if (locator != null) {
108 init(locator.getPublicId(), locator.getSystemId(), locator
109 .getLineNumber(), locator.getColumnNumber());
110 } else {
111 init(null, null, -1, -1);
112 }
113 }
114
115 /**
116 * Create a new SAXParseException.
117 *
118 * <p>This constructor is most useful for parser writers.</p>
119 *
120 * <p>All parameters except the message are as if
121 * they were provided by a {@link Locator}. For example, if the
122 * system identifier is a URL (including relative filename), the
123 * caller must resolve it fully before creating the exception.</p>
124 *
125 *
126 * @param message The error or warning message.
127 * @param publicId The public identifier of the entity that generated
128 * the error or warning.
129 * @param systemId The system identifier of the entity that generated
130 * the error or warning.
131 * @param lineNumber The line number of the end of the text that
132 * caused the error or warning.
133 * @param columnNumber The column number of the end of the text that
134 * cause the error or warning.
135 */
136 public SAXParseException(String message, String publicId,
137 String systemId, int lineNumber, int columnNumber) {
138 super (message);
139 init(publicId, systemId, lineNumber, columnNumber);
140 }
141
142 /**
143 * Create a new SAXParseException with an embedded exception.
144 *
145 * <p>This constructor is most useful for parser writers who
146 * need to wrap an exception that is not a subclass of
147 * {@link org.xml.sax.SAXException SAXException}.</p>
148 *
149 * <p>All parameters except the message and exception are as if
150 * they were provided by a {@link Locator}. For example, if the
151 * system identifier is a URL (including relative filename), the
152 * caller must resolve it fully before creating the exception.</p>
153 *
154 * @param message The error or warning message, or null to use
155 * the message from the embedded exception.
156 * @param publicId The public identifier of the entity that generated
157 * the error or warning.
158 * @param systemId The system identifier of the entity that generated
159 * the error or warning.
160 * @param lineNumber The line number of the end of the text that
161 * caused the error or warning.
162 * @param columnNumber The column number of the end of the text that
163 * cause the error or warning.
164 * @param e Another exception to embed in this one.
165 */
166 public SAXParseException(String message, String publicId,
167 String systemId, int lineNumber, int columnNumber,
168 Exception e) {
169 super (message, e);
170 init(publicId, systemId, lineNumber, columnNumber);
171 }
172
173 /**
174 * Internal initialization method.
175 *
176 * @param publicId The public identifier of the entity which generated the exception,
177 * or null.
178 * @param systemId The system identifier of the entity which generated the exception,
179 * or null.
180 * @param lineNumber The line number of the error, or -1.
181 * @param columnNumber The column number of the error, or -1.
182 */
183 private void init(String publicId, String systemId, int lineNumber,
184 int columnNumber) {
185 this .publicId = publicId;
186 this .systemId = systemId;
187 this .lineNumber = lineNumber;
188 this .columnNumber = columnNumber;
189 }
190
191 /**
192 * Get the public identifier of the entity where the exception occurred.
193 *
194 * @return A string containing the public identifier, or null
195 * if none is available.
196 * @see org.xml.sax.Locator#getPublicId
197 */
198 public String getPublicId() {
199 return this .publicId;
200 }
201
202 /**
203 * Get the system identifier of the entity where the exception occurred.
204 *
205 * <p>If the system identifier is a URL, it will have been resolved
206 * fully.</p>
207 *
208 * @return A string containing the system identifier, or null
209 * if none is available.
210 * @see org.xml.sax.Locator#getSystemId
211 */
212 public String getSystemId() {
213 return this .systemId;
214 }
215
216 /**
217 * The line number of the end of the text where the exception occurred.
218 *
219 * <p>The first line is line 1.</p>
220 *
221 * @return An integer representing the line number, or -1
222 * if none is available.
223 * @see org.xml.sax.Locator#getLineNumber
224 */
225 public int getLineNumber() {
226 return this .lineNumber;
227 }
228
229 /**
230 * The column number of the end of the text where the exception occurred.
231 *
232 * <p>The first column in a line is position 1.</p>
233 *
234 * @return An integer representing the column number, or -1
235 * if none is available.
236 * @see org.xml.sax.Locator#getColumnNumber
237 */
238 public int getColumnNumber() {
239 return this .columnNumber;
240 }
241
242 //////////////////////////////////////////////////////////////////////
243 // Internal state.
244 //////////////////////////////////////////////////////////////////////
245
246 /**
247 * @serial The public identifier, or null.
248 * @see #getPublicId
249 */
250 private String publicId;
251
252 /**
253 * @serial The system identifier, or null.
254 * @see #getSystemId
255 */
256 private String systemId;
257
258 /**
259 * @serial The line number, or -1.
260 * @see #getLineNumber
261 */
262 private int lineNumber;
263
264 /**
265 * @serial The column number, or -1.
266 * @see #getColumnNumber
267 */
268 private int columnNumber;
269
270 // Added serialVersionUID to preserve binary compatibility
271 static final long serialVersionUID = -5651165872476709336L;
272 }
273
274 // end of SAXParseException.java
|