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