001: /* *************************************************************************
002:
003: Millstone(TM)
004: Open Sourced User Interface Library for
005: Internet Development with Java
006:
007: Millstone is a registered trademark of IT Mill Ltd
008: Copyright (C) 2000-2005 IT Mill Ltd
009:
010: *************************************************************************
011:
012: This library is free software; you can redistribute it and/or
013: modify it under the terms of the GNU Lesser General Public
014: license version 2.1 as published by the Free Software Foundation.
015:
016: This library is distributed in the hope that it will be useful,
017: but WITHOUT ANY WARRANTY; without even the implied warranty of
018: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
019: Lesser General Public License for more details.
020:
021: You should have received a copy of the GNU Lesser General Public
022: License along with this library; if not, write to the Free Software
023: Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
024:
025: *************************************************************************
026:
027: For more information, contact:
028:
029: IT Mill Ltd phone: +358 2 4802 7180
030: Ruukinkatu 2-4 fax: +358 2 4802 7181
031: 20540, Turku email: info@itmill.com
032: Finland company www: www.itmill.com
033:
034: Primary source for MillStone information and releases: www.millstone.org
035:
036: ********************************************************************** */
037:
038: package org.millstone.base.terminal;
039:
040: import java.io.PrintWriter;
041: import java.io.StringWriter;
042:
043: /** System error is a runtime exception caused by error in system. The system
044: * error can be shown to the user as it implements ErrorMessage interface,
045: * but contains technical information such as stack trace and exception.
046: *
047: * @author IT Mill Ltd.
048: * @version 3.1.1
049: * @since 3.0
050: */
051: public class SystemError extends RuntimeException implements
052: ErrorMessage {
053:
054: /**
055: * Serial generated by eclipse.
056: */
057: private static final long serialVersionUID = 3256445789512675891L;
058:
059: /** The cause of the system error. The cause is stored separately as
060: * JDK 1.3 does not support causes natively */
061: private Throwable cause = null;
062:
063: /** Constructor for SystemError with error message specified.
064: * @param message Textual error description.
065: */
066: public SystemError(String message) {
067: super (message);
068: }
069:
070: /** Constructor for SystemError with causing exception and error message.
071: * @param message Textual error description.
072: * @param cause The throwable causing the system error.
073: */
074: public SystemError(String message, Throwable cause) {
075: super (message);
076: this .cause = cause;
077: }
078:
079: /** Constructor for SystemError with cause.
080: * @param cause The throwable causing the system error.
081: */
082: public SystemError(Throwable cause) {
083: this .cause = cause;
084: }
085:
086: public final int getErrorLevel() {
087: return ErrorMessage.SYSTEMERROR;
088: }
089:
090: public void paint(PaintTarget target) throws PaintException {
091:
092: target.startTag("error");
093: target.addAttribute("level", "system");
094:
095: // Paint the error message
096: String message = getLocalizedMessage();
097: if (message != null) {
098: target.addSection("b", message);
099: }
100:
101: // Paint the exception
102: if (cause != null) {
103: if (message != null)
104: target.addUIDL("<br/><br/>");
105: target.addSection("b", "Exception");
106: target.addUIDL("<br/><br/>");
107: StringWriter buffer = new StringWriter();
108: cause.printStackTrace(new PrintWriter(buffer));
109: target.addSection("pre", buffer.toString());
110: }
111:
112: target.endTag("error");
113:
114: }
115:
116: /** Get cause for the error */
117: public Throwable getCause() {
118: return cause;
119: }
120:
121: /* Documented in super interface */
122: public void addListener(RepaintRequestListener listener) {
123: }
124:
125: /* Documented in super interface */
126: public void removeListener(RepaintRequestListener listener) {
127: }
128:
129: /* Documented in super interface */
130: public void requestRepaint() {
131: }
132:
133: /* Documented in super interface */
134: public void requestRepaintRequests() {
135: }
136:
137: }
|