KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jalisto > se > exception > remote > RemoteException


1 /*
2  * Jalisto - JAva LIght STOrage
3  * Copyright (C) 2000-2005 Xcalia http://www.xcalia.com
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
18  *
19  * Xcalia
20  * 71, rue Desnouettes
21  * 75014 Paris - France
22  * http://www.xcalia.com
23  */

24 package org.objectweb.jalisto.se.exception.remote;
25
26 import org.objectweb.jalisto.se.exception.JalistoException;
27
28 import java.io.StringWriter JavaDoc;
29 import java.io.PrintWriter JavaDoc;
30 import java.io.PrintStream JavaDoc;
31
32 public class RemoteException extends JalistoException {
33
34     public RemoteException() {
35     }
36
37     public RemoteException(String JavaDoc s) {
38         super(s);
39         remoteMessage = s;
40     }
41
42     public RemoteException(String JavaDoc s, Throwable JavaDoc throwable) {
43         super(s);
44         remoteMessage = s;
45         manageThrowable(throwable);
46     }
47
48     public RemoteException(Throwable JavaDoc throwable) {
49         super();
50         manageThrowable(throwable);
51         remoteMessage = throwable.getMessage();
52     }
53
54     private void manageThrowable(Throwable JavaDoc throwable) {
55         StringWriter JavaDoc sw = new StringWriter JavaDoc();
56         throwable.printStackTrace(new PrintWriter JavaDoc(sw));
57         sw.flush();
58         stackTrace = sw.toString();
59     }
60
61     public void printStackTrace() {
62         super.printStackTrace();
63         if (stackTrace != null) {
64             System.err.println("remotly caused by : "+stackTrace);
65         }
66     }
67
68     public void printStackTrace(PrintStream JavaDoc printStream) {
69         super.printStackTrace(printStream);
70         if (stackTrace != null) {
71             printStream.println("remotly caused by : "+stackTrace);
72         }
73     }
74
75     public void printStackTrace(PrintWriter JavaDoc printWriter) {
76         super.printStackTrace(printWriter);
77         if (stackTrace != null) {
78             printWriter.println("remotly caused by : "+stackTrace);
79         }
80     }
81
82     public String JavaDoc getMessage() {
83         if (remoteMessage == null) {
84             return super.getMessage();
85         } else {
86             return remoteMessage;
87         }
88     }
89
90     private String JavaDoc stackTrace;
91     private String JavaDoc remoteMessage;
92 }
93
Popular Tags