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