KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > carol > rmi > exception > RemoteExceptionHelper


1 /**
2  * Copyright (C) 2005 - Bull S.A.
3  *
4  * CAROL: Common Architecture for RMI ObjectWeb Layer
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.1 of the License, or 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
19  * USA
20  *
21  * --------------------------------------------------------------------------
22  * $Id: RemoteExceptionHelper.java,v 1.2 2005/04/07 15:07:08 benoitf Exp $
23  * --------------------------------------------------------------------------
24  */

25 package org.objectweb.carol.rmi.exception;
26
27 import java.rmi.RemoteException JavaDoc;
28
29
30 /**
31  * This class throws RemoteException by using provided exception, and set the
32  * detail attribute of the newly created exception. This avoid to forget initial
33  * exception.<br>
34  * initCause() cannot be used as it is a RemoteException.<br>
35  * Use detail attribute as suggested by Vadim Nasardinov
36  * @author Florent Benoit (
37  */

38 public class RemoteExceptionHelper {
39
40
41     /**
42      * Utility class, no constructor
43      */

44     private RemoteExceptionHelper() {
45     }
46
47     /**
48      * Build a new exception with the given exception by wrapping it in a NoSuchObjectException
49      * @return built exception
50      * @param message text error for the exception
51      * @param originalException original exception
52      */

53     public static RemoteException JavaDoc create(String JavaDoc message, Exception JavaDoc originalException) {
54         return new RemoteException JavaDoc(message, originalException);
55     }
56
57     /**
58      * Build a new exception with the given Throwable by wrapping it in a NoSuchObjectException
59      * @return built exception
60      * @param originalThrowable original throwable
61      */

62     public static RemoteException JavaDoc create(Throwable JavaDoc originalThrowable) {
63         if (originalThrowable instanceof RemoteException JavaDoc) {
64             return (RemoteException JavaDoc) originalThrowable;
65         } else {
66             return new RemoteException JavaDoc(originalThrowable.getMessage(), originalThrowable);
67         }
68     }
69
70     /**
71      * Build a new exception with the given Throwable by wrapping it in a NoSuchObjectException
72      * @return built exception
73      * @param message text error for the exception
74      * @param originalThrowable original throwable
75      */

76     public static RemoteException JavaDoc create(String JavaDoc message, Throwable JavaDoc originalThrowable) {
77         if (originalThrowable instanceof RemoteException JavaDoc) {
78             return (RemoteException JavaDoc) originalThrowable;
79         } else {
80             return new RemoteException JavaDoc(message, originalThrowable);
81         }
82     }
83 }
84
Popular Tags