1. // SAX exception class.
  2. // http://www.saxproject.org
  3. // No warranty; no copyright -- use this as you will.
  4. // $Id: SAXParseException.java,v 1.1.24.1.2.1 2004/06/08 22:44:57 rameshm Exp $
  5. package org.xml.sax;
  6. /**
  7. * Encapsulate an XML parse error or warning.
  8. *
  9. * <blockquote>
  10. * <em>This module, both source code and documentation, is in the
  11. * Public Domain, and comes with <strong>NO WARRANTY</strong>.</em>
  12. * See <a href='http://www.saxproject.org'>http://www.saxproject.org</a>
  13. * for further information.
  14. * </blockquote>
  15. *
  16. * <p>This exception may include information for locating the error
  17. * in the original XML document, as if it came from a {@link Locator}
  18. * object. Note that although the application
  19. * will receive a SAXParseException as the argument to the handlers
  20. * in the {@link org.xml.sax.ErrorHandler ErrorHandler} interface,
  21. * the application is not actually required to throw the exception;
  22. * instead, it can simply read the information in it and take a
  23. * different action.</p>
  24. *
  25. * <p>Since this exception is a subclass of {@link org.xml.sax.SAXException
  26. * SAXException}, it inherits the ability to wrap another exception.</p>
  27. *
  28. * @since SAX 1.0
  29. * @author David Megginson
  30. * @version 2.0.1 (sax2r2)
  31. * @see org.xml.sax.SAXException
  32. * @see org.xml.sax.Locator
  33. * @see org.xml.sax.ErrorHandler
  34. */
  35. public class SAXParseException extends SAXException {
  36. //////////////////////////////////////////////////////////////////////
  37. // Constructors.
  38. //////////////////////////////////////////////////////////////////////
  39. /**
  40. * Create a new SAXParseException from a message and a Locator.
  41. *
  42. * <p>This constructor is especially useful when an application is
  43. * creating its own exception from within a {@link org.xml.sax.ContentHandler
  44. * ContentHandler} callback.</p>
  45. *
  46. * @param message The error or warning message.
  47. * @param locator The locator object for the error or warning (may be
  48. * null).
  49. * @see org.xml.sax.Locator
  50. */
  51. public SAXParseException (String message, Locator locator) {
  52. super(message);
  53. if (locator != null) {
  54. init(locator.getPublicId(), locator.getSystemId(),
  55. locator.getLineNumber(), locator.getColumnNumber());
  56. } else {
  57. init(null, null, -1, -1);
  58. }
  59. }
  60. /**
  61. * Wrap an existing exception in a SAXParseException.
  62. *
  63. * <p>This constructor is especially useful when an application is
  64. * creating its own exception from within a {@link org.xml.sax.ContentHandler
  65. * ContentHandler} callback, and needs to wrap an existing exception that is not a
  66. * subclass of {@link org.xml.sax.SAXException SAXException}.</p>
  67. *
  68. * @param message The error or warning message, or null to
  69. * use the message from the embedded exception.
  70. * @param locator The locator object for the error or warning (may be
  71. * null).
  72. * @param e Any exception.
  73. * @see org.xml.sax.Locator
  74. */
  75. public SAXParseException (String message, Locator locator,
  76. Exception e) {
  77. super(message, e);
  78. if (locator != null) {
  79. init(locator.getPublicId(), locator.getSystemId(),
  80. locator.getLineNumber(), locator.getColumnNumber());
  81. } else {
  82. init(null, null, -1, -1);
  83. }
  84. }
  85. /**
  86. * Create a new SAXParseException.
  87. *
  88. * <p>This constructor is most useful for parser writers.</p>
  89. *
  90. * <p>All parameters except the message are as if
  91. * they were provided by a {@link Locator}. For example, if the
  92. * system identifier is a URL (including relative filename), the
  93. * caller must resolve it fully before creating the exception.</p>
  94. *
  95. *
  96. * @param message The error or warning message.
  97. * @param publicId The public identifier of the entity that generated
  98. * the error or warning.
  99. * @param systemId The system identifier of the entity that generated
  100. * the error or warning.
  101. * @param lineNumber The line number of the end of the text that
  102. * caused the error or warning.
  103. * @param columnNumber The column number of the end of the text that
  104. * cause the error or warning.
  105. */
  106. public SAXParseException (String message, String publicId, String systemId,
  107. int lineNumber, int columnNumber)
  108. {
  109. super(message);
  110. init(publicId, systemId, lineNumber, columnNumber);
  111. }
  112. /**
  113. * Create a new SAXParseException with an embedded exception.
  114. *
  115. * <p>This constructor is most useful for parser writers who
  116. * need to wrap an exception that is not a subclass of
  117. * {@link org.xml.sax.SAXException SAXException}.</p>
  118. *
  119. * <p>All parameters except the message and exception are as if
  120. * they were provided by a {@link Locator}. For example, if the
  121. * system identifier is a URL (including relative filename), the
  122. * caller must resolve it fully before creating the exception.</p>
  123. *
  124. * @param message The error or warning message, or null to use
  125. * the message from the embedded exception.
  126. * @param publicId The public identifier of the entity that generated
  127. * the error or warning.
  128. * @param systemId The system identifier of the entity that generated
  129. * the error or warning.
  130. * @param lineNumber The line number of the end of the text that
  131. * caused the error or warning.
  132. * @param columnNumber The column number of the end of the text that
  133. * cause the error or warning.
  134. * @param e Another exception to embed in this one.
  135. */
  136. public SAXParseException (String message, String publicId, String systemId,
  137. int lineNumber, int columnNumber, Exception e)
  138. {
  139. super(message, e);
  140. init(publicId, systemId, lineNumber, columnNumber);
  141. }
  142. /**
  143. * Internal initialization method.
  144. *
  145. * @param publicId The public identifier of the entity which generated the exception,
  146. * or null.
  147. * @param systemId The system identifier of the entity which generated the exception,
  148. * or null.
  149. * @param lineNumber The line number of the error, or -1.
  150. * @param columnNumber The column number of the error, or -1.
  151. */
  152. private void init (String publicId, String systemId,
  153. int lineNumber, int columnNumber)
  154. {
  155. this.publicId = publicId;
  156. this.systemId = systemId;
  157. this.lineNumber = lineNumber;
  158. this.columnNumber = columnNumber;
  159. }
  160. /**
  161. * Get the public identifier of the entity where the exception occurred.
  162. *
  163. * @return A string containing the public identifier, or null
  164. * if none is available.
  165. * @see org.xml.sax.Locator#getPublicId
  166. */
  167. public String getPublicId ()
  168. {
  169. return this.publicId;
  170. }
  171. /**
  172. * Get the system identifier of the entity where the exception occurred.
  173. *
  174. * <p>If the system identifier is a URL, it will have been resolved
  175. * fully.</p>
  176. *
  177. * @return A string containing the system identifier, or null
  178. * if none is available.
  179. * @see org.xml.sax.Locator#getSystemId
  180. */
  181. public String getSystemId ()
  182. {
  183. return this.systemId;
  184. }
  185. /**
  186. * The line number of the end of the text where the exception occurred.
  187. *
  188. * <p>The first line is line 1.</p>
  189. *
  190. * @return An integer representing the line number, or -1
  191. * if none is available.
  192. * @see org.xml.sax.Locator#getLineNumber
  193. */
  194. public int getLineNumber ()
  195. {
  196. return this.lineNumber;
  197. }
  198. /**
  199. * The column number of the end of the text where the exception occurred.
  200. *
  201. * <p>The first column in a line is position 1.</p>
  202. *
  203. * @return An integer representing the column number, or -1
  204. * if none is available.
  205. * @see org.xml.sax.Locator#getColumnNumber
  206. */
  207. public int getColumnNumber ()
  208. {
  209. return this.columnNumber;
  210. }
  211. //////////////////////////////////////////////////////////////////////
  212. // Internal state.
  213. //////////////////////////////////////////////////////////////////////
  214. /**
  215. * @serial The public identifier, or null.
  216. * @see #getPublicId
  217. */
  218. private String publicId;
  219. /**
  220. * @serial The system identifier, or null.
  221. * @see #getSystemId
  222. */
  223. private String systemId;
  224. /**
  225. * @serial The line number, or -1.
  226. * @see #getLineNumber
  227. */
  228. private int lineNumber;
  229. /**
  230. * @serial The column number, or -1.
  231. * @see #getColumnNumber
  232. */
  233. private int columnNumber;
  234. // Added serialVersionUID to preserve binary compatibility
  235. static final long serialVersionUID = -5651165872476709336L;
  236. }
  237. // end of SAXParseException.java