01: package gnu.xquery.util;
02:
03: import gnu.mapping.*;
04:
05: public class XQException extends RuntimeException {
06:
07: public Symbol code;
08: public String description;
09: public Object errorValue;
10:
11: public XQException(Symbol code, String description,
12: Object errorValue) {
13: super (description);
14: this .code = code;
15: this .description = description;
16: this .errorValue = errorValue;
17: }
18:
19: public static Symbol FOER0000_QNAME = Symbol.make(
20: "http://www.w3.org/2005/xqt-errors", "FOER0000", "err");
21:
22: public static void error() {
23: throw new XQException(FOER0000_QNAME, null, null);
24: }
25:
26: public static void error(Symbol error) {
27: throw new XQException(error, null, null);
28: }
29:
30: public static void error(Object error, String description) {
31: if (error == null || error == Values.empty)
32: error = FOER0000_QNAME;
33: throw new XQException((Symbol) error, description, null);
34: }
35:
36: public static void error(Object error, String description,
37: Object errorValue) {
38: if (error == null || error == Values.empty)
39: error = FOER0000_QNAME;
40: throw new XQException((Symbol) error, description, errorValue);
41: }
42:
43: public String getMessage() {
44: StringBuffer sbuf = new StringBuffer(100);
45: if (description == null)
46: sbuf.append("XQuery-error");
47: else
48: sbuf.append(description);
49: if (code != null) {
50: sbuf.append(" [");
51: String prefix = code.getPrefix();
52: if (prefix != null && prefix.length() > 0) {
53: sbuf.append(prefix);
54: sbuf.append(':');
55: }
56: sbuf.append(code.getLocalName());
57: sbuf.append(']');
58: }
59: if (errorValue != null && errorValue != Values.empty) {
60: sbuf.append(" value: ");
61: sbuf.append(errorValue);
62: }
63: return sbuf.toString();
64: }
65: }
|