KickJava   Java API By Example, From Geeks To Geeks.

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


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-2006 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 Runtime Exception class which will provide exception nesting functionalities.
21  * @author Fabrizio Giustina
22  * @version $Revision: 6341 $ ($Author: philipp $)
23  * @since 2.2
24  */

25 public abstract class BaseRuntimeException extends RuntimeException JavaDoc {
26
27     /**
28      * Stable serialVersionUID.
29      */

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

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

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

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

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

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

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

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

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

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

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

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

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