001: /*
002: * JBoss, Home of Professional Open Source.
003: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
004: * as indicated by the @author tags. See the copyright.txt file in the
005: * distribution for a full listing of individual contributors.
006: *
007: * This is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU Lesser General Public License as
009: * published by the Free Software Foundation; either version 2.1 of
010: * the License, or (at your option) any later version.
011: *
012: * This software is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this software; if not, write to the Free
019: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
021: */
022: package javax.management;
023:
024: /**
025: * A wrapper for exceptions thrown by MBeans.
026: *
027: * @author <a href="mailto:juha@jboss.org">Juha Lindfors</a>
028: * @author <a href="mailto:Adrian.Brock@HappeningTimes.com">Adrian Brock</a>
029: * @version $Revision: 57200 $
030: *
031: * <p><b>Revisions:</b>
032: *
033: * <p><b>20020313 Juha Lindfors:</b>
034: * <ul>
035: * <li> Overriding toString() to print out the root exception </li>
036: * </ul>
037: *
038: * <p><b>20020710 Adrian Brock:</b>
039: * <ul>
040: * <li> Serialization </li>
041: * </ul>
042: */
043: public class MBeanException extends JMException {
044: // Attributes ----------------------------------------------------
045:
046: /**
047: * The wrapped exception.
048: */
049: private Exception exception = null;
050:
051: private static final long serialVersionUID = 4066342430588744142L;
052:
053: // Constructors --------------------------------------------------
054:
055: /**
056: * Construct a new MBeanException from a given exception.
057: *
058: * @param exception the exception to wrap.
059: */
060: public MBeanException(Exception exception) {
061: super ();
062: this .exception = exception;
063: }
064:
065: /**
066: * Construct a new MBeanException from a given exception and message.
067: *
068: * @param e the exception to wrap.
069: * @param message the specified message.
070: */
071: public MBeanException(Exception exception, String message) {
072: super (message);
073: this .exception = exception;
074: }
075:
076: // Public --------------------------------------------------------
077:
078: /**
079: * Retrieves the wrapped exception.
080: *
081: * @return the wrapped exception.
082: */
083: public Exception getTargetException() {
084: return exception;
085: }
086:
087: /**
088: * Retrieves the wrapped exception.
089: *
090: * @return the wrapped exception.
091: */
092: public Throwable getCause() {
093: return exception;
094: }
095:
096: // JMException overrides -----------------------------------------
097:
098: /**
099: * Returns a string representation of this exception. The returned string
100: * contains this exception name, message and a string representation of the
101: * target exception if it has been set.
102: *
103: * @return string representation of this exception
104: */
105: public String toString() {
106: return "MBeanException: "
107: + getMessage()
108: + ((exception == null) ? "" : " Cause: "
109: + exception.toString());
110: }
111:
112: }
|