1 |
343
|
jones
|
/**
|
2 |
|
|
* '$RCSfile$'
|
3 |
|
|
* Purpose: An Exception thrown when an error occurs because a
|
4 |
|
|
* problem occurred in the metacat database
|
5 |
|
|
* Copyright: 2000 Regents of the University of California and the
|
6 |
|
|
* National Center for Ecological Analysis and Synthesis
|
7 |
|
|
* Authors: Matt Jones
|
8 |
349
|
jones
|
* Release: @release@
|
9 |
343
|
jones
|
*
|
10 |
|
|
* '$Author$'
|
11 |
|
|
* '$Date$'
|
12 |
|
|
* '$Revision$'
|
13 |
669
|
jones
|
*
|
14 |
|
|
* This program is free software; you can redistribute it and/or modify
|
15 |
|
|
* it under the terms of the GNU General Public License as published by
|
16 |
|
|
* the Free Software Foundation; either version 2 of the License, or
|
17 |
|
|
* (at your option) any later version.
|
18 |
|
|
*
|
19 |
|
|
* This program is distributed in the hope that it will be useful,
|
20 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
21 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
22 |
|
|
* GNU General Public License for more details.
|
23 |
|
|
*
|
24 |
|
|
* You should have received a copy of the GNU General Public License
|
25 |
|
|
* along with this program; if not, write to the Free Software
|
26 |
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
27 |
343
|
jones
|
*/
|
28 |
|
|
|
29 |
|
|
package edu.ucsb.nceas.metacat;
|
30 |
|
|
|
31 |
|
|
import java.io.PrintWriter;
|
32 |
|
|
|
33 |
|
|
/**
|
34 |
|
|
* Exception thrown when an error occurs because a problem occurred in
|
35 |
|
|
* the metacat database. This is the general type of Exception that is
|
36 |
|
|
* thrown whenever the server encounters an Error or Exception that is
|
37 |
|
|
* outside of the scope of normal operation. This class may be
|
38 |
|
|
* subclassed to provide more detailed informatin about the error.
|
39 |
|
|
*/
|
40 |
|
|
public class McdbException extends Exception {
|
41 |
|
|
|
42 |
|
|
/**
|
43 |
|
|
* @serial The embedded exception if wrapping an Exception
|
44 |
|
|
*/
|
45 |
|
|
private Exception exception;
|
46 |
|
|
|
47 |
|
|
/**
|
48 |
|
|
* Create a new McdbException.
|
49 |
|
|
*/
|
50 |
|
|
public McdbException() {
|
51 |
|
|
super();
|
52 |
|
|
this.exception = null;
|
53 |
|
|
}
|
54 |
|
|
|
55 |
|
|
/**
|
56 |
|
|
* Create a new McdbException.
|
57 |
|
|
*
|
58 |
|
|
* @param message The error or warning message.
|
59 |
|
|
*/
|
60 |
|
|
public McdbException(String message) {
|
61 |
|
|
super(message);
|
62 |
|
|
this.exception = null;
|
63 |
|
|
}
|
64 |
|
|
|
65 |
|
|
/**
|
66 |
|
|
* Create a new McdbException.
|
67 |
|
|
*
|
68 |
|
|
* @param e The exception to tunnel inside this exception
|
69 |
|
|
*/
|
70 |
|
|
public McdbException(Exception e) {
|
71 |
|
|
super();
|
72 |
|
|
this.exception = e;
|
73 |
|
|
}
|
74 |
|
|
|
75 |
|
|
/**
|
76 |
|
|
* Create a new McdbException.
|
77 |
|
|
*
|
78 |
|
|
* @param message The error or warning message.
|
79 |
|
|
* @param e The exception to tunnel inside this exception
|
80 |
|
|
*/
|
81 |
|
|
public McdbException(String message, Exception e) {
|
82 |
|
|
super(message);
|
83 |
|
|
this.exception = e;
|
84 |
|
|
}
|
85 |
|
|
|
86 |
|
|
/**
|
87 |
|
|
* Get the tunneled Exception
|
88 |
|
|
*/
|
89 |
|
|
public Exception getException() {
|
90 |
|
|
return exception;
|
91 |
|
|
}
|
92 |
|
|
|
93 |
|
|
/**
|
94 |
|
|
* Get the message from this exception.
|
95 |
|
|
*
|
96 |
|
|
* <p>This returns the message from this exception, but if it
|
97 |
|
|
* is null, and if the tunnelled exception is not null, then
|
98 |
|
|
* it returns the message fromthe tunnelled exception.
|
99 |
|
|
*/
|
100 |
|
|
public String getMessage() {
|
101 |
|
|
String msg = super.getMessage();
|
102 |
|
|
|
103 |
|
|
if (msg == null && exception != null) {
|
104 |
|
|
return exception.getMessage();
|
105 |
|
|
}
|
106 |
|
|
|
107 |
|
|
return msg;
|
108 |
|
|
}
|
109 |
|
|
|
110 |
|
|
/**
|
111 |
|
|
* Print the message from this exception in XML format.
|
112 |
|
|
*
|
113 |
|
|
* <p>This returns the message from this exception, but if it
|
114 |
|
|
* is null, and if the tunnelled exception is not null, then
|
115 |
|
|
* it returns the message from the tunnelled exception.
|
116 |
|
|
*/
|
117 |
|
|
public void toXml(PrintWriter pw) {
|
118 |
|
|
String msg = super.getMessage();
|
119 |
|
|
|
120 |
|
|
if (msg == null && exception != null) {
|
121 |
|
|
msg = exception.getMessage();
|
122 |
|
|
}
|
123 |
|
|
|
124 |
|
|
pw.println("<?xml version=\"1.0\"?>");
|
125 |
|
|
pw.println("<error>" + msg + "</error>");
|
126 |
|
|
pw.flush();
|
127 |
|
|
}
|
128 |
|
|
}
|