KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > cjdbc > common > exceptions > driver > protocol > ControllerCoreException


1 /**
2  * C-JDBC: Clustered JDBC.
3  * Copyright (C) 2005 Emic Networks
4  * Contact: c-jdbc@objectweb.org
5  *
6  * This library is free software; you can redistribute it and/or modify it
7  * under the terms of the GNU Lesser General Public License as published by the
8  * Free Software Foundation; either version 2.1 of the License, or any later
9  * version.
10  *
11  * This library is distributed in the hope that it will be useful, but WITHOUT
12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
14  * for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public License
17  * along with this library; if not, write to the Free Software Foundation,
18  * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
19  *
20  * Initial developer(s): Marc Herbert
21  * Contributor(s): ______________________.
22  */

23
24 package org.objectweb.cjdbc.common.exceptions.driver.protocol;
25
26 import java.io.IOException JavaDoc;
27 import java.sql.SQLException JavaDoc;
28
29 import org.objectweb.cjdbc.common.exceptions.NoMoreBackendException;
30 import org.objectweb.cjdbc.common.exceptions.NoMoreControllerException;
31 import org.objectweb.cjdbc.common.exceptions.NotImplementedException;
32 import org.objectweb.cjdbc.common.stream.CJDBCInputStream;
33
34 /**
35  * This class is meant for exceptions originated in controller core (i.e.,
36  * non-backend) that are serialized to the driver.
37  *
38  * @author <a HREF="mailto:Marc.Herbert@emicnetworks.com">Marc Herbert</a>
39  * @version 1.0
40  */

41 public class ControllerCoreException
42     extends SerializableException
43 {
44
45   private static final int UNKNOWN = 0;
46   private static final int NO_MORE_BACKEND = 1;
47   private static final int NO_MORE_CONTROLLER = 2;
48   private static final int NOT_IMPLEMENTED = 3;
49
50   private static int exceptionTypeCode(Throwable JavaDoc ex)
51   {
52     if (ex instanceof NoMoreBackendException)
53       return NO_MORE_BACKEND;
54     if (ex instanceof NoMoreControllerException)
55       return NO_MORE_CONTROLLER;
56     if (ex instanceof NotImplementedException)
57       return NOT_IMPLEMENTED;
58
59     return UNKNOWN;
60   }
61
62   /**
63    * This method returns a wrapper around 'this' ControllerCoreException, in
64    * order to stay bug for bug compatible with legacy exception handling code.
65    * This method should disappear and be implemented above, directly by the code
66    * calling it.
67    *
68    * @deprecated
69    * @return a wrapper around this object
70    */

71   public Exception JavaDoc compatibilityWrapperHack()
72   {
73     Exception JavaDoc wrapper;
74     switch (this.getErrorCode())
75     {
76       case NO_MORE_BACKEND :
77         wrapper = new NoMoreBackendException(getMessage(), getSQLState(),
78             getErrorCode());
79         break;
80       case NO_MORE_CONTROLLER :
81         wrapper = new NoMoreControllerException(getMessage(), getSQLState(),
82             getErrorCode());
83         break;
84       case NOT_IMPLEMENTED :
85         wrapper = new NotImplementedException(getMessage(), getSQLState(),
86             getErrorCode());
87         break;
88       default : // hey, why not ?
89
wrapper = new SQLException JavaDoc(getMessage(), getSQLState(), getErrorCode());
90     }
91     wrapper.initCause(this);
92     return wrapper;
93   }
94
95   /**
96    * @see SerializableException#SerializableException(CJDBCInputStream)
97    */

98   public ControllerCoreException(CJDBCInputStream in) throws IOException JavaDoc
99   {
100     super(in);
101   }
102
103   /**
104    * Converts a chain of Throwables to a new chain of SerializableExceptions
105    * starting with a <code>ControllerCoreException</code>. The returned chain
106    * has the same length.
107    *
108    * @param ex head of chain to convert
109    * @see SerializableException#SerializableException(Throwable)
110    */

111   public ControllerCoreException(Throwable JavaDoc ex)
112   {
113     super(ex);
114
115     // This is the place where we could set your own SQL codes
116
// super.SQLState = sqlE.getSQLState();
117

118     // hack: let's use vendorCode int as a type
119
setErrorCode(exceptionTypeCode(ex));
120
121   }
122
123 }
124
Popular Tags