001: /*
002: * Copyright (c) 2002-2003 by OpenSymphony
003: * All rights reserved.
004: */
005: package com.opensymphony.workflow;
006:
007: import java.io.PrintStream;
008: import java.io.PrintWriter;
009:
010: /**
011: * @author Hani Suleiman (hani@formicary.net)
012: * Date: May 10, 2003
013: * Time: 11:26:07 AM
014: */
015: public class WorkflowException extends Exception {
016: //~ Instance fields ////////////////////////////////////////////////////////
017:
018: private Throwable rootCause;
019:
020: //~ Constructors ///////////////////////////////////////////////////////////
021:
022: public WorkflowException() {
023: }
024:
025: public WorkflowException(String s) {
026: super (s);
027: }
028:
029: public WorkflowException(String s, Throwable rootCause) {
030: super (s);
031: this .rootCause = rootCause;
032: }
033:
034: public WorkflowException(Throwable rootCause) {
035: this .rootCause = rootCause;
036: }
037:
038: //~ Methods ////////////////////////////////////////////////////////////////
039:
040: public Throwable getCause() {
041: return rootCause;
042: }
043:
044: public String getMessage() {
045: StringBuffer sb = new StringBuffer();
046: String msg = super .getMessage();
047:
048: if (msg != null) {
049: sb.append(msg);
050:
051: if (rootCause != null) {
052: sb.append(": ");
053: }
054: }
055:
056: if (rootCause != null) {
057: sb.append("root cause: "
058: + ((rootCause.getMessage() == null) ? rootCause
059: .toString() : rootCause.getMessage()));
060: }
061:
062: return sb.toString();
063: }
064:
065: public Throwable getRootCause() {
066: return rootCause;
067: }
068:
069: public void printStackTrace() {
070: super .printStackTrace();
071:
072: if (rootCause != null) {
073: synchronized (System.err) {
074: System.err.println("\nRoot cause:");
075: rootCause.printStackTrace();
076: }
077: }
078: }
079:
080: public void printStackTrace(PrintStream s) {
081: super .printStackTrace(s);
082:
083: if (rootCause != null) {
084: synchronized (s) {
085: s.println("\nRoot cause:");
086: rootCause.printStackTrace(s);
087: }
088: }
089: }
090:
091: public void printStackTrace(PrintWriter s) {
092: super .printStackTrace(s);
093:
094: if (rootCause != null) {
095: synchronized (s) {
096: s.println("\nRoot cause:");
097: rootCause.printStackTrace(s);
098: }
099: }
100: }
101: }
|