001: package com.rimfaxe.xml.xmlreader;
002:
003: /** Thrown when error parsing XML or XPath.
004:
005: <blockquote><small> Copyright (C) 2002 Hewlett-Packard Company.
006: This file is part of Sparta, an XML Parser, DOM, and XPath library.
007: This library is free software; you can redistribute it and/or
008: modify it under the terms of the GNU Lesser General Public License
009: as published by the Free Software Foundation; either version 2.1 of
010: the License, or (at your option) any later version. This library
011: is distributed in the hope that it will be useful, but WITHOUT ANY
012: WARRANTY; without even the implied warranty of MERCHANTABILITY or
013: FITNESS FOR A PARTICULAR PURPOSE.</small></blockquote>
014: @see <a "href="doc-files/LGPL.txt">GNU Lesser General Public License</a>
015: @version $Date: 2002/08/19 05:03:58 $ $Revision: 1.1.1.1 $
016: @author Eamonn O'Brien-Strain
017: */
018: public class ParseException extends Exception {
019:
020: public ParseException(String msg) {
021: super (msg);
022: }
023:
024: /* For use by handlers */
025: public ParseException(String msg, Throwable cause) {
026: super (msg + " " + cause);
027: this .cause_ = cause;
028: }
029:
030: /* Using systemID */
031: public ParseException(String systemId, int lineNumber,
032: int lastCharRead, String history, String msg) {
033: super (toMessage(systemId, lineNumber, lastCharRead, history,
034: msg));
035: lineNumber_ = lineNumber;
036: }
037:
038: public ParseException(ParseLog log, String systemId,
039: int lineNumber, int lastCharRead, String history, String msg) {
040: this (systemId, lineNumber, lastCharRead, history, msg);
041: log.error(msg, systemId, lineNumber);
042: }
043:
044: public ParseException(ParseCharStream source, String msg) {
045: this (source.getLog(), source.getSystemId(), source
046: .getLineNumber(), source.getLastCharRead(), source
047: .getHistory(), msg);
048: }
049:
050: public ParseException(ParseCharStream source, char actual,
051: char expected) {
052: this (source, "got \'" + actual + "\' instead of expected \'"
053: + expected + "\'");
054: }
055:
056: /** Precondition: expected.length > 0 */
057: public ParseException(ParseCharStream source, char actual,
058: char[] expected) {
059: this (source, "got \'" + actual + "\' instead of "
060: + toString(expected));
061: }
062:
063: public ParseException(ParseCharStream source, char actual,
064: String expected) {
065: this (source, "got \'" + actual + "\' instead of " + expected
066: + " as expected");
067: }
068:
069: public ParseException(ParseCharStream source, String actual,
070: String expected) {
071: this (source, "got \"" + actual + "\" instead of \"" + expected
072: + "\" as expected");
073: }
074:
075: static private String toString(char[] chars) {
076: StringBuffer result = new StringBuffer();
077: result.append(chars[0]);
078: for (int i = 1; i < chars.length; ++i)
079: result.append("or " + chars[i]);
080: return result.toString();
081: }
082:
083: public ParseException(ParseCharStream source, String actual,
084: char[] expected) {
085: this (source, actual, new String(expected));
086: }
087:
088: public int getLineNumber() {
089: return lineNumber_;
090: }
091:
092: private int lineNumber_ = -1;
093:
094: public Throwable getCause() {
095: return cause_;
096: }
097:
098: //////////////////////////////////////////////////////////////////
099:
100: /*static private String toMessage(ParseCharStream source, String msg){
101: return toMessage( source.getSystemId(),
102: source.getLineNumber(),
103: source.getLastCharRead(),
104: source.getHistory(),
105: msg );
106: }*/
107:
108: static private String toMessage(String systemId, int lineNumber,
109: int lastCharRead, String history, String msg) {
110: return systemId + "(" + lineNumber + "): \n" + history
111: + "\nLast character read was \'"
112: + charRepr(lastCharRead) + "\'\n" + msg;
113: }
114:
115: static String charRepr(int ch) {
116: return (ch == -1) ? "EOF" : ("" + (char) ch);
117: }
118:
119: private Throwable cause_ = null;
120:
121: }
122:
123: // $Log: ParseException.java,v $
124: // Revision 1.1.1.1 2002/08/19 05:03:58 eobrain
125: // import from HP Labs internal CVS
126: //
127: // Revision 1.13 2002/08/18 04:37:56 eob
128: // Add copyright and other formatting and commenting in preparation for
129: // release to SourceForge.
130: //
131: // Revision 1.12 2002/08/09 22:36:49 sermarti
132: //
133: // Revision 1.11 2002/08/05 20:04:32 sermarti
134: //
135: // Revision 1.10 2002/07/25 21:10:15 sermarti
136: // Adding files that mysteriously weren't added from Sparta before.
137: //
138: // Revision 1.9 2002/05/23 21:29:32 eob
139: // Tweaks.
140: //
141: // Revision 1.8 2002/05/09 20:58:30 eob
142: // Add protected constructor to allow sub-classes without supplying all
143: // other info.
144: //
145: // Revision 1.7 2002/05/09 16:50:21 eob
146: // Add history for better error reporting.
147: //
148: // Revision 1.6 2002/01/08 19:51:02 eob
149: // Factored out constructors for more flexibilty.
150: //
151: // Revision 1.5 2002/01/04 00:38:40 eob
152: // Improve logging.
153: //
154: // Revision 1.4 2002/01/04 16:52:40 eob
155: // Comment change only.
156: //
157: // Revision 1.3 2002/01/04 16:52:10 eob
158: // Add constructors.
159: //
160: // Revision 1.2 2001/12/20 20:07:49 eob
161: // Added constructor that takes 2 strings. Add getLineNumber method.
162: //
163: // Revision 1.1 2001/12/19 05:52:38 eob
164: // initial
|