KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > hibernate > exception > NestableRuntimeException


1 /* ====================================================================
2  * The Apache Software License, Version 1.1
3  *
4  * Copyright (c) 2002-2003 The Apache Software Foundation. All rights
5  * reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * 1. Redistributions of source code must retain the above copyright
12  * notice, this list of conditions and the following disclaimer.
13  *
14  * 2. Redistributions in binary form must reproduce the above copyright
15  * notice, this list of conditions and the following disclaimer in
16  * the documentation and/or other materials provided with the
17  * distribution.
18  *
19  * 3. The end-user documentation included with the redistribution, if
20  * any, must include the following acknowledgement:
21  * "This product includes software developed by the
22  * Apache Software Foundation (http://www.apache.org/)."
23  * Alternately, this acknowledgement may appear in the software itself,
24  * if and wherever such third-party acknowledgements normally appear.
25  *
26  * 4. The names "The Jakarta Project", "Commons", and "Apache Software
27  * Foundation" must not be used to endorse or promote products derived
28  * from this software without prior written permission. For written
29  * permission, please contact apache@apache.org.
30  *
31  * 5. Products derived from this software may not be called "Apache"
32  * nor may "Apache" appear in their names without prior written
33  * permission of the Apache Software Foundation.
34  *
35  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
36  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
37  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
38  * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
39  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
40  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
41  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
42  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
43  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
44  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
45  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
46  * SUCH DAMAGE.
47  * ====================================================================
48  *
49  * This software consists of voluntary contributions made by many
50  * individuals on behalf of the Apache Software Foundation. For more
51  * information on the Apache Software Foundation, please see
52  * <http://www.apache.org/>.
53  */

54 package org.hibernate.exception;
55
56 import java.io.PrintStream JavaDoc;
57 import java.io.PrintWriter JavaDoc;
58
59 /**
60  * The base class of all runtime exceptions which can contain other
61  * exceptions.
62  *
63  * @author <a HREF="mailto:Rafal.Krzewski@e-point.pl">Rafal Krzewski</a>
64  * @author <a HREF="mailto:dlr@collab.net">Daniel Rall</a>
65  * @author <a HREF="mailto:knielsen@apache.org">Kasper Nielsen</a>
66  * @author <a HREF="mailto:steven@caswell.name">Steven Caswell</a>
67  * @version $Id: NestableRuntimeException.java,v 1.2 2004/11/21 00:11:27 pgmjsd Exp $
68  * @see org.apache.commons.lang.exception.NestableException
69  * @since 1.0
70  */

71 public class NestableRuntimeException extends RuntimeException JavaDoc implements Nestable {
72
73     /**
74      * The helper instance which contains much of the code which we
75      * delegate to.
76      */

77     protected NestableDelegate delegate = new NestableDelegate( this );
78
79     /**
80      * Holds the reference to the exception or error that caused
81      * this exception to be thrown.
82      */

83     private Throwable JavaDoc cause = null;
84
85     /**
86      * Constructs a new <code>NestableRuntimeException</code> without specified
87      * detail message.
88      */

89     public NestableRuntimeException() {
90         super();
91     }
92
93     /**
94      * Constructs a new <code>NestableRuntimeException</code> with specified
95      * detail message.
96      *
97      * @param msg the error message
98      */

99     public NestableRuntimeException(String JavaDoc msg) {
100         super( msg );
101     }
102
103     /**
104      * Constructs a new <code>NestableRuntimeException</code> with specified
105      * nested <code>Throwable</code>.
106      *
107      * @param cause the exception or error that caused this exception to be
108      * thrown
109      */

110     public NestableRuntimeException(Throwable JavaDoc cause) {
111         super();
112         this.cause = cause;
113     }
114
115     /**
116      * Constructs a new <code>NestableRuntimeException</code> with specified
117      * detail message and nested <code>Throwable</code>.
118      *
119      * @param msg the error message
120      * @param cause the exception or error that caused this exception to be
121      * thrown
122      */

123     public NestableRuntimeException(String JavaDoc msg, Throwable JavaDoc cause) {
124         super( msg );
125         this.cause = cause;
126     }
127
128     public Throwable JavaDoc getCause() {
129         return cause;
130     }
131
132     /**
133      * Returns the detail message string of this throwable. If it was
134      * created with a null message, returns the following:
135      * ( cause==null ? null : cause.toString( ).
136      */

137     public String JavaDoc getMessage() {
138         if ( super.getMessage() != null ) {
139             return super.getMessage();
140         }
141         else if ( cause != null ) {
142             return cause.toString();
143         }
144         else {
145             return null;
146         }
147     }
148
149     public String JavaDoc getMessage(int index) {
150         if ( index == 0 ) {
151             return super.getMessage();
152         }
153         else {
154             return delegate.getMessage( index );
155         }
156     }
157
158     public String JavaDoc[] getMessages() {
159         return delegate.getMessages();
160     }
161
162     public Throwable JavaDoc getThrowable(int index) {
163         return delegate.getThrowable( index );
164     }
165
166     public int getThrowableCount() {
167         return delegate.getThrowableCount();
168     }
169
170     public Throwable JavaDoc[] getThrowables() {
171         return delegate.getThrowables();
172     }
173
174     public int indexOfThrowable(Class JavaDoc type) {
175         return delegate.indexOfThrowable( type, 0 );
176     }
177
178     public int indexOfThrowable(Class JavaDoc type, int fromIndex) {
179         return delegate.indexOfThrowable( type, fromIndex );
180     }
181
182     public void printStackTrace() {
183         delegate.printStackTrace();
184     }
185
186     public void printStackTrace(PrintStream JavaDoc out) {
187         delegate.printStackTrace( out );
188     }
189
190     public void printStackTrace(PrintWriter JavaDoc out) {
191         delegate.printStackTrace( out );
192     }
193
194     public final void printPartialStackTrace(PrintWriter JavaDoc out) {
195         super.printStackTrace( out );
196     }
197
198 }
199
Popular Tags