KickJava   Java API By Example, From Geeks To Geeks.

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


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  * InternalExceptions are unexpected exceptions that may occur e.g., when some
34  * entities (kernel, binders, stub factories, ...), are incompatible or badly used.
35  */

36 public class InternalException extends RuntimeException JavaDoc {
37    /** @serial */
38    Throwable JavaDoc actual;
39
40    /**
41     * Constructs a new InternalException with no detail message.
42     */

43    public InternalException() {}
44    /**
45     * Constructs a new InternalException with a detail message.
46     *
47     * @param s a detail message.
48     */

49    public InternalException(String JavaDoc s) { super(s); }
50
51    /**
52     * Builds an InternalException that wraps another exception.
53     *
54     * @param throwable a wrapped exception.
55     */

56    public InternalException(Throwable JavaDoc throwable) {
57       actual = (throwable instanceof InternalException) ?
58          ((InternalException) throwable).represents() :
59          ((throwable instanceof JonathanException) ?
60           ((JonathanException) throwable).represents() :
61           throwable);
62    }
63    
64    /**
65     * Returns the detail message of this InternalException.
66     * <p>
67     * If this exception represents another exception, the returned message is
68     * that of the represented exception.
69     *
70     * @return the detail message of this 'InternalException',
71     * or 'null' if this 'InternalException' does not
72     * have a detail message.
73     */

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

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

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

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

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

133    public Throwable JavaDoc represents() {
134       return (actual != null) ? actual : this;
135    }
136 }
137
138
139
Popular Tags