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
|
* Release: @release@
|
9
|
*
|
10
|
* '$Author: jones $'
|
11
|
* '$Date: 2000-08-14 13:53:34 -0700 (Mon, 14 Aug 2000) $'
|
12
|
* '$Revision: 349 $'
|
13
|
*/
|
14
|
|
15
|
package edu.ucsb.nceas.metacat;
|
16
|
|
17
|
import java.io.PrintWriter;
|
18
|
|
19
|
/**
|
20
|
* Exception thrown when an error occurs because a problem occurred in
|
21
|
* the metacat database. This is the general type of Exception that is
|
22
|
* thrown whenever the server encounters an Error or Exception that is
|
23
|
* outside of the scope of normal operation. This class may be
|
24
|
* subclassed to provide more detailed informatin about the error.
|
25
|
*/
|
26
|
public class McdbException extends Exception {
|
27
|
|
28
|
/**
|
29
|
* @serial The embedded exception if wrapping an Exception
|
30
|
*/
|
31
|
private Exception exception;
|
32
|
|
33
|
/**
|
34
|
* Create a new McdbException.
|
35
|
*/
|
36
|
public McdbException() {
|
37
|
super();
|
38
|
this.exception = null;
|
39
|
}
|
40
|
|
41
|
/**
|
42
|
* Create a new McdbException.
|
43
|
*
|
44
|
* @param message The error or warning message.
|
45
|
*/
|
46
|
public McdbException(String message) {
|
47
|
super(message);
|
48
|
this.exception = null;
|
49
|
}
|
50
|
|
51
|
/**
|
52
|
* Create a new McdbException.
|
53
|
*
|
54
|
* @param e The exception to tunnel inside this exception
|
55
|
*/
|
56
|
public McdbException(Exception e) {
|
57
|
super();
|
58
|
this.exception = e;
|
59
|
}
|
60
|
|
61
|
/**
|
62
|
* Create a new McdbException.
|
63
|
*
|
64
|
* @param message The error or warning message.
|
65
|
* @param e The exception to tunnel inside this exception
|
66
|
*/
|
67
|
public McdbException(String message, Exception e) {
|
68
|
super(message);
|
69
|
this.exception = e;
|
70
|
}
|
71
|
|
72
|
/**
|
73
|
* Get the tunneled Exception
|
74
|
*/
|
75
|
public Exception getException() {
|
76
|
return exception;
|
77
|
}
|
78
|
|
79
|
/**
|
80
|
* Get the message from this exception.
|
81
|
*
|
82
|
* <p>This returns the message from this exception, but if it
|
83
|
* is null, and if the tunnelled exception is not null, then
|
84
|
* it returns the message fromthe tunnelled exception.
|
85
|
*/
|
86
|
public String getMessage() {
|
87
|
String msg = super.getMessage();
|
88
|
|
89
|
if (msg == null && exception != null) {
|
90
|
return exception.getMessage();
|
91
|
}
|
92
|
|
93
|
return msg;
|
94
|
}
|
95
|
|
96
|
/**
|
97
|
* Print the message from this exception in XML format.
|
98
|
*
|
99
|
* <p>This returns the message from this exception, but if it
|
100
|
* is null, and if the tunnelled exception is not null, then
|
101
|
* it returns the message from the tunnelled exception.
|
102
|
*/
|
103
|
public void toXml(PrintWriter pw) {
|
104
|
String msg = super.getMessage();
|
105
|
|
106
|
if (msg == null && exception != null) {
|
107
|
msg = exception.getMessage();
|
108
|
}
|
109
|
|
110
|
pw.println("<?xml version=\"1.0\"?>");
|
111
|
pw.println("<error>" + msg + "</error>");
|
112
|
pw.flush();
|
113
|
}
|
114
|
}
|