KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * ExtUnsupportedOperationException.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.UnsupportedOperationException JavaDoc;
37
38
39 //------------------------------------------------------------------------------
40
// ExtUnsupportedOperationException - definition
41
//
42

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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