KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonathan > apis > kernel > JonathanException


1 /***
2  * Jonathan: an Open Distributed Processing Environment
3  * Copyright (C) 1999 France Telecom R&D
4  * Copyright (C) 2001 Kelua SA
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19  *
20  * Contact: jonathan@objectweb.org
21  *
22  * Author: Bruno Dumant
23  *
24  */

25
26
27 package org.objectweb.jonathan.apis.kernel;
28
29 import java.io.PrintStream JavaDoc;
30 import java.io.PrintWriter JavaDoc;
31
32 /**
33  * JonathanException is the supertype of all Jonathan exceptions. It includes a
34  * mechanism to wrap exceptions of an other type so that the stack trace and
35  * the message returned by a Jonathan exception correspond to that of the wrapped
36  * exception.
37  */

38 public class JonathanException extends Exception JavaDoc {
39    /** @serial */
40    Exception JavaDoc actual;
41
42    /**
43     * Constructs a new JonathanException with no detail message.
44     */

45    public JonathanException() {
46       super();
47       actual = null;
48    }
49    /**
50     * Builds a JonathanException with a detail message.
51     *
52     * @param s a detail message.
53     */

54    public JonathanException(String JavaDoc s) {
55       super(s);
56       actual = null;
57    }
58
59    /**
60     * Builds a JonathanException that wraps another exception.
61     *
62     * @param exception a wrapped exception.
63     */

64    public JonathanException(Exception JavaDoc exception) {
65       actual = (exception instanceof JonathanException) ?
66          ((JonathanException) exception).represents() :
67          exception;
68    }
69    /**
70     * Returns the detail message of this JonathanException.
71     * <p>
72     * If this exception represents another exception, the returned message is
73     * that of the represented exception.
74     *
75     * @return the detail message of this 'JonathanException',
76     * or 'null' if this 'JonathanException' does not
77     * have a detail message.
78     */

79    public String JavaDoc getMessage() {
80       return (actual != null) ? actual.getMessage() : super.getMessage();
81    }
82
83    /**
84     * Returns a short description of this JonathanException.
85     * <p>
86     * If this exception represents another exception, the returned description
87     * is that of the represented exception.
88     *
89     * @return a string representation of this 'JonathanException'.
90     */

91    public String JavaDoc toString() {
92       return (actual != null) ? actual.toString() : super.toString();
93    }
94
95    /**
96     * Prints this JonathanException and its backtrace to the
97     * standard error stream.
98     * <p>
99     * If this exception represents another exception, the printed description
100     * and backtrace are that of the represented exception.
101     */

102    public void printStackTrace() {
103       if (actual != null) actual.printStackTrace(); else super.printStackTrace();
104    }
105
106    /**
107     * Prints this JonathanException and its backtrace to the
108     * specified print stream.
109     * <p>
110     * If this exception represents another exception, the printed description
111     * and backtrace are that of the represented exception.
112     *
113     * @param s the print stream.
114     */

115    public void printStackTrace(PrintStream JavaDoc s) {
116       if (actual != null) actual.printStackTrace(s); else super.printStackTrace(s);
117    }
118    
119    /**
120     * Prints this 'Throwable' and its backtrace to the specified
121     * print writer.
122     * <p>
123     * If this exception represents another exception, the printed description
124     * and backtrace are that of the represented exception.
125     *
126     * @param s the print writer.
127     */

128    public void printStackTrace(PrintWriter JavaDoc s) {
129       if (actual != null) actual.printStackTrace(s); else super.printStackTrace(s);
130    }
131    /**
132     * Returns the exception wrapped by this JonathanException.
133     * <p>
134     * If this exception doesn't wrap any other exception, it returns itself.
135     *
136     * @return the represented exception.
137     */

138    public Exception JavaDoc represents() {
139       return (actual != null) ? actual : this;
140    }
141 }
142    
143
144
Popular Tags