KickJava   Java API By Example, From Geeks To Geeks.

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


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: NoSuchObjectExceptionHelper.java,v 1.1 2005/03/11 14:02:28 benoitf Exp $
23  * --------------------------------------------------------------------------
24  */

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

37 public class NoSuchObjectExceptionHelper {
38
39     /**
40      * Utility class, no constructor
41      */

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

51     public static NoSuchObjectException JavaDoc create(String JavaDoc message, Exception JavaDoc originalException) {
52         NoSuchObjectException JavaDoc ne = new NoSuchObjectException JavaDoc(message);
53         ne.detail = originalException;
54         return ne;
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 NoSuchObjectException JavaDoc create(Throwable JavaDoc originalThrowable) {
63         if (originalThrowable instanceof NoSuchObjectException JavaDoc) {
64             return (NoSuchObjectException JavaDoc) originalThrowable;
65         } else {
66             NoSuchObjectException JavaDoc ne = new NoSuchObjectException JavaDoc(originalThrowable.getMessage());
67             ne.detail = originalThrowable;
68             return ne;
69         }
70     }
71
72     /**
73      * Build a new exception with the given Throwable by wrapping it in a NoSuchObjectException
74      * @return built exception
75      * @param message text error for the exception
76      * @param originalThrowable original throwable
77      */

78     public static NoSuchObjectException JavaDoc create(String JavaDoc message, Throwable JavaDoc originalThrowable) {
79         if (originalThrowable instanceof NoSuchObjectException JavaDoc) {
80             return (NoSuchObjectException JavaDoc) originalThrowable;
81         } else {
82             NoSuchObjectException JavaDoc ne = new NoSuchObjectException JavaDoc(message);
83             ne.detail = originalThrowable;
84             return ne;
85         }
86     }
87
88 }
89
Popular Tags