001: /*
002: #IFNDEF ALT_LICENSE
003: ThinWire(R) RIA Ajax Framework
004: Copyright (C) 2003-2007 Custom Credit Systems
005:
006: This library is free software; you can redistribute it and/or modify it under
007: the terms of the GNU Lesser General Public License as published by the Free
008: Software Foundation; either version 2.1 of the License, or (at your option) any
009: later version.
010:
011: This library is distributed in the hope that it will be useful, but WITHOUT ANY
012: WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
013: PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
014:
015: You should have received a copy of the GNU Lesser General Public License along
016: with this library; if not, write to the Free Software Foundation, Inc., 59
017: Temple Place, Suite 330, Boston, MA 02111-1307 USA
018:
019: Users who would rather have a commercial license, warranty or support should
020: contact the following company who invented, built and supports the technology:
021:
022: Custom Credit Systems, Richardson, TX 75081, USA.
023: email: info@thinwire.com ph: +1 (888) 644-6405
024: http://www.thinwire.com
025: #ENDIF
026: [ v1.2_RC2 ]
027: */
028: package thinwire.ui.event;
029:
030: import java.io.ByteArrayOutputStream;
031: import java.io.PrintStream;
032: import java.util.EventObject;
033:
034: import thinwire.ui.Application;
035:
036: /**
037: * @author Joshua J. Gertzen
038: */
039: public final class ExceptionEvent extends EventObject {
040: private static final String DEFAULT_MESSAGE = "An exception has occurred in the application. "
041: + "If you are unable to continue, please press F5 to restart the application.";
042:
043: private Throwable exception;
044: private String defaultMessage = DEFAULT_MESSAGE;
045: private boolean canceled;
046: private boolean stopPropagation;
047: private boolean suppressLogging;
048:
049: public ExceptionEvent(Object source, Throwable exception) {
050: super (
051: source == null ? (Application.current() == null ? Application.class
052: : Application.current())
053: : source);
054: this .exception = exception;
055: }
056:
057: public boolean isCanceled() {
058: return canceled;
059: }
060:
061: public boolean isStopPropagation() {
062: return stopPropagation;
063: }
064:
065: public boolean isSuppressLogging() {
066: return suppressLogging;
067: }
068:
069: public void cancel() {
070: cancel(false, false);
071: }
072:
073: public void cancel(boolean stopPropagation) {
074: cancel(stopPropagation, false);
075: }
076:
077: public void cancel(boolean stopPropagation, boolean suppressLogging) {
078: this .canceled = true;
079: if (this .stopPropagation && !stopPropagation)
080: throw new IllegalStateException(
081: "the propgation of this event has already been stopped");
082: this .stopPropagation = stopPropagation;
083: if (this .suppressLogging && !suppressLogging)
084: throw new IllegalStateException(
085: "the logging of this event has already been suppressed");
086: this .suppressLogging = suppressLogging;
087: }
088:
089: public String getDefaultMessage() {
090: return defaultMessage;
091: }
092:
093: public void setDefaultMessage(String defaultMessage) {
094: if (defaultMessage == null || defaultMessage.length() == 0)
095: defaultMessage = DEFAULT_MESSAGE;
096: this .defaultMessage = defaultMessage;
097: }
098:
099: public Throwable getException() {
100: return exception;
101: }
102:
103: public String getStackTraceText() {
104: ByteArrayOutputStream baos = new ByteArrayOutputStream();
105: PrintStream ps = new PrintStream(baos);
106: Throwable e = exception;
107:
108: do {
109: e.printStackTrace(ps);
110: } while ((e = e.getCause()) != null);
111:
112: return baos.toString();
113: }
114: }
|