001: // SAX exception class.
002: // No warranty; no copyright -- use this as you will.
003: // $Id: SAXParseException.java,v 1.2 2005/03/25 14:58:33 csilva Exp $
004:
005: package org.xml.sax;
006:
007: /**
008: * Encapsulate an XML parse error or warning.
009: *
010: * <p>This exception will include information for locating the error
011: * in the original XML document. Note that although the application
012: * will receive a SAXParseException as the argument to the handlers
013: * in the ErrorHandler interface, the application is not actually
014: * required to throw the exception; instead, it can simply read the
015: * information in it and take a different action.</p>
016: *
017: * <p>Since this exception is a subclass of SAXException, it
018: * inherits the ability to wrap another exception.</p>
019: *
020: * @author David Megginson (ak117@freenet.carleton.ca)
021: * @version 1.0
022: * @see org.xml.sax.SAXException
023: * @see org.xml.sax.Locator
024: * @see org.xml.sax.ErrorHandler
025: */
026: public class SAXParseException extends SAXException {
027: private static final long serialVersionUID = 3257569507558897205L;
028:
029: //////////////////////////////////////////////////////////////////////
030: // Constructors.
031: //////////////////////////////////////////////////////////////////////
032:
033: /**
034: * Create a new SAXParseException from a message and a Locator.
035: *
036: * <p>This constructor is especially useful when an application is
037: * creating its own exception from within a DocumentHandler
038: * callback.</p>
039: *
040: * @param message The error or warning message.
041: * @param locator The locator object for the error or warning.
042: * @see org.xml.sax.Locator
043: * @see org.xml.sax.Parser#setLocale
044: */
045: public SAXParseException(String message, Locator locator) {
046: super (message);
047: this .publicId = locator.getPublicId();
048: this .systemId = locator.getSystemId();
049: this .lineNumber = locator.getLineNumber();
050: this .columnNumber = locator.getColumnNumber();
051: }
052:
053: /**
054: * Wrap an existing exception in a SAXParseException.
055: *
056: * <p>This constructor is especially useful when an application is
057: * creating its own exception from within a DocumentHandler
058: * callback, and needs to wrap an existing exception that is not a
059: * subclass of SAXException.</p>
060: *
061: * @param message The error or warning message, or null to
062: * use the message from the embedded exception.
063: * @param locator The locator object for the error or warning.
064: * @param e Any exception
065: * @see org.xml.sax.Locator
066: * @see org.xml.sax.Parser#setLocale
067: */
068: public SAXParseException(String message, Locator locator,
069: Exception e) {
070: super (message, e);
071: this .publicId = locator.getPublicId();
072: this .systemId = locator.getSystemId();
073: this .lineNumber = locator.getLineNumber();
074: this .columnNumber = locator.getColumnNumber();
075: }
076:
077: /**
078: * Create a new SAXParseException.
079: *
080: * <p>This constructor is most useful for parser writers.</p>
081: *
082: * <p>If the system identifier is a URL, the parser must resolve it
083: * fully before creating the exception.</p>
084: *
085: * @param message The error or warning message.
086: * @param publicId The public identifer of the entity that generated
087: * the error or warning.
088: * @param systemId The system identifer of the entity that generated
089: * the error or warning.
090: * @param lineNumber The line number of the end of the text that
091: * caused the error or warning.
092: * @param columnNumber The column number of the end of the text that
093: * cause the error or warning.
094: * @see org.xml.sax.Parser#setLocale
095: */
096: public SAXParseException(String message, String publicId,
097: String systemId, int lineNumber, int columnNumber) {
098: super (message);
099: this .publicId = publicId;
100: this .systemId = systemId;
101: this .lineNumber = lineNumber;
102: this .columnNumber = columnNumber;
103: }
104:
105: /**
106: * Create a new SAXParseException with an embedded exception.
107: *
108: * <p>This constructor is most useful for parser writers who
109: * need to wrap an exception that is not a subclass of
110: * SAXException.</p>
111: *
112: * <p>If the system identifier is a URL, the parser must resolve it
113: * fully before creating the exception.</p>
114: *
115: * @param message The error or warning message, or null to use
116: * the message from the embedded exception.
117: * @param publicId The public identifer of the entity that generated
118: * the error or warning.
119: * @param systemId The system identifer of the entity that generated
120: * the error or warning.
121: * @param lineNumber The line number of the end of the text that
122: * caused the error or warning.
123: * @param columnNumber The column number of the end of the text that
124: * cause the error or warning.
125: * @param e Another exception to embed in this one.
126: * @see org.xml.sax.Parser#setLocale
127: */
128: public SAXParseException(String message, String publicId,
129: String systemId, int lineNumber, int columnNumber,
130: Exception e) {
131: super (message, e);
132: this .publicId = publicId;
133: this .systemId = systemId;
134: this .lineNumber = lineNumber;
135: this .columnNumber = columnNumber;
136: }
137:
138: /**
139: * Get the public identifier of the entity where the exception occurred.
140: *
141: * @return A string containing the public identifier, or null
142: * if none is available.
143: * @see org.xml.sax.Locator#getPublicId
144: */
145: public String getPublicId() {
146: return this .publicId;
147: }
148:
149: /**
150: * Get the system identifier of the entity where the exception occurred.
151: *
152: * <p>If the system identifier is a URL, it will be resolved
153: * fully.</p>
154: *
155: * @return A string containing the system identifier, or null
156: * if none is available.
157: * @see org.xml.sax.Locator#getSystemId
158: */
159: public String getSystemId() {
160: return this .systemId;
161: }
162:
163: /**
164: * The line number of the end of the text where the exception occurred.
165: *
166: * @return An integer representing the line number, or -1
167: * if none is available.
168: * @see org.xml.sax.Locator#getLineNumber
169: */
170: public int getLineNumber() {
171: return this .lineNumber;
172: }
173:
174: /**
175: * The column number of the end of the text where the exception occurred.
176: *
177: * <p>The first column in a line is position 1.</p>
178: *
179: * @return An integer representing the column number, or -1
180: * if none is available.
181: * @see org.xml.sax.Locator#getColumnNumber
182: */
183: public int getColumnNumber() {
184: return this .columnNumber;
185: }
186:
187: //////////////////////////////////////////////////////////////////////
188: // Internal state.
189: //////////////////////////////////////////////////////////////////////
190:
191: private String publicId;
192: private String systemId;
193: private int lineNumber;
194: private int columnNumber;
195:
196: }
|