diff options
Diffstat (limited to 'src/com/itmill/toolkit/terminal/SystemError.java')
-rw-r--r-- | src/com/itmill/toolkit/terminal/SystemError.java | 127 |
1 files changed, 127 insertions, 0 deletions
diff --git a/src/com/itmill/toolkit/terminal/SystemError.java b/src/com/itmill/toolkit/terminal/SystemError.java new file mode 100644 index 0000000000..0ab836f520 --- /dev/null +++ b/src/com/itmill/toolkit/terminal/SystemError.java @@ -0,0 +1,127 @@ +/* ************************************************************************* + + IT Mill Toolkit + + Development of Browser User Intarfaces Made Easy + + Copyright (C) 2000-2006 IT Mill Ltd + + ************************************************************************* + + This product is distributed under commercial license that can be found + from the product package on license/license.txt. Use of this product might + require purchasing a commercial license from IT Mill Ltd. For guidelines + on usage, see license/licensing-guidelines.html + + ************************************************************************* + + For more information, contact: + + IT Mill Ltd phone: +358 2 4802 7180 + Ruukinkatu 2-4 fax: +358 2 4802 7181 + 20540, Turku email: info@itmill.com + Finland company www: www.itmill.com + + Primary source for information and releases: www.itmill.com + + ********************************************************************** */ + +package com.itmill.toolkit.terminal; + +import java.io.PrintWriter; +import java.io.StringWriter; + +/** System error is a runtime exception caused by error in system. The system + * error can be shown to the user as it implements ErrorMessage interface, + * but contains technical information such as stack trace and exception. + * + * @author IT Mill Ltd. + * @version @VERSION@ + * @since 3.0 + */ +public class SystemError extends RuntimeException implements ErrorMessage { + + /** + * Serial generated by eclipse. + */ + private static final long serialVersionUID = 3256445789512675891L; + + /** The cause of the system error. The cause is stored separately as + * JDK 1.3 does not support causes natively */ + private Throwable cause = null; + + /** Constructor for SystemError with error message specified. + * @param message Textual error description. + */ + public SystemError(String message) { + super(message); + } + + /** Constructor for SystemError with causing exception and error message. + * @param message Textual error description. + * @param cause The throwable causing the system error. + */ + public SystemError(String message, Throwable cause) { + super(message); + this.cause = cause; + } + + /** Constructor for SystemError with cause. + * @param cause The throwable causing the system error. + */ + public SystemError(Throwable cause) { + this.cause = cause; + } + + public final int getErrorLevel() { + return ErrorMessage.SYSTEMERROR; + } + + public void paint(PaintTarget target) throws PaintException { + + target.startTag("error"); + target.addAttribute("level", "system"); + + // Paint the error message + String message = getLocalizedMessage(); + if (message != null) { + target.addSection("b", message); + } + + // Paint the exception + if (cause != null) { + if (message != null) + target.addUIDL("<br/><br/>"); + target.addSection("b", "Exception"); + target.addUIDL("<br/><br/>"); + StringWriter buffer = new StringWriter(); + cause.printStackTrace(new PrintWriter(buffer)); + target.addSection("pre", buffer.toString()); + } + + target.endTag("error"); + + } + + /** Get cause for the error */ + public Throwable getCause() { + return cause; + } + + /* Documented in super interface */ + public void addListener(RepaintRequestListener listener) { + } + + /* Documented in super interface */ + public void removeListener(RepaintRequestListener listener) { + } + + /* Documented in super interface */ + public void requestRepaint() { + } + + /* Documented in super interface */ + public void requestRepaintRequests() { + } + +} |