KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > dods > exceptions > DodsBaseExceptionUtil


1 /*
2  * Enhydra Java Application Server Project
3  *
4  * The contents of this file are subject to the Enhydra Public License
5  * Version 1.1 (the "License"); you may not use this file except in
6  * compliance with the License. You may obtain a copy of the License on
7  * the Enhydra web site ( http://www.enhydra.org/ ).
8  *
9  * Software distributed under the License is distributed on an "AS IS"
10  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
11  * the License for the specific terms governing rights and limitations
12  * under the License.
13  *
14  * The Initial Developer of the Enhydra Application Server is Lutris
15  * Technologies, Inc. The Enhydra Application Server and portions created
16  * by Lutris Technologies, Inc. are Copyright Lutris Technologies, Inc.
17  * All Rights Reserved.
18  *
19  * Contributor(s):
20  *
21  * $Id: DodsBaseExceptionUtil.java,v 1.1 2004/09/03 13:42:37 sinisa Exp $
22  *
23  * formatted with JxBeauty (c) johann.langhofer@nextra.at
24  */

25
26
27 package org.enhydra.dods.exceptions;
28
29 import java.io.*;
30
31
32 /**
33  * Utilities used to implement the DodsBaseException.
34  */

35 // compliance with WEBDOCWF begin
36
// WebDocWf extension
37
// The following line has been changed:
38
public class DodsBaseExceptionUtil {
39
40   // before : class ChainedThrowableUtil {
41
// end of WebDocWf extension
42
// original line
43
// class ChainedThrowableUtil {
44
// compliance with WEBDOCWF end
45
/**
46    * Can't makes instances.
47    */

48   private DodsBaseExceptionUtil () {
49   }
50
51   /**
52    * Generate the message to set for the exception message.
53    * When not explicit message is supplied.
54    */

55   // compliance with WEBDOCWF begin
56
// WebDocWf extension
57
// The following line has been changed:
58
public static String JavaDoc makeMessage (Throwable JavaDoc cause) {
59     // before: protected static String makeMessage(Throwable cause) {
60
// end of WebDocWf extension
61
// original line
62
//protected static String makeMessage(Throwable cause) {
63
// compliance with WEBDOCWF end
64
String JavaDoc causeMsg = cause.getMessage();
65     if (causeMsg == null) {
66       return cause.getClass().getName();
67     }
68     else {
69       return causeMsg;
70     }
71   }
72
73   /**
74    * Get the message associated with this exception.
75    */

76   // compliance with WEBDOCWF begin
77
// WebDocWf extension
78
// The following line has been changed:
79
public static String JavaDoc getMessage (DodsBaseException except, String JavaDoc superMsg) {
80     //before: protected static String getMessage(DodsBaseException except, String superMsg) {
81
// end of WebDocWf extension
82
// original line
83
// protected static String getMessage(DodsBaseException except,
84
// String superMsg) {
85
// compliance with WEBDOCWF end
86
Throwable JavaDoc cause = except.getCause();
87     if (cause == null) {
88       return superMsg;
89     }
90     else {
91       String JavaDoc causeMsg = cause.getMessage();
92       if ((causeMsg == null) || (causeMsg.length() == 0)) {
93         causeMsg = cause.getClass().getName();
94       }
95       return superMsg + ": " + causeMsg;
96     }
97   }
98
99   /**
100    * Do work of printing the causes of a chained exception. This is
101    * recursive. This attempts to following causing exceptions that are
102    * chained in other types of exception objects. If only Sun would
103    * standardize a mechanism in throwable instead of letting it accumulate
104    * in an ad-hoc manner.
105    */

106   private static void printChainedCauses (Throwable JavaDoc cause, PrintWriter out) {
107     if (cause != null) {
108       out.println("*** Caused by:");
109       cause.printStackTrace(out);
110       if (cause instanceof DodsBaseException) {
111       // If cause was is a DodsBaseException, its chain has already
112
// been followed, otherwise, see what we can do.
113
}
114       else if (cause instanceof java.awt.print.PrinterIOException JavaDoc) {
115         printChainedCauses(((java.awt.print.PrinterIOException JavaDoc)cause).getIOException(),
116             out);
117       }
118       else if (cause instanceof java.io.WriteAbortedException JavaDoc) {
119         printChainedCauses(((java.io.WriteAbortedException JavaDoc)cause).detail, out);
120       }
121       else if (cause instanceof java.lang.ClassNotFoundException JavaDoc) {
122         printChainedCauses(((java.lang.ClassNotFoundException JavaDoc)cause).getException(),
123             out);
124       }
125       else if (cause instanceof java.lang.ExceptionInInitializerError JavaDoc) {
126         printChainedCauses(((java.lang.ExceptionInInitializerError JavaDoc)cause).getException(),
127             out);
128       }
129       else if (cause instanceof java.lang.reflect.InvocationTargetException JavaDoc) {
130         printChainedCauses(((java.lang.reflect.InvocationTargetException JavaDoc)cause).getTargetException(),
131             out);
132       }
133       else if (cause instanceof java.rmi.RemoteException JavaDoc) {
134         printChainedCauses(((java.rmi.RemoteException JavaDoc)cause).detail, out);
135       }
136       else if (cause instanceof java.rmi.activation.ActivationException JavaDoc) {
137         printChainedCauses(((java.rmi.activation.ActivationException JavaDoc)cause).detail,
138             out);
139       }
140       else if (cause instanceof java.rmi.server.ServerCloneException JavaDoc) {
141         printChainedCauses(((java.rmi.server.ServerCloneException JavaDoc)cause).detail,
142             out);
143       }
144       else if (cause instanceof java.security.PrivilegedActionException JavaDoc) {
145         printChainedCauses(((java.security.PrivilegedActionException JavaDoc)cause).getException(),
146             out);
147       }
148       else if (cause instanceof java.sql.SQLException JavaDoc) {
149         printChainedCauses(((java.sql.SQLException JavaDoc)cause).getNextException(),
150             out);
151       }
152       else if (cause instanceof org.xml.sax.SAXException JavaDoc) {
153         printChainedCauses(((org.xml.sax.SAXException JavaDoc)cause).getException(),
154             out);
155       }
156     }
157   }
158
159   /**
160    * Prints stacktrace and cause stacktrace.
161    */

162   // compliance with WEBDOCWF begin
163
// WebDocWf extension
164
// The following line has been changed:
165
public static void printCauseTrace (DodsBaseException except) {
166     //before: protected static void printCauseTrace(DodsBaseException except) {
167
// end of WebDocWf extension
168
// original line
169
// protected static void printCauseTrace(DodsBaseException except) {
170
// compliance with WEBDOCWF end
171
PrintWriter pw = new PrintWriter(System.err);
172     printChainedCauses(except.getCause(), pw);
173     pw.flush();
174   }
175
176   /**
177    * Prints stacktrace and cause stacktrace.
178    */

179   // compliance with WEBDOCWF begin
180
// WebDocWf extension
181
// The following line has been changed:
182
public static void printCauseTrace (DodsBaseException except, PrintStream s) {
183     //before: protected static void printCauseTrace(DodsBaseException except, PrintStream s) {
184
// end of WebDocWf extension
185
// original line
186
// protected static void printCauseTrace(DodsBaseException except,
187
//PrintStream s) {
188
// compliance with WEBDOCWF end
189
PrintWriter pw = new PrintWriter(s);
190     printChainedCauses(except.getCause(), pw);
191     pw.flush();
192   }
193
194   /**
195    * Prints stacktrace and cause stacktrace.
196    */

197   public static void printCauseTrace (DodsBaseException except, PrintWriter out) {
198     printChainedCauses(except.getCause(), out);
199     out.flush();
200   }
201 }
202
203
204
205
Popular Tags