001: /* Copyright 2000 - 2001 Quadcap Software. All rights reserved.
002: *
003: * This software is distributed under the Quadcap Free Software License.
004: * This software may be used or modified for any purpose, personal or
005: * commercial. Open Source redistributions are permitted. Commercial
006: * redistribution of larger works derived from, or works which bundle
007: * this software requires a "Commercial Redistribution License"; see
008: * http://www.quadcap.com/purchase.
009: *
010: * Redistributions qualify as "Open Source" under one of the following terms:
011: *
012: * Redistributions are made at no charge beyond the reasonable cost of
013: * materials and delivery.
014: *
015: * Redistributions are accompanied by a copy of the Source Code or by an
016: * irrevocable offer to provide a copy of the Source Code for up to three
017: * years at the cost of materials and delivery. Such redistributions
018: * must allow further use, modification, and redistribution of the Source
019: * Code under substantially the same terms as this license.
020: *
021: * Redistributions of source code must retain the copyright notices as they
022: * appear in each source code file, these license terms, and the
023: * disclaimer/limitation of liability set forth as paragraph 6 below.
024: *
025: * Redistributions in binary form must reproduce this Copyright Notice,
026: * these license terms, and the disclaimer/limitation of liability set
027: * forth as paragraph 6 below, in the documentation and/or other materials
028: * provided with the distribution.
029: *
030: * The Software is provided on an "AS IS" basis. No warranty is
031: * provided that the Software is free of defects, or fit for a
032: * particular purpose.
033: *
034: * Limitation of Liability. Quadcap Software shall not be liable
035: * for any damages suffered by the Licensee or any third party resulting
036: * from use of the Software.
037: */
038:
039: // SAX exception class.
040: // No warranty; no copyright -- use this as you will.
041: // $Id: SAXParseException.java,v 1.3 2001/01/06 06:11:03 stan Exp $
042: package org.xml.sax;
043:
044: /**
045: * Encapsulate an XML parse error or warning.
046: *
047: * <p>This exception will include information for locating the error
048: * in the original XML document. Note that although the application
049: * will receive a SAXParseException as the argument to the handlers
050: * in the ErrorHandler interface, the application is not actually
051: * required to throw the exception; instead, it can simply read the
052: * information in it and take a different action.</p>
053: *
054: * <p>Since this exception is a subclass of SAXException, it
055: * inherits the ability to wrap another exception.</p>
056: *
057: * @author David Megginson (ak117@freenet.carleton.ca)
058: * @version 1.0
059: * @see org.xml.sax.SAXException
060: * @see org.xml.sax.Locator
061: * @see org.xml.sax.ErrorHandler
062: */
063: public class SAXParseException extends SAXException {
064:
065: //////////////////////////////////////////////////////////////////////
066: // Constructors.
067: //////////////////////////////////////////////////////////////////////
068:
069: /**
070: * Create a new SAXParseException from a message and a Locator.
071: *
072: * <p>This constructor is especially useful when an application is
073: * creating its own exception from within a DocumentHandler
074: * callback.</p>
075: *
076: * @param message The error or warning message.
077: * @param locator The locator object for the error or warning.
078: * @see org.xml.sax.Locator
079: * @see org.xml.sax.Parser#setLocale
080: */
081: public SAXParseException(String message, Locator locator) {
082: super (message);
083: this .publicId = locator.getPublicId();
084: this .systemId = locator.getSystemId();
085: this .lineNumber = locator.getLineNumber();
086: this .columnNumber = locator.getColumnNumber();
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 DocumentHandler
094: * callback, and needs to wrap an existing exception that is not a
095: * subclass of 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.
100: * @param e Any exception
101: * @see org.xml.sax.Locator
102: * @see org.xml.sax.Parser#setLocale
103: */
104: public SAXParseException(String message, Locator locator,
105: Exception e) {
106: super (message, e);
107: this .publicId = locator.getPublicId();
108: this .systemId = locator.getSystemId();
109: this .lineNumber = locator.getLineNumber();
110: this .columnNumber = locator.getColumnNumber();
111: }
112:
113: /**
114: * Create a new SAXParseException.
115: *
116: * <p>This constructor is most useful for parser writers.</p>
117: *
118: * <p>If the system identifier is a URL, the parser must resolve it
119: * fully before creating the exception.</p>
120: *
121: * @param message The error or warning message.
122: * @param publicId The public identifer of the entity that generated
123: * the error or warning.
124: * @param systemId The system identifer of the entity that generated
125: * the error or warning.
126: * @param lineNumber The line number of the end of the text that
127: * caused the error or warning.
128: * @param columnNumber The column number of the end of the text that
129: * cause the error or warning.
130: * @see org.xml.sax.Parser#setLocale
131: */
132: public SAXParseException(String message, String publicId,
133: String systemId, int lineNumber, int columnNumber) {
134: super (message);
135: this .publicId = publicId;
136: this .systemId = systemId;
137: this .lineNumber = lineNumber;
138: this .columnNumber = columnNumber;
139: }
140:
141: /**
142: * Create a new SAXParseException with an embedded exception.
143: *
144: * <p>This constructor is most useful for parser writers who
145: * need to wrap an exception that is not a subclass of
146: * SAXException.</p>
147: *
148: * <p>If the system identifier is a URL, the parser must resolve it
149: * fully before creating the exception.</p>
150: *
151: * @param message The error or warning message, or null to use
152: * the message from the embedded exception.
153: * @param publicId The public identifer of the entity that generated
154: * the error or warning.
155: * @param systemId The system identifer of the entity that generated
156: * the error or warning.
157: * @param lineNumber The line number of the end of the text that
158: * caused the error or warning.
159: * @param columnNumber The column number of the end of the text that
160: * cause the error or warning.
161: * @param e Another exception to embed in this one.
162: * @see org.xml.sax.Parser#setLocale
163: */
164: public SAXParseException(String message, String publicId,
165: String systemId, int lineNumber, int columnNumber,
166: Exception e) {
167: super (message, e);
168: this .publicId = publicId;
169: this .systemId = systemId;
170: this .lineNumber = lineNumber;
171: this .columnNumber = columnNumber;
172: }
173:
174: /**
175: * Get the public identifier of the entity where the exception occurred.
176: *
177: * @return A string containing the public identifier, or null
178: * if none is available.
179: * @see org.xml.sax.Locator#getPublicId
180: */
181: public String getPublicId() {
182: return this .publicId;
183: }
184:
185: /**
186: * Get the system identifier of the entity where the exception occurred.
187: *
188: * <p>If the system identifier is a URL, it will be resolved
189: * fully.</p>
190: *
191: * @return A string containing the system identifier, or null
192: * if none is available.
193: * @see org.xml.sax.Locator#getSystemId
194: */
195: public String getSystemId() {
196: return this .systemId;
197: }
198:
199: /**
200: * The line number of the end of the text where the exception occurred.
201: *
202: * @return An integer representing the line number, or -1
203: * if none is available.
204: * @see org.xml.sax.Locator#getLineNumber
205: */
206: public int getLineNumber() {
207: return this .lineNumber;
208: }
209:
210: /**
211: * The column number of the end of the text where the exception occurred.
212: *
213: * <p>The first column in a line is position 1.</p>
214: *
215: * @return An integer representing the column number, or -1
216: * if none is available.
217: * @see org.xml.sax.Locator#getColumnNumber
218: */
219: public int getColumnNumber() {
220: return this .columnNumber;
221: }
222:
223: //////////////////////////////////////////////////////////////////////
224: // Internal state.
225: //////////////////////////////////////////////////////////////////////
226:
227: private String publicId;
228: private String systemId;
229: private int lineNumber;
230: private int columnNumber;
231:
232: }
|