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 org.jboss.mq;
023:
024: import java.io.PrintStream;
025: import java.io.PrintWriter;
026:
027: import javax.jms.TransactionRolledBackException;
028:
029: import org.jboss.util.NestedException;
030: import org.jboss.util.NestedThrowable;
031:
032: /**
033: * A TransactionRolledBackException with a nested <tt>Throwable</tt> detail
034: * object.
035: *
036: * @author <a href="mailto:adrian@jboss.org">Adrian Brock</a>
037: * @version <tt>$Revision: 57198 $</tt>
038: */
039: public class SpyTransactionRolledBackException extends
040: TransactionRolledBackException implements NestedThrowable {
041: // Constants -----------------------------------------------------
042:
043: /** The serialVersionUID */
044: static final long serialVersionUID = 1764748894215274537L;
045:
046: // Attributes ----------------------------------------------------
047:
048: /** The nested throwable */
049: protected Throwable nested;
050:
051: // Static --------------------------------------------------------
052:
053: // Constructors --------------------------------------------------
054:
055: /**
056: * Construct a <tt>SpyTransactionRolledBackException</tt> with the
057: * specified detail message.
058: *
059: * @param msg Detail message.
060: */
061: public SpyTransactionRolledBackException(final String msg) {
062: super (msg);
063: this .nested = null;
064: }
065:
066: /**
067: * Construct a <tt>SpyTransactionRolledBackException</tt> with the
068: * specified detail message and nested <tt>Throwable</tt>.
069: *
070: * @param msg Detail message.
071: * @param nested Nested <tt>Throwable</tt>.
072: */
073: public SpyTransactionRolledBackException(final String msg,
074: final Throwable nested) {
075: super (msg);
076: this .nested = nested;
077: NestedThrowable.Util.checkNested(this , nested);
078: }
079:
080: /**
081: * Construct a <tt>SpyTransactionRolledBackException</tt> with the
082: * specified nested <tt>Throwable</tt>.
083: *
084: * @param nested Nested <tt>Throwable</tt>.
085: */
086: public SpyTransactionRolledBackException(final Throwable nested) {
087: this (nested.getMessage(), nested);
088: }
089:
090: // Public --------------------------------------------------------
091:
092: // NestedException implementation --------------------------------
093:
094: /**
095: * Return the nested <tt>Throwable</tt>.
096: *
097: * @return Nested <tt>Throwable</tt>.
098: */
099: public Throwable getNested() {
100: return nested;
101: }
102:
103: // Throwable overrides -------------------------------------------
104:
105: public Throwable getCause() {
106: return nested;
107: }
108:
109: public void setLinkedException(final Exception e) {
110: this .nested = e;
111: }
112:
113: public Exception getLinkedException() {
114: // jason: this is bad, but whatever... the jms folks should have had more
115: // insight
116: if (nested == null)
117: return this ;
118: if (nested instanceof Exception)
119: return (Exception) nested;
120: return new NestedException(nested);
121: }
122:
123: public String getMessage() {
124: return NestedThrowable.Util.getMessage(super .getMessage(),
125: nested);
126: }
127:
128: public void printStackTrace(final PrintStream stream) {
129: if (nested == null || NestedThrowable.PARENT_TRACE_ENABLED)
130: super .printStackTrace(stream);
131: NestedThrowable.Util.print(nested, stream);
132: }
133:
134: public void printStackTrace(final PrintWriter writer) {
135: if (nested == null || NestedThrowable.PARENT_TRACE_ENABLED)
136: super .printStackTrace(writer);
137: NestedThrowable.Util.print(nested, writer);
138: }
139:
140: public void printStackTrace() {
141: printStackTrace(System.err);
142: }
143:
144: // Package protected ---------------------------------------------
145:
146: // Protected -----------------------------------------------------
147:
148: // Private -------------------------------------------------------
149:
150: // Inner classes -------------------------------------------------
151: }
|