KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > de > susebox > java > lang > ExtIndexOutOfBoundsException


1 /*
2  * ExtIndexOutOfBoundsException.java: Extended standard exceptio for stacks
3  *
4  * Copyright (C) 2001 Heiko Blau
5  *
6  * This file belongs to the Susebox Java Core Library (Susebox JCL).
7  * The Susebox JCL is free software; you can redistribute it and/or modify it
8  * under the terms of the GNU Lesser General Public License as published by the
9  * Free Software Foundation; either version 2.1 of the License, or (at your
10  * option) any later version.
11  *
12  * This software is distributed in the hope that it will be useful, but WITHOUT
13  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14  * FITNESS FOR A PARTICULAR PURPOSE.
15  * See the GNU Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public License along
18  * with the Susebox JCL. If not, write to the
19  *
20  * Free Software Foundation, Inc.
21  * 59 Temple Place, Suite 330,
22  * Boston, MA 02111-1307
23  * USA
24  *
25  * or check the Internet: http://www.fsf.org
26  *
27  * Contact:
28  * email: heiko@susebox.de
29  */

30
31 package de.susebox.java.lang;
32
33 //------------------------------------------------------------------------------
34
// Imports
35
//
36
import java.lang.IndexOutOfBoundsException JavaDoc;
37
38 //------------------------------------------------------------------------------
39
// ExtIndexOutOfBoundsException - definition
40
//
41

42 /**
43  * Implementation of the {@link ThrowableList} interface for the JDK
44  * {@link java.lang.IndexOutOfBoundsException}.
45  *
46  * @version 1.00, 2001/06/26
47  * @author Heiko Blau
48  */

49 public class ExtIndexOutOfBoundsException
50   extends IndexOutOfBoundsException JavaDoc
51   implements ThrowableList
52 {
53   
54   //---------------------------------------------------------------------------
55
// methods of the ThrowableList interface
56
//
57

58   /**
59    * Retrieving the cause of a <code>Throwable</code>. This is the method introduced
60    * with JDK 1.4. It replaces the older {@link #nextThrowable}.
61    *
62    * @return the cause of this <code>Throwable</code>
63    * @see java.lang.Throwable#getCause
64    */

65   public Throwable JavaDoc getCause() {
66     return _next;
67   }
68   
69   /**
70    * Method to traverse the list of {@link java.lang.Throwable}.
71    * See {@link ThrowableList#nextThrowable} for details.
72    *
73    * @return the "earlier" throwable
74    * @deprecated use the JDK 1.4 call {@link #getCause} instead
75    */

76   public Throwable JavaDoc nextThrowable() {
77     return getCause();
78   }
79
80   /**
81    * Check if <code>this</code> is only a throwable that wraps the real one. See
82    * {@link ThrowableList#isWrapper} for details.
83    *
84    * @return <code>true</code> if this is a wrapper throwable,
85    * <code>false</code> otherwise
86    */

87   public boolean isWrapper() {
88     return _isWrapper;
89   }
90   
91   /**
92    * Getting the format string of a throwable message. This can also be the
93    * message itself if there are no arguments.
94    *
95    * @return the format string being used by {@link java.text.MessageFormat}
96    * @see #getArguments
97    */

98   public String JavaDoc getFormat() {
99     return super.getMessage();
100   }
101   
102   /**
103    * Retrieving the arguments for message formats. These arguments are used by
104    * the {@link java.text.MessageFormat#format} call.
105    *
106    * @return the arguments for a message format
107    * @see #getFormat
108    */

109   public Object JavaDoc[] getArguments() {
110     return _args;
111   }
112   
113   
114   //---------------------------------------------------------------------------
115
// constructors
116
//
117

118   /**
119    * This constructor takes a simple message string like ordinary Java
120    * {@link java.lang.Throwable} classes. This is the most convenient form to
121    * construct an <code>ThrowableList</code> throwable.
122    *
123    * @param msg message for this <code>Throwable</code> instance
124    */

125   public ExtIndexOutOfBoundsException(String JavaDoc msg) {
126     this(null, msg, null);
127   }
128   
129   /**
130    * This constructor should be used for wrapping another throwable. While reading
131    * data an IOException may occur, but a certain interface requires a
132    * <code>java.sql.SQLException</code>. Simply use:
133    *<blockquote><pre>
134    * try {
135    * ...
136    * } catch (NullPointerException ex) {
137    * throw new ExtIndexOutOfBoundsException(ex);
138    * }
139    *</pre></blockquote>
140    *
141    * @param ex the throwable to wrap
142    */

143   public ExtIndexOutOfBoundsException(Throwable JavaDoc ex) {
144     this(ex, null, null);
145   }
146   
147   /**
148    * If one likes to add ones own information to a throwable, this constructor is
149    * the easiest way to do so. By using such an approach a throwable trace with useful
150    * additional informations (which file could be found, what username is unknown)
151    * can be realized:
152    *<blockquote><pre>
153    * try {
154    * ...
155    * } catch (SQLException ex) {
156    * throw new IOException(ex, "while connecting to " + url);
157    * }
158    *</pre></blockquote>
159    *
160    * @param ex the inner throwable
161    * @param msg throwable message
162    */

163   public ExtIndexOutOfBoundsException(Throwable JavaDoc ex, String JavaDoc msg) {
164     this(ex, msg, null);
165   }
166   
167   /**
168    * This constructor takes a format string and its arguments. The format string
169    * must have a form that can be used by {@link java.text.MessageFormat} methods.
170    * That means:
171    *<blockquote><pre>
172    * java.text.Message.format(fmt, args)
173    *</pre></blockquote>
174    * is similar to
175    *<blockquote><pre>
176    * new MyException(fmt, args).getMessage();
177    *</pre></blockquote>
178    *
179    * @param fmt throwable message
180    * @param args arguments for the given format string
181    */

182   public ExtIndexOutOfBoundsException(String JavaDoc fmt, Object JavaDoc[] args) {
183     this(null, fmt, args);
184   }
185   
186   /**
187    * This is the most complex way to construct an <code>ThrowableList</code>-
188    * Throwable.<br>
189    * An inner throwable is accompanied by a format string and its arguments.
190    * Use this constructor in language-sensitive contexts or for formalized messages.
191    * The meaning of the parameters is explained in the other constructors.
192    *
193    * @param ex the inner throwable
194    * @param fmt throwable message
195    * @param args arguments for the given format string
196    */

197   public ExtIndexOutOfBoundsException(Throwable JavaDoc ex, String JavaDoc fmt, Object JavaDoc[] args) {
198     super(fmt);
199    
200     if (ex != null && fmt == null) {
201       _isWrapper = true;
202     } else {
203       _isWrapper = false;
204     }
205     _next = ex;
206     _args = args;
207   }
208   
209   
210   //---------------------------------------------------------------------------
211
// overridden methods
212
//
213

214   /**
215    * Implementation of the standard {@link java.lang.Throwable#getMessage} method. It
216    * delegates the call to the central {@link ThrowableMessageFormatter#getMessage}
217    * method.
218    *
219    * @return the formatted throwable message
220    * @see ThrowableMessageFormatter
221    */

222   public String JavaDoc getMessage() {
223     return ThrowableMessageFormatter.getMessage(this);
224   }
225   
226
227   //---------------------------------------------------------------------------
228
// members
229
//
230

231   /**
232    * the parameters to be used when formatting the throwable message
233    */

234   protected Object JavaDoc[] _args = null;
235
236   /**
237    * The wrapped, nested of next throwable.
238    */

239   protected Throwable JavaDoc _next = null;
240   
241   /**
242    * If <code>true</code> this is only a wrapper throwable with the real one
243    * being returned by {@link #nextThrowable}, <code>false</code> for standalone,
244    * nested or subsequent exceptions
245    */

246   protected boolean _isWrapper = false;
247 }
248
Popular Tags