01: /*
02: * Copyright (C) The MX4J Contributors.
03: * All rights reserved.
04: *
05: * This software is distributed under the terms of the MX4J License version 1.0.
06: * See the terms of the MX4J License in the documentation provided with this software.
07: */
08:
09: package javax.management;
10:
11: import java.io.PrintStream;
12: import java.io.PrintWriter;
13:
14: /**
15: * @version $Revision: 1.9 $
16: */
17: public class MBeanException extends JMException {
18: private static final long serialVersionUID = 4066342430588744142L;
19:
20: /**
21: * @serial The nested exception
22: */
23: private final Exception exception;
24:
25: public MBeanException(Exception x) {
26: this .exception = x;
27: }
28:
29: public MBeanException(Exception x, String message) {
30: super (message);
31: this .exception = x;
32: }
33:
34: public String getMessage() {
35: return super .getMessage() + " nested exception is "
36: + getTargetException();
37: }
38:
39: public Exception getTargetException() {
40: return exception;
41: }
42:
43: public Throwable getCause() {
44: return getTargetException();
45: }
46:
47: public void printStackTrace() {
48: if (exception == null) {
49: super .printStackTrace();
50: } else {
51: synchronized (System.err) {
52: System.err.println(this );
53: exception.printStackTrace();
54: }
55: }
56: }
57:
58: public void printStackTrace(PrintStream s) {
59: if (exception == null) {
60: super .printStackTrace(s);
61: } else {
62: synchronized (s) {
63: s.println(this );
64: exception.printStackTrace(s);
65: }
66: }
67: }
68:
69: public void printStackTrace(PrintWriter w) {
70: if (exception == null) {
71: super.printStackTrace(w);
72: } else {
73: synchronized (w) {
74: w.println(this);
75: exception.printStackTrace(w);
76: }
77: }
78: }
79: }
|