KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > opensymphony > workflow > WorkflowException


1 /*
2  * Copyright (c) 2002-2003 by OpenSymphony
3  * All rights reserved.
4  */

5 package com.opensymphony.workflow;
6
7 import java.io.PrintStream JavaDoc;
8 import java.io.PrintWriter JavaDoc;
9
10
11 /**
12  * @author Hani Suleiman (hani@formicary.net)
13  * Date: May 10, 2003
14  * Time: 11:26:07 AM
15  */

16 public class WorkflowException extends Exception JavaDoc {
17     //~ Instance fields ////////////////////////////////////////////////////////
18

19     private Throwable JavaDoc rootCause;
20
21     //~ Constructors ///////////////////////////////////////////////////////////
22

23     public WorkflowException() {
24     }
25
26     public WorkflowException(String JavaDoc s) {
27         super(s);
28     }
29
30     public WorkflowException(String JavaDoc s, Throwable JavaDoc rootCause) {
31         super(s);
32         this.rootCause = rootCause;
33     }
34
35     public WorkflowException(Throwable JavaDoc rootCause) {
36         this.rootCause = rootCause;
37     }
38
39     //~ Methods ////////////////////////////////////////////////////////////////
40

41     public String JavaDoc getMessage() {
42         StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
43         String JavaDoc msg = super.getMessage();
44
45         if (msg != null) {
46             sb.append(msg);
47
48             if (rootCause != null) {
49                 sb.append(": ");
50             }
51         }
52
53         if (rootCause != null) {
54             sb.append("root cause: " + ((rootCause.getMessage() == null) ? rootCause.toString() : rootCause.getMessage()));
55         }
56
57         return sb.toString();
58     }
59
60     public Throwable JavaDoc getRootCause() {
61         return rootCause;
62     }
63
64     public void printStackTrace() {
65         super.printStackTrace();
66
67         if (rootCause != null) {
68             synchronized (System.err) {
69                 System.err.println("\nRoot cause:");
70                 rootCause.printStackTrace();
71             }
72         }
73     }
74
75     public void printStackTrace(PrintStream JavaDoc s) {
76         super.printStackTrace(s);
77
78         if (rootCause != null) {
79             synchronized (s) {
80                 s.println("\nRoot cause:");
81                 rootCause.printStackTrace(s);
82             }
83         }
84     }
85
86     public void printStackTrace(PrintWriter JavaDoc s) {
87         super.printStackTrace(s);
88
89         if (rootCause != null) {
90             synchronized (s) {
91                 s.println("\nRoot cause:");
92                 rootCause.printStackTrace(s);
93             }
94         }
95     }
96 }
97
Popular Tags