KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > quartz > SchedulerException


1
2 /*
3  * Copyright 2004-2005 OpenSymphony
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
6  * use this file except in compliance with the License. You may obtain a copy
7  * of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14  * License for the specific language governing permissions and limitations
15  * under the License.
16  *
17  */

18
19 /*
20  * Previously Copyright (c) 2001-2004 James House
21  */

22 package org.quartz;
23
24 import java.io.PrintStream JavaDoc;
25 import java.io.PrintWriter JavaDoc;
26
27 import org.quartz.utils.ExceptionHelper;
28
29 /**
30  * <p>
31  * Base class for exceptions thrown by the Quartz <code>{@link Scheduler}</code>.
32  * </p>
33  *
34  * <p>
35  * <code>SchedulerException</code> s may contain a reference to another
36  * <code>Exception</code>, which was the underlying cause of the <code>SchedulerException</code>.
37  * </p>
38  *
39  * @author James House
40  */

41 public class SchedulerException extends Exception JavaDoc {
42
43     /*
44      * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
45      *
46      * Constants.
47      *
48      * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
49      */

50
51     public static final int ERR_UNSPECIFIED = 0;
52
53     public static final int ERR_BAD_CONFIGURATION = 50;
54
55     public static final int ERR_TIME_BROKER_FAILURE = 70;
56
57     public static final int ERR_CLIENT_ERROR = 100;
58
59     public static final int ERR_COMMUNICATION_FAILURE = 200;
60
61     public static final int ERR_UNSUPPORTED_FUNCTION_IN_THIS_CONFIGURATION = 210;
62
63     public static final int ERR_PERSISTENCE = 400;
64
65     public static final int ERR_PERSISTENCE_JOB_DOES_NOT_EXIST = 410;
66
67     public static final int ERR_PERSISTENCE_CALENDAR_DOES_NOT_EXIST = 420;
68
69     public static final int ERR_PERSISTENCE_TRIGGER_DOES_NOT_EXIST = 430;
70
71     public static final int ERR_PERSISTENCE_CRITICAL_FAILURE = 499;
72
73     public static final int ERR_THREAD_POOL = 500;
74
75     public static final int ERR_THREAD_POOL_EXHAUSTED = 510;
76
77     public static final int ERR_THREAD_POOL_CRITICAL_FAILURE = 599;
78
79     public static final int ERR_JOB_LISTENER = 600;
80
81     public static final int ERR_JOB_LISTENER_NOT_FOUND = 610;
82
83     public static final int ERR_TRIGGER_LISTENER = 700;
84
85     public static final int ERR_TRIGGER_LISTENER_NOT_FOUND = 710;
86
87     public static final int ERR_JOB_EXECUTION_THREW_EXCEPTION = 800;
88
89     public static final int ERR_TRIGGER_THREW_EXCEPTION = 850;
90
91     /*
92      * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
93      *
94      * Data members.
95      *
96      * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
97      */

98
99     private Throwable JavaDoc cause;
100
101     private int errorCode = ERR_UNSPECIFIED;
102
103     /*
104      * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
105      *
106      * Constructors.
107      *
108      * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
109      */

110
111     public SchedulerException() {
112         super();
113     }
114
115     public SchedulerException(String JavaDoc msg) {
116         super(msg);
117     }
118
119     public SchedulerException(String JavaDoc msg, int errorCode) {
120         super(msg);
121         setErrorCode(errorCode);
122     }
123
124     public SchedulerException(Throwable JavaDoc cause) {
125         super(cause.toString());
126         setCause(cause);
127     }
128
129     public SchedulerException(String JavaDoc msg, Throwable JavaDoc cause) {
130         super(msg);
131         setCause(cause);
132     }
133
134     public SchedulerException(String JavaDoc msg, Throwable JavaDoc cause, int errorCode) {
135         super(msg);
136         setCause(cause);
137         setErrorCode(errorCode);
138     }
139
140     private void setCause(Throwable JavaDoc cause) {
141         if (ExceptionHelper.supportsNestedThrowable()) {
142             ExceptionHelper.setCause(this, cause);
143         } else {
144             this.cause = cause;
145         }
146     }
147     
148     /*
149      * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
150      *
151      * Interface.
152      *
153      * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
154      */

155
156     /**
157      * <p>
158      * Return the exception that is the underlying cause of this exception.
159      * </p>
160      *
161      * <p>
162      * This may be used to find more detail about the cause of the error.
163      * </p>
164      *
165      * @return the underlying exception, or <code>null</code> if there is not
166      * one.
167      */

168     public Throwable JavaDoc getUnderlyingException() {
169         return (ExceptionHelper.supportsNestedThrowable()) ?
170             ExceptionHelper.getCause(this) : cause;
171     }
172
173     /**
174      * <p>
175      * Get the error code associated with this exception.
176      * </p>
177      *
178      * <p>
179      * This may be used to find more detail about the cause of the error.
180      * </p>
181      *
182      * @return one of the ERR_XXX constants defined in this class.
183      */

184     public int getErrorCode() {
185         return errorCode;
186     }
187
188     /**
189      * <p>
190      * Get the error code associated with this exception.
191      * </p>
192      *
193      * <p>
194      * This may be used to provide more detail about the cause of the error.
195      * </p>
196      *
197      * @param errorCode
198      * one of the ERR_XXX constants defined in this class.
199      */

200     public void setErrorCode(int errorCode) {
201         this.errorCode = errorCode;
202     }
203
204     /**
205      * <p>
206      * Determine if the specified error code is in the <code>'ERR_PERSISTENCE'</code>
207      * category of errors.
208      * </p>
209      */

210     public boolean isPersistenceError() {
211         return (errorCode >= ERR_PERSISTENCE && errorCode <= ERR_PERSISTENCE + 99);
212     }
213
214     /**
215      * <p>
216      * Determine if the specified error code is in the <code>'ERR_THREAD_POOL'</code>
217      * category of errors.
218      * </p>
219      */

220     public boolean isThreadPoolError() {
221         return (errorCode >= ERR_THREAD_POOL && errorCode <= ERR_THREAD_POOL + 99);
222     }
223
224     /**
225      * <p>
226      * Determine if the specified error code is in the <code>'ERR_JOB_LISTENER'</code>
227      * category of errors.
228      * </p>
229      */

230     public boolean isJobListenerError() {
231         return (errorCode >= ERR_JOB_LISTENER && errorCode <= ERR_JOB_LISTENER + 99);
232     }
233
234     /**
235      * <p>
236      * Determine if the specified error code is in the <code>'ERR_TRIGGER_LISTENER'</code>
237      * category of errors.
238      * </p>
239      */

240     public boolean isTriggerListenerError() {
241         return (errorCode >= ERR_TRIGGER_LISTENER && errorCode <= ERR_TRIGGER_LISTENER + 99);
242     }
243
244     /**
245      * <p>
246      * Determine if the specified error code is in the <code>'ERR_CLIENT_ERROR'</code>
247      * category of errors.
248      * </p>
249      */

250     public boolean isClientError() {
251         return (errorCode >= ERR_CLIENT_ERROR && errorCode <= ERR_CLIENT_ERROR + 99);
252     }
253
254     /**
255      * <p>
256      * Determine if the specified error code is in the <code>'ERR_CLIENT_ERROR'</code>
257      * category of errors.
258      * </p>
259      */

260     public boolean isConfigurationError() {
261         return (errorCode >= ERR_BAD_CONFIGURATION && errorCode <= ERR_BAD_CONFIGURATION + 49);
262     }
263
264     public String JavaDoc toString() {
265         Throwable JavaDoc cause = getUnderlyingException();
266         if (cause == null || cause == this) {
267             return super.toString();
268         } else {
269             return super.toString() + " [See nested exception: " + cause + "]";
270         }
271     }
272
273     /**
274      * <P>
275      * Print a stack trace to the standard error stream.
276      * </P>
277      *
278      * <P>
279      * This overridden version will print the nested stack trace if available,
280      * otherwise it prints only this exception's stack.
281      * </P>
282      */

283     public void printStackTrace() {
284         printStackTrace(System.err);
285     }
286
287     /**
288      * <P>
289      * Print a stack trace to the specified stream.
290      * </P>
291      *
292      * <P>
293      * This overridden version will print the nested stack trace if available,
294      * otherwise it prints only this exception's stack.
295      * </P>
296      *
297      * @param out
298      * the stream to which the stack traces will be printed.
299      */

300     public void printStackTrace(PrintStream JavaDoc out) {
301         super.printStackTrace(out);
302         
303         if (cause != null) {
304             synchronized (out) {
305                 out.println("* Nested Exception (Underlying Cause) ---------------");
306                 cause.printStackTrace(out);
307             }
308         }
309     }
310
311     /**
312      * <P>
313      * Print a stack trace to the specified writer.
314      * </P>
315      *
316      * <P>
317      * This overridden version will print the nested stack trace if available,
318      * otherwise it prints this exception's stack.
319      * </P>
320      *
321      * @param out
322      * the writer to which the stack traces will be printed.
323      */

324     public void printStackTrace(PrintWriter JavaDoc out) {
325         super.printStackTrace(out);
326         
327         if (cause != null) {
328             synchronized (out) {
329                 out.println("* Nested Exception (Underlying Cause) ---------------");
330                 cause.printStackTrace(out);
331             }
332         }
333     }
334
335 }
336
Popular Tags