001: // SAX exception class.
002: // http://www.saxproject.org
003: // No warranty; no copyright -- use this as you will.
004: // $Id: SAXParseException.java,v 1.1.1.1 2002/05/03 23:29:41 yuvalo Exp $
005:
006: package org.xml.sax;
007:
008: /**
009: * Encapsulate an XML parse error or warning.
010: *
011: * <blockquote>
012: * <em>This module, both source code and documentation, is in the
013: * Public Domain, and comes with <strong>NO WARRANTY</strong>.</em>
014: * See <a href='http://www.saxproject.org'>http://www.saxproject.org</a>
015: * for further information.
016: * </blockquote>
017: *
018: * <p>This exception may include information for locating the error
019: * in the original XML document, as if it came from a {@link Locator}
020: * object. Note that although the application
021: * will receive a SAXParseException as the argument to the handlers
022: * in the {@link org.xml.sax.ErrorHandler ErrorHandler} interface,
023: * the application is not actually required to throw the exception;
024: * instead, it can simply read the information in it and take a
025: * different action.</p>
026: *
027: * <p>Since this exception is a subclass of {@link org.xml.sax.SAXException
028: * SAXException}, it inherits the ability to wrap another exception.</p>
029: *
030: * @since SAX 1.0
031: * @author David Megginson
032: * @version 2.0.1 (sax2r2)
033: * @see org.xml.sax.SAXException
034: * @see org.xml.sax.Locator
035: * @see org.xml.sax.ErrorHandler
036: */
037: public class SAXParseException extends SAXException {
038:
039: //////////////////////////////////////////////////////////////////////
040: // Constructors.
041: //////////////////////////////////////////////////////////////////////
042:
043: /**
044: * Create a new SAXParseException from a message and a Locator.
045: *
046: * <p>This constructor is especially useful when an application is
047: * creating its own exception from within a {@link org.xml.sax.ContentHandler
048: * ContentHandler} callback.</p>
049: *
050: * @param message The error or warning message.
051: * @param locator The locator object for the error or warning (may be
052: * null).
053: * @see org.xml.sax.Locator
054: */
055: public SAXParseException(String message, Locator locator) {
056: super (message);
057: if (locator != null) {
058: init(locator.getPublicId(), locator.getSystemId(), locator
059: .getLineNumber(), locator.getColumnNumber());
060: } else {
061: init(null, null, -1, -1);
062: }
063: }
064:
065: /**
066: * Wrap an existing exception in a SAXParseException.
067: *
068: * <p>This constructor is especially useful when an application is
069: * creating its own exception from within a {@link org.xml.sax.ContentHandler
070: * ContentHandler} callback, and needs to wrap an existing exception that is not a
071: * subclass of {@link org.xml.sax.SAXException SAXException}.</p>
072: *
073: * @param message The error or warning message, or null to
074: * use the message from the embedded exception.
075: * @param locator The locator object for the error or warning (may be
076: * null).
077: * @param e Any exception.
078: * @see org.xml.sax.Locator
079: */
080: public SAXParseException(String message, Locator locator,
081: Exception e) {
082: super (message, e);
083: if (locator != null) {
084: init(locator.getPublicId(), locator.getSystemId(), locator
085: .getLineNumber(), locator.getColumnNumber());
086: } else {
087: init(null, null, -1, -1);
088: }
089: }
090:
091: /**
092: * Create a new SAXParseException.
093: *
094: * <p>This constructor is most useful for parser writers.</p>
095: *
096: * <p>All parameters except the message are as if
097: * they were provided by a {@link Locator}. For example, if the
098: * system identifier is a URL (including relative filename), the
099: * caller must resolve it fully before creating the exception.</p>
100: *
101: *
102: * @param message The error or warning message.
103: * @param publicId The public identifer of the entity that generated
104: * the error or warning.
105: * @param systemId The system identifer of the entity that generated
106: * the error or warning.
107: * @param lineNumber The line number of the end of the text that
108: * caused the error or warning.
109: * @param columnNumber The column number of the end of the text that
110: * cause the error or warning.
111: */
112: public SAXParseException(String message, String publicId,
113: String systemId, int lineNumber, int columnNumber) {
114: super (message);
115: init(publicId, systemId, lineNumber, columnNumber);
116: }
117:
118: /**
119: * Create a new SAXParseException with an embedded exception.
120: *
121: * <p>This constructor is most useful for parser writers who
122: * need to wrap an exception that is not a subclass of
123: * {@link org.xml.sax.SAXException SAXException}.</p>
124: *
125: * <p>All parameters except the message and exception are as if
126: * they were provided by a {@link Locator}. For example, if the
127: * system identifier is a URL (including relative filename), the
128: * caller must resolve it fully before creating the exception.</p>
129: *
130: * @param message The error or warning message, or null to use
131: * the message from the embedded exception.
132: * @param publicId The public identifer of the entity that generated
133: * the error or warning.
134: * @param systemId The system identifer of the entity that generated
135: * the error or warning.
136: * @param lineNumber The line number of the end of the text that
137: * caused the error or warning.
138: * @param columnNumber The column number of the end of the text that
139: * cause the error or warning.
140: * @param e Another exception to embed in this one.
141: */
142: public SAXParseException(String message, String publicId,
143: String systemId, int lineNumber, int columnNumber,
144: Exception e) {
145: super (message, e);
146: init(publicId, systemId, lineNumber, columnNumber);
147: }
148:
149: /**
150: * Internal initialization method.
151: *
152: * @param publicId The public identifier of the entity which generated the exception,
153: * or null.
154: * @param systemId The system identifier of the entity which generated the exception,
155: * or null.
156: * @param lineNumber The line number of the error, or -1.
157: * @param columnNumber The column number of the error, or -1.
158: */
159: private void init(String publicId, String systemId, int lineNumber,
160: int columnNumber) {
161: this .publicId = publicId;
162: this .systemId = systemId;
163: this .lineNumber = lineNumber;
164: this .columnNumber = columnNumber;
165: }
166:
167: /**
168: * Get the public identifier of the entity where the exception occurred.
169: *
170: * @return A string containing the public identifier, or null
171: * if none is available.
172: * @see org.xml.sax.Locator#getPublicId
173: */
174: public String getPublicId() {
175: return this .publicId;
176: }
177:
178: /**
179: * Get the system identifier of the entity where the exception occurred.
180: *
181: * <p>If the system identifier is a URL, it will have been resolved
182: * fully.</p>
183: *
184: * @return A string containing the system identifier, or null
185: * if none is available.
186: * @see org.xml.sax.Locator#getSystemId
187: */
188: public String getSystemId() {
189: return this .systemId;
190: }
191:
192: /**
193: * The line number of the end of the text where the exception occurred.
194: *
195: * <p>The first line is line 1.</p>
196: *
197: * @return An integer representing the line number, or -1
198: * if none is available.
199: * @see org.xml.sax.Locator#getLineNumber
200: */
201: public int getLineNumber() {
202: return this .lineNumber;
203: }
204:
205: /**
206: * The column number of the end of the text where the exception occurred.
207: *
208: * <p>The first column in a line is position 1.</p>
209: *
210: * @return An integer representing the column number, or -1
211: * if none is available.
212: * @see org.xml.sax.Locator#getColumnNumber
213: */
214: public int getColumnNumber() {
215: return this .columnNumber;
216: }
217:
218: //////////////////////////////////////////////////////////////////////
219: // Internal state.
220: //////////////////////////////////////////////////////////////////////
221:
222: /**
223: * @serial The public identifier, or null.
224: * @see #getPublicId
225: */
226: private String publicId;
227:
228: /**
229: * @serial The system identifier, or null.
230: * @see #getSystemId
231: */
232: private String systemId;
233:
234: /**
235: * @serial The line number, or -1.
236: * @see #getLineNumber
237: */
238: private int lineNumber;
239:
240: /**
241: * @serial The column number, or -1.
242: * @see #getColumnNumber
243: */
244: private int columnNumber;
245:
246: }
247:
248: // end of SAXParseException.java
|