KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > speedo > api > ExceptionHelper


1 /**
2  * Copyright (C) 2001-2004 France Telecom R&D
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  */

18 package org.objectweb.speedo.api;
19
20 import org.objectweb.jorm.api.PException;
21 import org.objectweb.perseus.persistence.api.PersistenceException;
22 import org.objectweb.perseus.pool.api.PoolException;
23 import org.objectweb.medor.api.MedorException;
24 import org.objectweb.medor.expression.api.ExpressionException;
25
26 import javax.jdo.JDOException;
27
28 /**
29  * This helper permits to find the final nested exception of a given exception.
30  *
31  * @author S.Chassande-Barrioz
32  */

33 public class ExceptionHelper {
34
35     public static final Exception JavaDoc getNested(Exception JavaDoc e) {
36         if (e == null)
37             return null;
38         Exception JavaDoc c = e;
39         Exception JavaDoc i = null;
40         boolean notLast = true;
41         while (notLast) {
42             if (c instanceof SpeedoException) {
43                 i = ((SpeedoException) c).getNestedException();
44             } else if (c instanceof PException) {
45                 i = ((PException) c).getNestedException();
46             } else if (c instanceof MedorException) {
47                 i = ((MedorException) c).getNestedException();
48             } else if (c instanceof ExpressionException) {
49                 i = ((ExpressionException) c).getNestedException();
50             } else if (c instanceof PersistenceException) {
51                 i = ((PersistenceException) c).getNestedException();
52             } else if (c instanceof PoolException) {
53                 i = ((PoolException) c).getNestedException();
54             } else if (c instanceof JDOException) {
55                 Throwable JavaDoc[] ts = ((JDOException) c).getNestedExceptions();
56                 if (ts != null && ts.length >0 && (ts[0] instanceof Exception JavaDoc)) {
57                     i = (Exception JavaDoc) ts[0];
58                 } else {
59                     notLast = false;
60                 }
61             } else {
62                 notLast = false;
63             }
64             if (notLast && i != null) {
65                 c = i;
66             } else {
67                 notLast = false;
68             }
69         }
70         return c;
71     }
72
73 }
74
Popular Tags