KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > mq > SpyTransactionRolledBackException


1 /*
2 * JBoss, Home of Professional Open Source
3 * Copyright 2005, JBoss Inc., and individual contributors as indicated
4 * by the @authors tag. See the copyright.txt in the distribution for a
5 * full listing of individual contributors.
6 *
7 * This is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU Lesser General Public License as
9 * published by the Free Software Foundation; either version 2.1 of
10 * the License, or (at your option) any later version.
11 *
12 * This software is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this software; if not, write to the Free
19 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21 */

22 package org.jboss.mq;
23
24 import java.io.PrintStream JavaDoc;
25 import java.io.PrintWriter JavaDoc;
26
27 import javax.jms.TransactionRolledBackException JavaDoc;
28
29 import org.jboss.util.NestedException;
30 import org.jboss.util.NestedThrowable;
31
32 /**
33  * A TransactionRolledBackException with a nested <tt>Throwable</tt> detail
34  * object.
35  *
36  * @author <a HREF="mailto:adrian@jboss.org">Adrian Brock</a>
37  * @version <tt>$Revision: 37459 $</tt>
38  */

39 public class SpyTransactionRolledBackException extends TransactionRolledBackException JavaDoc implements NestedThrowable
40 {
41    // Constants -----------------------------------------------------
42

43    /** The serialVersionUID */
44    static final long serialVersionUID = 1764748894215274537L;
45    
46    // Attributes ----------------------------------------------------
47

48    /** The nested throwable */
49    protected Throwable JavaDoc nested;
50    
51    // Static --------------------------------------------------------
52

53    // Constructors --------------------------------------------------
54

55    /**
56     * Construct a <tt>SpyTransactionRolledBackException</tt> with the
57     * specified detail message.
58     *
59     * @param msg Detail message.
60     */

61    public SpyTransactionRolledBackException(final String JavaDoc msg)
62    {
63       super(msg);
64       this.nested = null;
65    }
66
67    /**
68     * Construct a <tt>SpyTransactionRolledBackException</tt> with the
69     * specified detail message and nested <tt>Throwable</tt>.
70     *
71     * @param msg Detail message.
72     * @param nested Nested <tt>Throwable</tt>.
73     */

74    public SpyTransactionRolledBackException(final String JavaDoc msg, final Throwable JavaDoc nested)
75    {
76       super(msg);
77       this.nested = nested;
78       NestedThrowable.Util.checkNested(this, nested);
79    }
80
81    /**
82     * Construct a <tt>SpyTransactionRolledBackException</tt> with the
83     * specified nested <tt>Throwable</tt>.
84     *
85     * @param nested Nested <tt>Throwable</tt>.
86     */

87    public SpyTransactionRolledBackException(final Throwable JavaDoc nested)
88    {
89       this(nested.getMessage(), nested);
90    }
91    
92    // Public --------------------------------------------------------
93

94    // NestedException implementation --------------------------------
95

96    /**
97     * Return the nested <tt>Throwable</tt>.
98     *
99     * @return Nested <tt>Throwable</tt>.
100     */

101    public Throwable JavaDoc getNested()
102    {
103       return nested;
104    }
105    
106    // Throwable overrides -------------------------------------------
107

108    public Throwable JavaDoc getCause()
109    {
110       return nested;
111    }
112
113    public void setLinkedException(final Exception JavaDoc e)
114    {
115       this.nested = e;
116    }
117
118    public Exception JavaDoc getLinkedException()
119    {
120       // jason: this is bad, but whatever... the jms folks should have had more
121
// insight
122
if (nested == null)
123          return this;
124       if (nested instanceof Exception JavaDoc)
125          return (Exception JavaDoc) nested;
126       return new NestedException(nested);
127    }
128
129    public String JavaDoc getMessage()
130    {
131       return NestedThrowable.Util.getMessage(super.getMessage(), nested);
132    }
133
134    public void printStackTrace(final PrintStream JavaDoc stream)
135    {
136       if (nested == null || NestedThrowable.PARENT_TRACE_ENABLED)
137          super.printStackTrace(stream);
138       NestedThrowable.Util.print(nested, stream);
139    }
140
141    public void printStackTrace(final PrintWriter JavaDoc writer)
142    {
143       if (nested == null || NestedThrowable.PARENT_TRACE_ENABLED)
144          super.printStackTrace(writer);
145       NestedThrowable.Util.print(nested, writer);
146    }
147
148    public void printStackTrace()
149    {
150       printStackTrace(System.err);
151    }
152    
153    // Package protected ---------------------------------------------
154

155    // Protected -----------------------------------------------------
156

157    // Private -------------------------------------------------------
158

159    // Inner classes -------------------------------------------------
160
}
Popular Tags