View Javadoc

1   // SAX exception class.
2   // http://www.saxproject.org
3   // No warranty; no copyright -- use this as you will.
4   // $Id$
5   
6   package org.xml.sax;
7   
8   /***
9    * Encapsulate an XML parse error or warning.
10   *
11   * <blockquote>
12   * <em>This module, both source code and documentation, is in the
13   * Public Domain, and comes with <strong>NO WARRANTY</strong>.</em>
14   * See <a href='http://www.saxproject.org'>http://www.saxproject.org</a>
15   * for further information.
16   * </blockquote>
17   *
18   * <p>This exception may include information for locating the error
19   * in the original XML document, as if it came from a {@link Locator}
20   * object.  Note that although the application
21   * will receive a SAXParseException as the argument to the handlers
22   * in the {@link org.xml.sax.ErrorHandler ErrorHandler} interface, 
23   * the application is not actually required to throw the exception; 
24   * instead, it can simply read the information in it and take a 
25   * different action.</p>
26   *
27   * <p>Since this exception is a subclass of {@link org.xml.sax.SAXException 
28   * SAXException}, it inherits the ability to wrap another exception.</p>
29   *
30   * @since SAX 1.0
31   * @author David Megginson
32   * @version 2.0.1 (sax2r2)
33   * @see org.xml.sax.SAXException
34   * @see org.xml.sax.Locator
35   * @see org.xml.sax.ErrorHandler
36   */
37  public class SAXParseException extends SAXException {
38  
39  	//////////////////////////////////////////////////////////////////////
40  	// Constructors.
41  	//////////////////////////////////////////////////////////////////////
42  
43  	/***
44  	 * Create a new SAXParseException from a message and a Locator.
45  	 *
46  	 * <p>This constructor is especially useful when an application is
47  	 * creating its own exception from within a {@link org.xml.sax.ContentHandler
48  	 * ContentHandler} callback.</p>
49  	 *
50  	 * @param message The error or warning message.
51  	 * @param locator The locator object for the error or warning (may be
52  	 *        null).
53  	 * @see org.xml.sax.Locator
54  	 */
55  	public SAXParseException(String message, Locator locator) {
56  		super(message);
57  		if (locator != null) {
58  			init(locator.getPublicId(), locator.getSystemId(), locator.getLineNumber(), locator.getColumnNumber());
59  		} else {
60  			init(null, null, -1, -1);
61  		}
62  	}
63  
64  	/***
65  	 * Internal initialization method.
66  	 *
67  	 * @param publicId The public identifier of the entity which generated the exception,
68  	 *        or null.
69  	 * @param systemId The system identifier of the entity which generated the exception,
70  	 *        or null.
71  	 * @param lineNumber The line number of the error, or -1.
72  	 * @param columnNumber The column number of the error, or -1.
73  	 */
74  	private void init(String publicId, String systemId, int lineNumber, int columnNumber) {
75  		this.publicId = publicId;
76  		this.systemId = systemId;
77  		this.lineNumber = lineNumber;
78  		this.columnNumber = columnNumber;
79  	}
80  
81  	/***
82  	 * Get the public identifier of the entity where the exception occurred.
83  	 *
84  	 * @return A string containing the public identifier, or null
85  	 *         if none is available.
86  	 * @see org.xml.sax.Locator#getPublicId
87  	 */
88  	public String getPublicId() {
89  		return this.publicId;
90  	}
91  
92  	/***
93  	 * Get the system identifier of the entity where the exception occurred.
94  	 *
95  	 * <p>If the system identifier is a URL, it will have been resolved
96  	 * fully.</p>
97  	 *
98  	 * @return A string containing the system identifier, or null
99  	 *         if none is available.
100 	 * @see org.xml.sax.Locator#getSystemId
101 	 */
102 	public String getSystemId() {
103 		return this.systemId;
104 	}
105 
106 	/***
107 	 * The line number of the end of the text where the exception occurred.
108 	 *
109 	 * <p>The first line is line 1.</p>
110 	 *
111 	 * @return An integer representing the line number, or -1
112 	 *         if none is available.
113 	 * @see org.xml.sax.Locator#getLineNumber
114 	 */
115 	public int getLineNumber() {
116 		return this.lineNumber;
117 	}
118 
119 	/***
120 	 * The column number of the end of the text where the exception occurred.
121 	 *
122 	 * <p>The first column in a line is position 1.</p>
123 	 *
124 	 * @return An integer representing the column number, or -1
125 	 *         if none is available.
126 	 * @see org.xml.sax.Locator#getColumnNumber
127 	 */
128 	public int getColumnNumber() {
129 		return this.columnNumber;
130 	}
131 
132 	//////////////////////////////////////////////////////////////////////
133 	// Internal state.
134 	//////////////////////////////////////////////////////////////////////
135 
136 	/***
137 	 * @serial The public identifier, or null.
138 	 * @see #getPublicId
139 	 */
140 	private String publicId;
141 
142 	/***
143 	 * @serial The system identifier, or null.
144 	 * @see #getSystemId
145 	 */
146 	private String systemId;
147 
148 	/***
149 	 * @serial The line number, or -1.
150 	 * @see #getLineNumber
151 	 */
152 	private int lineNumber;
153 
154 	/***
155 	 * @serial The column number, or -1.
156 	 * @see #getColumnNumber
157 	 */
158 	private int columnNumber;
159 
160 }
161 
162 // end of SAXParseException.java