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