KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > kilim > 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.kilim;
28
29 import java.io.PrintStream JavaDoc;
30 import java.io.PrintWriter JavaDoc;
31
32 /**
33  * InternalException is the exception generated inthe Kilim environment in case of an abnormal behviour of the Kilim infrastructure.
34  * (a user error is notified through a KilimException). InternalException provides a simple mechanism to wrap exceptions of an other
35  * type so that the stack trace and the message returned by such an exception correspond to that of the wrapped exception.
36  * @author dumant
37  */

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

44    public InternalException() { }
45    
46    /**
47     * Constructs a new InternalException with a detail message.
48     * @param s : string corresponding to the exception message
49     */

50    public InternalException(String JavaDoc s) { super(s); }
51
52    /**
53     * Builds an InternalException that wraps another exception.
54     * @param throwable : the exception to be encapsulated.
55     */

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

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

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

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

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

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

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