KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > quartz > JobDataMap


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.Serializable JavaDoc;
25 import java.util.Map JavaDoc;
26
27 import org.quartz.utils.StringKeyDirtyFlagMap;
28
29 /**
30  * <p>
31  * Holds state information for <code>Job</code> instances.
32  * </p>
33  *
34  * <p>
35  * <code>JobDataMap</code> instances are stored once when the <code>Job</code>
36  * is added to a scheduler. They are also re-persisted after every execution of
37  * <code>StatefulJob</code> instances.
38  * </p>
39  *
40  * <p>
41  * <code>JobDataMap</code> instances can also be stored with a
42  * <code>Trigger</code>. This can be useful in the case where you have a Job
43  * that is stored in the scheduler for regular/repeated use by multiple
44  * Triggers, yet with each independent triggering, you want to supply the
45  * Job with different data inputs.
46  * </p>
47  *
48  * <p>
49  * The <code>JobExecutionContext</code> passed to a Job at execution time
50  * also contains a convenience <code>JobDataMap</code> that is the result
51  * of merging the contents of the trigger's JobDataMap (if any) over the
52  * Job's JobDataMap (if any).
53  * </p>
54  *
55  * @see Job
56  * @see StatefulJob
57  * @see Trigger
58  * @see JobExecutionContext
59  *
60  * @author James House
61  */

62 public class JobDataMap extends StringKeyDirtyFlagMap implements Serializable JavaDoc {
63
64     private static final long serialVersionUID = -6939901990106713909L;
65     
66     /*
67      * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
68      *
69      * Data members.
70      *
71      * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
72      */

73
74     /**
75      * <p>
76      * Create an empty <code>JobDataMap</code>.
77      * </p>
78      */

79     public JobDataMap() {
80         super(15);
81     }
82
83     /**
84      * <p>
85      * Create a <code>JobDataMap</code> with the given data.
86      * </p>
87      */

88     public JobDataMap(Map JavaDoc map) {
89         this();
90
91         putAll(map);
92     }
93
94     /*
95      * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
96      *
97      * Interface.
98      *
99      * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
100      */

101
102     /**
103      * <p>
104      * Adds the given <code>boolean</code> value as a string version to the
105      * <code>Job</code>'s data map.
106      * </p>
107      */

108     public void putAsString(String JavaDoc key, boolean value) {
109         String JavaDoc strValue = new Boolean JavaDoc(value).toString();
110
111         super.put(key, strValue);
112     }
113
114     /**
115      * <p>
116      * Adds the given <code>Boolean</code> value as a string version to the
117      * <code>Job</code>'s data map.
118      * </p>
119      */

120     public void putAsString(String JavaDoc key, Boolean JavaDoc value) {
121         String JavaDoc strValue = value.toString();
122
123         super.put(key, strValue);
124     }
125
126     /**
127      * <p>
128      * Adds the given <code>char</code> value as a string version to the
129      * <code>Job</code>'s data map.
130      * </p>
131      */

132     public void putAsString(String JavaDoc key, char value) {
133         String JavaDoc strValue = new Character JavaDoc(value).toString();
134
135         super.put(key, strValue);
136     }
137
138     /**
139      * <p>
140      * Adds the given <code>Character</code> value as a string version to the
141      * <code>Job</code>'s data map.
142      * </p>
143      */

144     public void putAsString(String JavaDoc key, Character JavaDoc value) {
145         String JavaDoc strValue = value.toString();
146
147         super.put(key, strValue);
148     }
149
150     /**
151      * <p>
152      * Adds the given <code>double</code> value as a string version to the
153      * <code>Job</code>'s data map.
154      * </p>
155      */

156     public void putAsString(String JavaDoc key, double value) {
157         String JavaDoc strValue = new Double JavaDoc(value).toString();
158
159         super.put(key, strValue);
160     }
161
162     /**
163      * <p>
164      * Adds the given <code>Double</code> value as a string version to the
165      * <code>Job</code>'s data map.
166      * </p>
167      */

168     public void putAsString(String JavaDoc key, Double JavaDoc value) {
169         String JavaDoc strValue = value.toString();
170
171         super.put(key, strValue);
172     }
173
174     /**
175      * <p>
176      * Adds the given <code>float</code> value as a string version to the
177      * <code>Job</code>'s data map.
178      * </p>
179      */

180     public void putAsString(String JavaDoc key, float value) {
181         String JavaDoc strValue = new Float JavaDoc(value).toString();
182
183         super.put(key, strValue);
184     }
185
186     /**
187      * <p>
188      * Adds the given <code>Float</code> value as a string version to the
189      * <code>Job</code>'s data map.
190      * </p>
191      */

192     public void putAsString(String JavaDoc key, Float JavaDoc value) {
193         String JavaDoc strValue = value.toString();
194
195         super.put(key, strValue);
196     }
197
198     /**
199      * <p>
200      * Adds the given <code>int</code> value as a string version to the
201      * <code>Job</code>'s data map.
202      * </p>
203      */

204     public void putAsString(String JavaDoc key, int value) {
205         String JavaDoc strValue = new Integer JavaDoc(value).toString();
206
207         super.put(key, strValue);
208     }
209
210     /**
211      * <p>
212      * Adds the given <code>Integer</code> value as a string version to the
213      * <code>Job</code>'s data map.
214      * </p>
215      */

216     public void putAsString(String JavaDoc key, Integer JavaDoc value) {
217         String JavaDoc strValue = value.toString();
218
219         super.put(key, strValue);
220     }
221
222     /**
223      * <p>
224      * Adds the given <code>long</code> value as a string version to the
225      * <code>Job</code>'s data map.
226      * </p>
227      */

228     public void putAsString(String JavaDoc key, long value) {
229         String JavaDoc strValue = new Long JavaDoc(value).toString();
230
231         super.put(key, strValue);
232     }
233
234     /**
235      * <p>
236      * Adds the given <code>Long</code> value as a string version to the
237      * <code>Job</code>'s data map.
238      * </p>
239      */

240     public void putAsString(String JavaDoc key, Long JavaDoc value) {
241         String JavaDoc strValue = value.toString();
242
243         super.put(key, strValue);
244     }
245
246     /**
247      * <p>
248      * Retrieve the identified <code>int</code> value from the <code>JobDataMap</code>.
249      * </p>
250      *
251      * @throws ClassCastException
252      * if the identified object is not a String.
253      */

254     public int getIntFromString(String JavaDoc key) {
255         Object JavaDoc obj = get(key);
256
257         return new Integer JavaDoc((String JavaDoc) obj).intValue();
258     }
259
260     /**
261      * <p>
262      * Retrieve the identified <code>int</code> value from the <code>JobDataMap</code>.
263      * </p>
264      *
265      * @throws ClassCastException
266      * if the identified object is not a String or Integeger.
267      */

268     public long getIntValue(String JavaDoc key) {
269         Object JavaDoc obj = get(key);
270
271         if(obj instanceof String JavaDoc) {
272             return getIntFromString(key);
273         } else {
274             return getInt(key);
275         }
276     }
277     
278     /**
279      * <p>
280      * Retrieve the identified <code>int</code> value from the <code>JobDataMap</code>.
281      * </p>
282      *
283      * @throws ClassCastException
284      * if the identified object is not a String.
285      */

286     public Integer JavaDoc getIntegerFromString(String JavaDoc key) {
287         Object JavaDoc obj = get(key);
288
289         return new Integer JavaDoc((String JavaDoc) obj);
290     }
291
292     /**
293      * <p>
294      * Retrieve the identified <code>boolean</code> value from the <code>JobDataMap</code>.
295      * </p>
296      *
297      * @throws ClassCastException
298      * if the identified object is not a String.
299      */

300     public boolean getBooleanValueFromString(String JavaDoc key) {
301         Object JavaDoc obj = get(key);
302
303         return new Boolean JavaDoc((String JavaDoc) obj).booleanValue();
304     }
305
306     /**
307      * <p>
308      * Retrieve the identified <code>boolean</code> value from the
309      * <code>JobDataMap</code>.
310      * </p>
311      *
312      * @throws ClassCastException
313      * if the identified object is not a String or Boolean.
314      */

315     public boolean getBooleanValue(String JavaDoc key) {
316         Object JavaDoc obj = get(key);
317
318         if(obj instanceof String JavaDoc) {
319             return getBooleanValueFromString(key);
320         } else {
321             return getBoolean(key);
322         }
323     }
324
325     /**
326      * <p>
327      * Retrieve the identified <code>Boolean</code> value from the <code>JobDataMap</code>.
328      * </p>
329      *
330      * @throws ClassCastException
331      * if the identified object is not a String.
332      */

333     public Boolean JavaDoc getBooleanFromString(String JavaDoc key) {
334         Object JavaDoc obj = get(key);
335
336         return new Boolean JavaDoc((String JavaDoc) obj);
337     }
338
339     /**
340      * <p>
341      * Retrieve the identified <code>char</code> value from the <code>JobDataMap</code>.
342      * </p>
343      *
344      * @throws ClassCastException
345      * if the identified object is not a String.
346      */

347     public char getCharFromString(String JavaDoc key) {
348         Object JavaDoc obj = get(key);
349
350         return ((String JavaDoc) obj).charAt(0);
351     }
352
353     /**
354      * <p>
355      * Retrieve the identified <code>Character</code> value from the <code>JobDataMap</code>.
356      * </p>
357      *
358      * @throws ClassCastException
359      * if the identified object is not a String.
360      */

361     public Character JavaDoc getCharacterFromString(String JavaDoc key) {
362         Object JavaDoc obj = get(key);
363
364         return new Character JavaDoc(((String JavaDoc) obj).charAt(0));
365     }
366
367     /**
368      * <p>
369      * Retrieve the identified <code>double</code> value from the <code>JobDataMap</code>.
370      * </p>
371      *
372      * @throws ClassCastException
373      * if the identified object is not a String.
374      */

375     public double getDoubleValueFromString(String JavaDoc key) {
376         Object JavaDoc obj = get(key);
377
378         return new Double JavaDoc((String JavaDoc) obj).doubleValue();
379     }
380
381     /**
382      * <p>
383      * Retrieve the identified <code>double</code> value from the <code>JobDataMap</code>.
384      * </p>
385      *
386      * @throws ClassCastException
387      * if the identified object is not a String or Double.
388      */

389     public double getDoubleValue(String JavaDoc key) {
390         Object JavaDoc obj = get(key);
391
392         if(obj instanceof String JavaDoc) {
393             return getDoubleValueFromString(key);
394         } else {
395             return getDouble(key);
396         }
397     }
398
399     /**
400      * <p>
401      * Retrieve the identified <code>Double</code> value from the <code>JobDataMap</code>.
402      * </p>
403      *
404      * @throws ClassCastException
405      * if the identified object is not a String.
406      */

407     public Double JavaDoc getDoubleFromString(String JavaDoc key) {
408         Object JavaDoc obj = get(key);
409
410         return new Double JavaDoc((String JavaDoc) obj);
411     }
412
413     /**
414      * <p>
415      * Retrieve the identified <code>float</code> value from the <code>JobDataMap</code>.
416      * </p>
417      *
418      * @throws ClassCastException
419      * if the identified object is not a String.
420      */

421     public float getFloatValueFromString(String JavaDoc key) {
422         Object JavaDoc obj = get(key);
423
424         return new Float JavaDoc((String JavaDoc) obj).floatValue();
425     }
426
427     /**
428      * <p>
429      * Retrieve the identified <code>float</code> value from the <code>JobDataMap</code>.
430      * </p>
431      *
432      * @throws ClassCastException
433      * if the identified object is not a String or Float.
434      */

435     public float getFloatValue(String JavaDoc key) {
436         Object JavaDoc obj = get(key);
437
438         if(obj instanceof String JavaDoc) {
439             return getFloatValueFromString(key);
440         } else {
441             return getFloat(key);
442         }
443     }
444     
445     /**
446      * <p>
447      * Retrieve the identified <code>Float</code> value from the <code>JobDataMap</code>.
448      * </p>
449      *
450      * @throws ClassCastException
451      * if the identified object is not a String.
452      */

453     public Float JavaDoc getFloatFromString(String JavaDoc key) {
454         Object JavaDoc obj = get(key);
455
456         return new Float JavaDoc((String JavaDoc) obj);
457     }
458
459     /**
460      * <p>
461      * Retrieve the identified <code>long</code> value from the <code>JobDataMap</code>.
462      * </p>
463      *
464      * @throws ClassCastException
465      * if the identified object is not a String.
466      */

467     public long getLongValueFromString(String JavaDoc key) {
468         Object JavaDoc obj = get(key);
469
470         return new Long JavaDoc((String JavaDoc) obj).longValue();
471     }
472
473     /**
474      * <p>
475      * Retrieve the identified <code>long</code> value from the <code>JobDataMap</code>.
476      * </p>
477      *
478      * @throws ClassCastException
479      * if the identified object is not a String or Long.
480      */

481     public long getLongValue(String JavaDoc key) {
482         Object JavaDoc obj = get(key);
483
484         if(obj instanceof String JavaDoc) {
485             return getLongValueFromString(key);
486         } else {
487             return getLong(key);
488         }
489     }
490     
491     /**
492      * <p>
493      * Retrieve the identified <code>Long</code> value from the <code>JobDataMap</code>.
494      * </p>
495      *
496      * @throws ClassCastException
497      * if the identified object is not a String.
498      */

499     public Long JavaDoc getLongFromString(String JavaDoc key) {
500         Object JavaDoc obj = get(key);
501
502         return new Long JavaDoc((String JavaDoc) obj);
503     }
504 }
505
Popular Tags