KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > info > magnolia > cms > core > BaseException


1 /**
2  *
3  * Magnolia and its source-code is licensed under the LGPL.
4  * You may copy, adapt, and redistribute this file for commercial or non-commercial use.
5  * When copying, adapting, or redistributing this document in keeping with the guidelines above,
6  * you are required to provide proper attribution to obinary.
7  * If you reproduce or distribute the document without making any substantive modifications to its content,
8  * please use the following attribution line:
9  *
10  * Copyright 1993-2005 obinary Ltd. (http://www.obinary.com) All rights reserved.
11  *
12  */

13 package info.magnolia.cms.core;
14
15 import java.io.PrintStream JavaDoc;
16 import java.io.PrintWriter JavaDoc;
17
18
19 /**
20  * Base Exception class which will provide exception nesting functionalities.
21  * @author Fabrizio Giustina
22  * @version $Revision: 1111 $ ($Author: fgiust $)
23  */

24 public abstract class BaseException extends Exception JavaDoc {
25
26     /**
27      * Stable serialVersionUID.
28      */

29     private static final long serialVersionUID = 222L;
30
31     /**
32      * The cause for this exception.
33      */

34     protected Throwable JavaDoc rootCause;
35
36     /**
37      * Instantiate a new exception with an error message.
38      * @param message error message
39      */

40     public BaseException(String JavaDoc message) {
41         super(message);
42     }
43
44     /**
45      * Instantiate a new exception with an error message and a previous exception.
46      * @param message error message
47      * @param rootCause previous exception
48      */

49     public BaseException(String JavaDoc message, Throwable JavaDoc rootCause) {
50         super(message);
51         this.rootCause = rootCause;
52     }
53
54     /**
55      * Instantiate a new exception with only previous exception.
56      * @param rootCause previous exception
57      */

58     public BaseException(Throwable JavaDoc rootCause) {
59         this.rootCause = rootCause;
60     }
61
62     /**
63      * @see java.lang.Throwable#getMessage()
64      */

65     public String JavaDoc getMessage() {
66         String JavaDoc message = super.getMessage();
67         if (rootCause == null) {
68             return message;
69         }
70
71         String JavaDoc rootMessage = rootCause.getMessage();
72         return message != null ? message + ": " + rootMessage : rootMessage; //$NON-NLS-1$
73

74     }
75
76     /**
77      * @see java.lang.Throwable#getLocalizedMessage()
78      */

79     public String JavaDoc getLocalizedMessage() {
80         String JavaDoc message = super.getLocalizedMessage();
81         if (rootCause == null) {
82             return message;
83         }
84
85         String JavaDoc rootMessage = rootCause.getLocalizedMessage();
86         return message != null ? message + ": " + rootMessage : rootMessage; //$NON-NLS-1$
87

88     }
89
90     /**
91      * @see java.lang.Throwable#getCause()
92      */

93     public Throwable JavaDoc getCause() {
94         return rootCause;
95     }
96
97     /**
98      * @see java.lang.Throwable#printStackTrace()
99      */

100     public void printStackTrace() {
101         printStackTrace(System.err);
102     }
103
104     /**
105      * @see java.lang.Throwable#printStackTrace(java.io.PrintStream)
106      */

107     public void printStackTrace(PrintStream JavaDoc s) {
108         synchronized (s) {
109             super.printStackTrace(s);
110             if (rootCause != null) {
111                 rootCause.printStackTrace(s);
112             }
113         }
114     }
115
116     /**
117      * @see java.lang.Throwable#printStackTrace(java.io.PrintWriter)
118      */

119     public void printStackTrace(PrintWriter JavaDoc s) {
120         synchronized (s) {
121             super.printStackTrace(s);
122             if (rootCause != null) {
123                 rootCause.printStackTrace(s);
124             }
125         }
126     }
127 }
128
Popular Tags