KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * ExtIllegalArgumentException.java: Extended standard throwable 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.IllegalArgumentException JavaDoc;
37
38
39 //------------------------------------------------------------------------------
40
// ExtIllegalArgumentException - definition
41
//
42

43 /**
44  * Implementation of the {@link ThrowableList} interface for the well-known JDK
45  * {@link java.lang.IllegalArgumentException}.
46  *
47  * @author Heiko Blau
48  */

49 public class ExtIllegalArgumentException extends IllegalArgumentException JavaDoc implements ThrowableList
50 {
51   //---------------------------------------------------------------------------
52
// methods of the ThrowableList interface
53
//
54

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

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

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

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

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

106   public Object JavaDoc[] getArguments() {
107     return _args;
108   }
109   
110   
111   //---------------------------------------------------------------------------
112
// constructors
113
//
114

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

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

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

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

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

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

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

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

228   /**
229    * the parameters to be used when formatting the throwable message
230    */

231   protected Object JavaDoc[] _args = null;
232
233   /**
234    * The wrapped, nested of next throwable.
235    */

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

243   protected boolean _isWrapper = false;
244 }
245
Popular Tags