Path: blob/aarch64-shenandoah-jdk8u272-b10/jaxp/src/org/xml/sax/SAXParseException.java
48534 views
/*1* Copyright (c) 2000, 2005, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425// SAX exception class.26// http://www.saxproject.org27// No warranty; no copyright -- use this as you will.28// $Id: SAXParseException.java,v 1.2 2004/11/03 22:55:32 jsuttor Exp $2930package org.xml.sax;3132/**33* Encapsulate an XML parse error or warning.34*35* <blockquote>36* <em>This module, both source code and documentation, is in the37* Public Domain, and comes with <strong>NO WARRANTY</strong>.</em>38* See <a href='http://www.saxproject.org'>http://www.saxproject.org</a>39* for further information.40* </blockquote>41*42* <p>This exception may include information for locating the error43* in the original XML document, as if it came from a {@link Locator}44* object. Note that although the application45* will receive a SAXParseException as the argument to the handlers46* in the {@link org.xml.sax.ErrorHandler ErrorHandler} interface,47* the application is not actually required to throw the exception;48* instead, it can simply read the information in it and take a49* different action.</p>50*51* <p>Since this exception is a subclass of {@link org.xml.sax.SAXException52* SAXException}, it inherits the ability to wrap another exception.</p>53*54* @since SAX 1.055* @author David Megginson56* @version 2.0.1 (sax2r2)57* @see org.xml.sax.SAXException58* @see org.xml.sax.Locator59* @see org.xml.sax.ErrorHandler60*/61public class SAXParseException extends SAXException {626364//////////////////////////////////////////////////////////////////////65// Constructors.66//////////////////////////////////////////////////////////////////////676869/**70* Create a new SAXParseException from a message and a Locator.71*72* <p>This constructor is especially useful when an application is73* creating its own exception from within a {@link org.xml.sax.ContentHandler74* ContentHandler} callback.</p>75*76* @param message The error or warning message.77* @param locator The locator object for the error or warning (may be78* null).79* @see org.xml.sax.Locator80*/81public SAXParseException (String message, Locator locator) {82super(message);83if (locator != null) {84init(locator.getPublicId(), locator.getSystemId(),85locator.getLineNumber(), locator.getColumnNumber());86} else {87init(null, null, -1, -1);88}89}909192/**93* Wrap an existing exception in a SAXParseException.94*95* <p>This constructor is especially useful when an application is96* creating its own exception from within a {@link org.xml.sax.ContentHandler97* ContentHandler} callback, and needs to wrap an existing exception that is not a98* subclass of {@link org.xml.sax.SAXException SAXException}.</p>99*100* @param message The error or warning message, or null to101* use the message from the embedded exception.102* @param locator The locator object for the error or warning (may be103* null).104* @param e Any exception.105* @see org.xml.sax.Locator106*/107public SAXParseException (String message, Locator locator,108Exception e) {109super(message, e);110if (locator != null) {111init(locator.getPublicId(), locator.getSystemId(),112locator.getLineNumber(), locator.getColumnNumber());113} else {114init(null, null, -1, -1);115}116}117118119/**120* Create a new SAXParseException.121*122* <p>This constructor is most useful for parser writers.</p>123*124* <p>All parameters except the message are as if125* they were provided by a {@link Locator}. For example, if the126* system identifier is a URL (including relative filename), the127* caller must resolve it fully before creating the exception.</p>128*129*130* @param message The error or warning message.131* @param publicId The public identifier of the entity that generated132* the error or warning.133* @param systemId The system identifier of the entity that generated134* the error or warning.135* @param lineNumber The line number of the end of the text that136* caused the error or warning.137* @param columnNumber The column number of the end of the text that138* cause the error or warning.139*/140public SAXParseException (String message, String publicId, String systemId,141int lineNumber, int columnNumber)142{143super(message);144init(publicId, systemId, lineNumber, columnNumber);145}146147148/**149* Create a new SAXParseException with an embedded exception.150*151* <p>This constructor is most useful for parser writers who152* need to wrap an exception that is not a subclass of153* {@link org.xml.sax.SAXException SAXException}.</p>154*155* <p>All parameters except the message and exception are as if156* they were provided by a {@link Locator}. For example, if the157* system identifier is a URL (including relative filename), the158* caller must resolve it fully before creating the exception.</p>159*160* @param message The error or warning message, or null to use161* the message from the embedded exception.162* @param publicId The public identifier of the entity that generated163* the error or warning.164* @param systemId The system identifier of the entity that generated165* the error or warning.166* @param lineNumber The line number of the end of the text that167* caused the error or warning.168* @param columnNumber The column number of the end of the text that169* cause the error or warning.170* @param e Another exception to embed in this one.171*/172public SAXParseException (String message, String publicId, String systemId,173int lineNumber, int columnNumber, Exception e)174{175super(message, e);176init(publicId, systemId, lineNumber, columnNumber);177}178179180/**181* Internal initialization method.182*183* @param publicId The public identifier of the entity which generated the exception,184* or null.185* @param systemId The system identifier of the entity which generated the exception,186* or null.187* @param lineNumber The line number of the error, or -1.188* @param columnNumber The column number of the error, or -1.189*/190private void init (String publicId, String systemId,191int lineNumber, int columnNumber)192{193this.publicId = publicId;194this.systemId = systemId;195this.lineNumber = lineNumber;196this.columnNumber = columnNumber;197}198199200/**201* Get the public identifier of the entity where the exception occurred.202*203* @return A string containing the public identifier, or null204* if none is available.205* @see org.xml.sax.Locator#getPublicId206*/207public String getPublicId ()208{209return this.publicId;210}211212213/**214* Get the system identifier of the entity where the exception occurred.215*216* <p>If the system identifier is a URL, it will have been resolved217* fully.</p>218*219* @return A string containing the system identifier, or null220* if none is available.221* @see org.xml.sax.Locator#getSystemId222*/223public String getSystemId ()224{225return this.systemId;226}227228229/**230* The line number of the end of the text where the exception occurred.231*232* <p>The first line is line 1.</p>233*234* @return An integer representing the line number, or -1235* if none is available.236* @see org.xml.sax.Locator#getLineNumber237*/238public int getLineNumber ()239{240return this.lineNumber;241}242243244/**245* The column number of the end of the text where the exception occurred.246*247* <p>The first column in a line is position 1.</p>248*249* @return An integer representing the column number, or -1250* if none is available.251* @see org.xml.sax.Locator#getColumnNumber252*/253public int getColumnNumber ()254{255return this.columnNumber;256}257258/**259* Override toString to provide more detailed error message.260*261* @return A string representation of this exception.262*/263public String toString() {264StringBuilder buf = new StringBuilder(getClass().getName());265String message = getLocalizedMessage();266if (publicId!=null) buf.append("publicId: ").append(publicId);267if (systemId!=null) buf.append("; systemId: ").append(systemId);268if (lineNumber!=-1) buf.append("; lineNumber: ").append(lineNumber);269if (columnNumber!=-1) buf.append("; columnNumber: ").append(columnNumber);270271//append the exception message at the end272if (message!=null) buf.append("; ").append(message);273return buf.toString();274}275276//////////////////////////////////////////////////////////////////////277// Internal state.278//////////////////////////////////////////////////////////////////////279280281/**282* @serial The public identifier, or null.283* @see #getPublicId284*/285private String publicId;286287288/**289* @serial The system identifier, or null.290* @see #getSystemId291*/292private String systemId;293294295/**296* @serial The line number, or -1.297* @see #getLineNumber298*/299private int lineNumber;300301302/**303* @serial The column number, or -1.304* @see #getColumnNumber305*/306private int columnNumber;307308// Added serialVersionUID to preserve binary compatibility309static final long serialVersionUID = -5651165872476709336L;310}311312// end of SAXParseException.java313314315