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: * Wraps runtime 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: * <p><b>20020711 Adrian Brock:</b>
038: * <ul>
039: * <li> Serialization </li>
040: * </ul>
041: */
042: public class RuntimeMBeanException extends JMRuntimeException {
043: // Constants -----------------------------------------------------
044:
045: private static final long serialVersionUID = 5274912751982730171L;
046:
047: // Attributes ----------------------------------------------------
048:
049: /**
050: * The wrapped runtime exception.
051: */
052: private RuntimeException runtimeException = null;
053:
054: // Constructors --------------------------------------------------
055:
056: /**
057: * Construct a new RuntimeMBeanException from a given runtime exception.
058: *
059: * @param e the runtime exception to wrap.
060: */
061: public RuntimeMBeanException(RuntimeException e) {
062: super ();
063: this .runtimeException = e;
064: }
065:
066: /**
067: * Construct a new RuntimeMBeanException from a given runtime exception
068: * and message.
069: *
070: * @param e the runtime exception to wrap.
071: * @param message the specified message.
072: */
073: public RuntimeMBeanException(RuntimeException e, String message) {
074: super (message);
075: this .runtimeException = e;
076: }
077:
078: // Public --------------------------------------------------------
079:
080: /**
081: * Retrieves the wrapped runtime exception.
082: *
083: * @return the wrapped runtime exception.
084: */
085: public RuntimeException getTargetException() {
086: return runtimeException;
087: }
088:
089: /**
090: * Retrieves the wrapped runtime exception.
091: *
092: * @return the wrapped runtime exception.
093: */
094: public Throwable getCause() {
095: return runtimeException;
096: }
097:
098: // JMRuntimeException overrides ----------------------------------
099:
100: /**
101: * Returns a string representation of this exception. The returned string
102: * contains this exception name, message and a string representation of the
103: * target exception if it has been set.
104: *
105: * @return string representation of this exception
106: */
107: public String toString() {
108: return "RuntimeMBeanException: "
109: + getMessage()
110: + ((runtimeException == null) ? "" : " Cause: "
111: + runtimeException.toString());
112: }
113:
114: }
|