1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/src/share/classes/sun/util/xml/XMLParseException.java Wed Jun 24 16:38:24 2009 +0200
1.3 @@ -0,0 +1,129 @@
1.4 +/* XMLParseException.java
1.5 + *
1.6 + * $Revision: 1.4 $
1.7 + * $Date: 2002/03/24 10:27:59 $
1.8 + * $Name: RELEASE_2_2_1 $
1.9 + *
1.10 + * This file is part of NanoXML 2 Lite.
1.11 + * Copyright (C) 2000-2002 Marc De Scheemaecker, All Rights Reserved.
1.12 + *
1.13 + * This software is provided 'as-is', without any express or implied warranty.
1.14 + * In no event will the authors be held liable for any damages arising from the
1.15 + * use of this software.
1.16 + *
1.17 + * Permission is granted to anyone to use this software for any purpose,
1.18 + * including commercial applications, and to alter it and redistribute it
1.19 + * freely, subject to the following restrictions:
1.20 + *
1.21 + * 1. The origin of this software must not be misrepresented; you must not
1.22 + * claim that you wrote the original software. If you use this software in
1.23 + * a product, an acknowledgment in the product documentation would be
1.24 + * appreciated but is not required.
1.25 + *
1.26 + * 2. Altered source versions must be plainly marked as such, and must not be
1.27 + * misrepresented as being the original software.
1.28 + *
1.29 + * 3. This notice may not be removed or altered from any source distribution.
1.30 + *****************************************************************************/
1.31 +
1.32 +
1.33 + package sun.util.xml;
1.34 +
1.35 +
1.36 +/**
1.37 + * An XMLParseException is thrown when an error occures while parsing an XML
1.38 + * string.
1.39 + * <P>
1.40 + * $Revision: 1.4 $<BR>
1.41 + * $Date: 2002/03/24 10:27:59 $<P>
1.42 + *
1.43 + * @see nanoxml.XMLElement
1.44 + *
1.45 + * @author Marc De Scheemaecker
1.46 + * @version $Name: RELEASE_2_2_1 $, $Revision: 1.4 $
1.47 + */
1.48 +class XMLParseException extends RuntimeException
1.49 +{
1.50 +
1.51 + /**
1.52 + * Indicates that no line number has been associated with this exception.
1.53 + */
1.54 + public static final int NO_LINE = -1;
1.55 +
1.56 +
1.57 + /**
1.58 + * The line number in the source code where the error occurred, or
1.59 + * <code>NO_LINE</code> if the line number is unknown.
1.60 + *
1.61 + * <dl><dt><b>Invariants:</b></dt><dd>
1.62 + * <ul><li><code>lineNr > 0 || lineNr == NO_LINE</code>
1.63 + * </ul></dd></dl>
1.64 + */
1.65 + private int lineNr;
1.66 +
1.67 +
1.68 + /**
1.69 + * Creates an exception.
1.70 + *
1.71 + * @param name The name of the element where the error is located.
1.72 + * @param message A message describing what went wrong.
1.73 + *
1.74 + * </dl><dl><dt><b>Preconditions:</b></dt><dd>
1.75 + * <ul><li><code>message != null</code>
1.76 + * </ul></dd></dl>
1.77 + *
1.78 + * <dl><dt><b>Postconditions:</b></dt><dd>
1.79 + * <ul><li>getLineNr() => NO_LINE
1.80 + * </ul></dd></dl><dl>
1.81 + */
1.82 + public XMLParseException(String name,
1.83 + String message)
1.84 + {
1.85 + super("XML Parse Exception during parsing of "
1.86 + + ((name == null) ? "the XML definition"
1.87 + : ("a " + name + " element"))
1.88 + + ": " + message);
1.89 + this.lineNr = XMLParseException.NO_LINE;
1.90 + }
1.91 +
1.92 +
1.93 + /**
1.94 + * Creates an exception.
1.95 + *
1.96 + * @param name The name of the element where the error is located.
1.97 + * @param lineNr The number of the line in the input.
1.98 + * @param message A message describing what went wrong.
1.99 + *
1.100 + * </dl><dl><dt><b>Preconditions:</b></dt><dd>
1.101 + * <ul><li><code>message != null</code>
1.102 + * <li><code>lineNr > 0</code>
1.103 + * </ul></dd></dl>
1.104 + *
1.105 + * <dl><dt><b>Postconditions:</b></dt><dd>
1.106 + * <ul><li>getLineNr() => lineNr
1.107 + * </ul></dd></dl><dl>
1.108 + */
1.109 + public XMLParseException(String name,
1.110 + int lineNr,
1.111 + String message)
1.112 + {
1.113 + super("XML Parse Exception during parsing of "
1.114 + + ((name == null) ? "the XML definition"
1.115 + : ("a " + name + " element"))
1.116 + + " at line " + lineNr + ": " + message);
1.117 + this.lineNr = lineNr;
1.118 + }
1.119 +
1.120 +
1.121 + /**
1.122 + * Where the error occurred, or <code>NO_LINE</code> if the line number is
1.123 + * unknown.
1.124 + *
1.125 + * @see nanoxml.XMLParseException#NO_LINE
1.126 + */
1.127 + public int getLineNr()
1.128 + {
1.129 + return this.lineNr;
1.130 + }
1.131 +
1.132 +}