You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

SystemError.java 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /*
  2. @ITMillApache2LicenseForJavaFiles@
  3. */
  4. package com.itmill.toolkit.terminal;
  5. import java.io.PrintWriter;
  6. import java.io.StringWriter;
  7. /**
  8. * <code>SystemError</code> is a runtime exception caused by error in system.
  9. * The system error can be shown to the user as it implements
  10. * <code>ErrorMessage</code> interface, but contains technical information
  11. * such as stack trace and exception.
  12. *
  13. * @author IT Mill Ltd.
  14. * @version
  15. * @VERSION@
  16. * @since 3.0
  17. */
  18. public class SystemError extends RuntimeException implements ErrorMessage {
  19. /**
  20. * Serial generated by eclipse.
  21. */
  22. private static final long serialVersionUID = 3256445789512675891L;
  23. /**
  24. * The cause of the system error. The cause is stored separately as JDK 1.3
  25. * does not support causes natively.
  26. */
  27. private Throwable cause = null;
  28. /**
  29. * Constructor for SystemError with error message specified.
  30. *
  31. * @param message
  32. * the Textual error description.
  33. */
  34. public SystemError(String message) {
  35. super(message);
  36. }
  37. /**
  38. * Constructor for SystemError with causing exception and error message.
  39. *
  40. * @param message
  41. * the Textual error description.
  42. * @param cause
  43. * the throwable causing the system error.
  44. */
  45. public SystemError(String message, Throwable cause) {
  46. super(message);
  47. this.cause = cause;
  48. }
  49. /**
  50. * Constructor for SystemError with cause.
  51. *
  52. * @param cause
  53. * the throwable causing the system error.
  54. */
  55. public SystemError(Throwable cause) {
  56. this.cause = cause;
  57. }
  58. /**
  59. * @see com.itmill.toolkit.terminal.ErrorMessage#getErrorLevel()
  60. */
  61. public final int getErrorLevel() {
  62. return ErrorMessage.SYSTEMERROR;
  63. }
  64. /**
  65. * @see com.itmill.toolkit.terminal.Paintable#paint(com.itmill.toolkit.terminal.PaintTarget)
  66. */
  67. public void paint(PaintTarget target) throws PaintException {
  68. target.startTag("error");
  69. target.addAttribute("level", "system");
  70. // Paint the error message
  71. final String message = getLocalizedMessage();
  72. if (message != null) {
  73. target.addSection("h2", message);
  74. }
  75. // Paint the exception
  76. if (cause != null) {
  77. target.addSection("h3", "Exception");
  78. final StringWriter buffer = new StringWriter();
  79. cause.printStackTrace(new PrintWriter(buffer));
  80. target.addSection("pre", buffer.toString());
  81. }
  82. target.endTag("error");
  83. }
  84. /**
  85. * Gets cause for the error.
  86. *
  87. * @return the cause.
  88. * @see java.lang.Throwable#getCause()
  89. */
  90. public Throwable getCause() {
  91. return cause;
  92. }
  93. /* Documented in super interface */
  94. public void addListener(RepaintRequestListener listener) {
  95. }
  96. /* Documented in super interface */
  97. public void removeListener(RepaintRequestListener listener) {
  98. }
  99. /* Documented in super interface */
  100. public void requestRepaint() {
  101. }
  102. /* Documented in super interface */
  103. public void requestRepaintRequests() {
  104. }
  105. }