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: * Thrown when a MBean method invoked by the MBeanServer throws any non-reflection RuntimeException.
16: *
17: * @version $Revision: 1.8 $
18: */
19: public class RuntimeMBeanException extends JMRuntimeException {
20: private static final long serialVersionUID = 5274912751982730171L;
21:
22: /**
23: * @serial The nested exception
24: */
25: private RuntimeException runtimeException;
26:
27: /**
28: * Creates a new RuntimeMBeanException
29: *
30: * @param exception The nested RuntimeException
31: */
32: public RuntimeMBeanException(RuntimeException exception) {
33: this .runtimeException = exception;
34: }
35:
36: /**
37: * Creates a new RuntimeMBeanException
38: *
39: * @param exception The nested RuntimeException
40: * @param message The message
41: */
42: public RuntimeMBeanException(RuntimeException exception,
43: String message) {
44: super (message);
45: this .runtimeException = exception;
46: }
47:
48: /**
49: * Returns the nested RuntimeException
50: */
51: public RuntimeException getTargetException() {
52: return runtimeException;
53: }
54:
55: /**
56: * Returns the nested RuntimeException
57: */
58: public Throwable getCause() {
59: return getTargetException();
60: }
61:
62: public String getMessage() {
63: return super .getMessage() + " nested runtime exception is "
64: + runtimeException;
65: }
66:
67: public void printStackTrace() {
68: if (runtimeException == null) {
69: super .printStackTrace();
70: } else {
71: synchronized (System.err) {
72: System.err.println(this );
73: runtimeException.printStackTrace();
74: }
75: }
76: }
77:
78: public void printStackTrace(PrintStream s) {
79: if (runtimeException == null) {
80: super .printStackTrace(s);
81: } else {
82: synchronized (s) {
83: s.println(this );
84: runtimeException.printStackTrace(s);
85: }
86: }
87: }
88:
89: public void printStackTrace(PrintWriter w) {
90: if (runtimeException == null) {
91: super.printStackTrace(w);
92: } else {
93: synchronized (w) {
94: w.println(this);
95: runtimeException.printStackTrace(w);
96: }
97: }
98: }
99: }
|