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