Save This Page
Home » openjdk-7 » org.xml » sax » [javadoc | source]
    1   /*
    2    * Copyright 2000-2005 Sun Microsystems, Inc.  All Rights Reserved.
    3    * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    4    *
    5    * This code is free software; you can redistribute it and/or modify it
    6    * under the terms of the GNU General Public License version 2 only, as
    7    * published by the Free Software Foundation.  Sun designates this
    8    * particular file as subject to the "Classpath" exception as provided
    9    * by Sun in the LICENSE file that accompanied this code.
   10    *
   11    * This code is distributed in the hope that it will be useful, but WITHOUT
   12    * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   13    * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   14    * version 2 for more details (a copy is included in the LICENSE file that
   15    * accompanied this code).
   16    *
   17    * You should have received a copy of the GNU General Public License version
   18    * 2 along with this work; if not, write to the Free Software Foundation,
   19    * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   20    *
   21    * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
   22    * CA 95054 USA or visit www.sun.com if you need additional information or
   23    * have any questions.
   24    */
   25   
   26   // SAX exception class.
   27   // http://www.saxproject.org
   28   // No warranty; no copyright -- use this as you will.
   29   // $Id: SAXParseException.java,v 1.2 2004/11/03 22:55:32 jsuttor Exp $
   30   
   31   package org.xml.sax;
   32   
   33   /**
   34    * Encapsulate an XML parse error or warning.
   35    *
   36    * <blockquote>
   37    * <em>This module, both source code and documentation, is in the
   38    * Public Domain, and comes with <strong>NO WARRANTY</strong>.</em>
   39    * See <a href='http://www.saxproject.org'>http://www.saxproject.org</a>
   40    * for further information.
   41    * </blockquote>
   42    *
   43    * <p>This exception may include information for locating the error
   44    * in the original XML document, as if it came from a {@link Locator}
   45    * object.  Note that although the application
   46    * will receive a SAXParseException as the argument to the handlers
   47    * in the {@link org.xml.sax.ErrorHandler ErrorHandler} interface,
   48    * the application is not actually required to throw the exception;
   49    * instead, it can simply read the information in it and take a
   50    * different action.</p>
   51    *
   52    * <p>Since this exception is a subclass of {@link org.xml.sax.SAXException
   53    * SAXException}, it inherits the ability to wrap another exception.</p>
   54    *
   55    * @since SAX 1.0
   56    * @author David Megginson
   57    * @see org.xml.sax.SAXException
   58    * @see org.xml.sax.Locator
   59    * @see org.xml.sax.ErrorHandler
   60    */
   61   public class SAXParseException extends SAXException {
   62   
   63   
   64       //////////////////////////////////////////////////////////////////////
   65       // Constructors.
   66       //////////////////////////////////////////////////////////////////////
   67   
   68   
   69       /**
   70        * Create a new SAXParseException from a message and a Locator.
   71        *
   72        * <p>This constructor is especially useful when an application is
   73        * creating its own exception from within a {@link org.xml.sax.ContentHandler
   74        * ContentHandler} callback.</p>
   75        *
   76        * @param message The error or warning message.
   77        * @param locator The locator object for the error or warning (may be
   78        *        null).
   79        * @see org.xml.sax.Locator
   80        */
   81       public SAXParseException (String message, Locator locator) {
   82           super(message);
   83           if (locator != null) {
   84               init(locator.getPublicId(), locator.getSystemId(),
   85                    locator.getLineNumber(), locator.getColumnNumber());
   86           } else {
   87               init(null, null, -1, -1);
   88           }
   89       }
   90   
   91   
   92       /**
   93        * Wrap an existing exception in a SAXParseException.
   94        *
   95        * <p>This constructor is especially useful when an application is
   96        * creating its own exception from within a {@link org.xml.sax.ContentHandler
   97        * ContentHandler} callback, and needs to wrap an existing exception that is not a
   98        * subclass of {@link org.xml.sax.SAXException SAXException}.</p>
   99        *
  100        * @param message The error or warning message, or null to
  101        *                use the message from the embedded exception.
  102        * @param locator The locator object for the error or warning (may be
  103        *        null).
  104        * @param e Any exception.
  105        * @see org.xml.sax.Locator
  106        */
  107       public SAXParseException (String message, Locator locator,
  108                                 Exception e) {
  109           super(message, e);
  110           if (locator != null) {
  111               init(locator.getPublicId(), locator.getSystemId(),
  112                    locator.getLineNumber(), locator.getColumnNumber());
  113           } else {
  114               init(null, null, -1, -1);
  115           }
  116       }
  117   
  118   
  119       /**
  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 if
  125        * they were provided by a {@link Locator}.  For example, if the
  126        * system identifier is a URL (including relative filename), the
  127        * 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 generated
  132        *                 the error or warning.
  133        * @param systemId The system identifier of the entity that generated
  134        *                 the error or warning.
  135        * @param lineNumber The line number of the end of the text that
  136        *                   caused the error or warning.
  137        * @param columnNumber The column number of the end of the text that
  138        *                     cause the error or warning.
  139        */
  140       public SAXParseException (String message, String publicId, String systemId,
  141                                 int lineNumber, int columnNumber)
  142       {
  143           super(message);
  144           init(publicId, systemId, lineNumber, columnNumber);
  145       }
  146   
  147   
  148       /**
  149        * Create a new SAXParseException with an embedded exception.
  150        *
  151        * <p>This constructor is most useful for parser writers who
  152        * need to wrap an exception that is not a subclass of
  153        * {@link org.xml.sax.SAXException SAXException}.</p>
  154        *
  155        * <p>All parameters except the message and exception are as if
  156        * they were provided by a {@link Locator}.  For example, if the
  157        * system identifier is a URL (including relative filename), the
  158        * caller must resolve it fully before creating the exception.</p>
  159        *
  160        * @param message The error or warning message, or null to use
  161        *                the message from the embedded exception.
  162        * @param publicId The public identifier of the entity that generated
  163        *                 the error or warning.
  164        * @param systemId The system identifier of the entity that generated
  165        *                 the error or warning.
  166        * @param lineNumber The line number of the end of the text that
  167        *                   caused the error or warning.
  168        * @param columnNumber The column number of the end of the text that
  169        *                     cause the error or warning.
  170        * @param e Another exception to embed in this one.
  171        */
  172       public SAXParseException (String message, String publicId, String systemId,
  173                                 int lineNumber, int columnNumber, Exception e)
  174       {
  175           super(message, e);
  176           init(publicId, systemId, lineNumber, columnNumber);
  177       }
  178   
  179   
  180       /**
  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        */
  190       private void init (String publicId, String systemId,
  191                          int lineNumber, int columnNumber)
  192       {
  193           this.publicId = publicId;
  194           this.systemId = systemId;
  195           this.lineNumber = lineNumber;
  196           this.columnNumber = columnNumber;
  197       }
  198   
  199   
  200       /**
  201        * Get the public identifier of the entity where the exception occurred.
  202        *
  203        * @return A string containing the public identifier, or null
  204        *         if none is available.
  205        * @see org.xml.sax.Locator#getPublicId
  206        */
  207       public String getPublicId ()
  208       {
  209           return this.publicId;
  210       }
  211   
  212   
  213       /**
  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 resolved
  217        * fully.</p>
  218        *
  219        * @return A string containing the system identifier, or null
  220        *         if none is available.
  221        * @see org.xml.sax.Locator#getSystemId
  222        */
  223       public String getSystemId ()
  224       {
  225           return this.systemId;
  226       }
  227   
  228   
  229       /**
  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 -1
  235        *         if none is available.
  236        * @see org.xml.sax.Locator#getLineNumber
  237        */
  238       public int getLineNumber ()
  239       {
  240           return this.lineNumber;
  241       }
  242   
  243   
  244       /**
  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 -1
  250        *         if none is available.
  251        * @see org.xml.sax.Locator#getColumnNumber
  252        */
  253       public int getColumnNumber ()
  254       {
  255           return this.columnNumber;
  256       }
  257   
  258   
  259       //////////////////////////////////////////////////////////////////////
  260       // Internal state.
  261       //////////////////////////////////////////////////////////////////////
  262   
  263   
  264       /**
  265        * @serial The public identifier, or null.
  266        * @see #getPublicId
  267        */
  268       private String publicId;
  269   
  270   
  271       /**
  272        * @serial The system identifier, or null.
  273        * @see #getSystemId
  274        */
  275       private String systemId;
  276   
  277   
  278       /**
  279        * @serial The line number, or -1.
  280        * @see #getLineNumber
  281        */
  282       private int lineNumber;
  283   
  284   
  285       /**
  286        * @serial The column number, or -1.
  287        * @see #getColumnNumber
  288        */
  289       private int columnNumber;
  290   
  291       // Added serialVersionUID to preserve binary compatibility
  292       static final long serialVersionUID = -5651165872476709336L;
  293   }
  294   
  295   // end of SAXParseException.java

Save This Page
Home » openjdk-7 » org.xml » sax » [javadoc | source]