KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > smartlib > pool > core > ConnectionPoolException


1 /*
2  * @(#) ConnectionPoolException.java 1.0 02/08/01
3  */

4 package org.smartlib.pool.core;
5
6 import java.sql.SQLException JavaDoc;
7 /**
8  * This class extends the Exception class and encapsulates any other exception.
9  *
10  * @author Sachin Shekar Shetty
11  * @version 1.0, 02/08/01
12  *
13  */

14
15 public class ConnectionPoolException extends SQLException JavaDoc {
16
17     private Throwable JavaDoc previousException = null;
18     protected String JavaDoc message = null;
19     private Throwable JavaDoc nextException;
20     Debugger debug =
21         new Debugger("org.smartlib.pool.core.ConnectionPoolException", true);
22
23       
24     ConnectionPoolException() {
25
26         super();
27         
28     }
29
30     
31     ConnectionPoolException(String JavaDoc messageId){
32     
33         super(messageId);
34         message = messageId;
35         debug.print("Exception Created:" + messageId);
36         
37     }
38
39     ConnectionPoolException(String JavaDoc messageId ,Throwable JavaDoc prevException) {
40     
41         super(messageId);
42         if((prevException instanceof ConnectionPoolException)
43                 ||(message==null))
44        message = messageId;
45         this.previousException = prevException;
46        debug.print("Exception Created: " + messageId);
47        debug.writeException(this);
48         
49     }
50     
51     Throwable JavaDoc getPreviousException() {
52     
53         return previousException;
54
55     }
56
57     /**
58      * This method prints the stack trace to System.err. It prints the
59      * entire stackTrace of all the previous exceptions that it has
60      * encapsulated.
61      */

62     public void printStackTrace() {
63     
64         super.printStackTrace();
65         if (previousException != null) {
66             System.err.println("Caused by Prev: ");
67             previousException.printStackTrace();
68         }
69         if (nextException != null) {
70             System.err.println("Caused by Next: ");
71             nextException.printStackTrace();
72         }
73
74     }
75
76     /**
77      * This method prints the stack trace to <code>ps</code>. It prints the
78      * entire stackTrace of all the previous exceptions that it has
79      * encapsulated.
80      *
81      * @param ps PrintStream into which the stack trace will be written.
82      */

83     public void printStackTrace(java.io.PrintStream JavaDoc ps) {
84
85         if(ps == null) {
86             System.err.println("PrintStream passed to printStackTrace method is null.");
87             printStackTrace();
88         }
89         super.printStackTrace(ps);
90         if (previousException != null) {
91             ps.println("Caused by:");
92             previousException.printStackTrace(ps);
93         }
94
95     }
96
97     /**
98      * This method returns the message id.
99      */

100     public String JavaDoc getMessageId() {
101     
102         if(message==null)
103             return null;
104         int index = message.indexOf(":");
105         int len = message.length();
106
107         if(index<=0)
108             return null;
109         return message.substring(0,index);
110
111     }
112     
113     String JavaDoc getRootMessageId() {
114         ConnectionPoolException exp = null;
115         Throwable JavaDoc prevExp = this;
116         while((prevExp!=null)&&(prevExp instanceof ConnectionPoolException)) {
117             exp = (ConnectionPoolException)prevExp;
118             prevExp = exp.previousException;
119         }
120         if(exp == null)
121             return null;
122         String JavaDoc message = exp.message;
123         if(message==null)
124             return null;
125         int index = message.indexOf(":");
126         int len = message.length();
127
128         if(index<=0)
129             return null;
130         return message.substring(0,index);
131         
132     }
133     
134
135     /**
136      * This method prints the stack trace to <code>pw</code>. It prints the
137      * entire stackTrace of all the previous exceptions that it has
138      * encapsulated.
139      *
140      * @param pw PrintWriter into which the stack trace will be written.
141      */

142     public void printStackTrace(java.io.PrintWriter JavaDoc pw) {
143     
144         if(pw == null) {
145             System.err.println("PrintWriter passed to printStackTrace method is null.");
146             printStackTrace();
147         }
148         super.printStackTrace(pw);
149         if (previousException != null) {
150             pw.println("Caused by:");
151             previousException.printStackTrace(pw);
152         }
153         
154     }
155     
156
157 }
158
Popular Tags