XQException.java 1.8 KB

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