01: package com.rimfaxe.xml.xmlreader.xpath;
02:
03: import java.io.*;
04:
05: /** Thrown when some problem parsing or executing an XPath expression.
06:
07: <blockquote><small> Copyright (C) 2002 Hewlett-Packard Company.
08: This file is part of Sparta, an XML Parser, DOM, and XPath library.
09: This library is free software; you can redistribute it and/or
10: modify it under the terms of the <a href="doc-files/LGPL.txt">GNU
11: Lesser General Public License</a> as published by the Free Software
12: Foundation; either version 2.1 of the License, or (at your option)
13: any later version. This library is distributed in the hope that it
14: will be useful, but WITHOUT ANY WARRANTY; without even the implied
15: warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
16: PURPOSE. </small></blockquote>
17: @version $Date: 2002/08/19 05:04:02 $ $Revision: 1.1.1.1 $
18: @author Eamonn O'Brien-Strain
19: */
20:
21: public class XPathException extends Exception {
22:
23: public XPathException(XPath xpath, String msg) {
24: super (xpath + " " + msg);
25: }
26:
27: XPathException(XPath xpath, String where, StreamTokenizer toks,
28: String expected) {
29: this (xpath, where + " got \"" + toString(toks)
30: + "\" instead of expected " + expected);
31: }
32:
33: XPathException(XPath xpath, Exception cause) {
34: super (xpath + " " + cause);
35: cause_ = cause;
36: }
37:
38: public Throwable getCause() {
39: return cause_;
40: }
41:
42: static private String toString(StreamTokenizer toks) {
43: try {
44: StringBuffer result = new StringBuffer();
45: result.append(tokenToString(toks));
46: if (toks.ttype != toks.TT_EOF) {
47: toks.nextToken();
48: result.append(tokenToString(toks));
49: toks.pushBack();
50: }
51: return result.toString();
52: } catch (IOException e) {
53: return "(cannot get info: " + e + ")";
54: }
55: }
56:
57: static private String tokenToString(StreamTokenizer toks) {
58: switch (toks.ttype) {
59: case StreamTokenizer.TT_EOF:
60: return "<end of expression>";
61: case StreamTokenizer.TT_EOL:
62: throw new Error(
63: "Assertion failure, linebreaks cannot be special");
64: case StreamTokenizer.TT_NUMBER:
65: return toks.nval + "";
66: case StreamTokenizer.TT_WORD:
67: return toks.sval;
68: default:
69: return (char) toks.ttype + "";
70: }
71: }
72:
73: private Throwable cause_ = null;
74: }
75:
76: // $Log: XPathException.java,v $
77: // Revision 1.1.1.1 2002/08/19 05:04:02 eobrain
78: // import from HP Labs internal CVS
79: //
80: // Revision 1.4 2002/08/18 23:39:32 eob
81: // Add copyright and other formatting and commenting in preparation for
82: // release to SourceForge.
83: //
84: // Revision 1.3 2002/08/15 05:11:57 eob
85: // add cause
86: //
87: // Revision 1.2 2002/05/23 21:07:07 eob
88: // Better error reporting.
89: //
90: // Revision 1.1 2002/01/24 22:11:35 eob
91: // initial
|