KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > oddjob > state > JobState


1 package org.oddjob.state;
2
3 import java.io.ObjectStreamException JavaDoc;
4 import java.io.Serializable JavaDoc;
5
6
7 /**
8  * Encapsulate the allowed states for a job.
9  *
10  * @author Rob Gordon
11  */

12
13 public class JobState implements Serializable JavaDoc {
14     private static final long serialVersionUID = 20050926;
15     
16     /**
17      * Indicates the job is ready to be executing. The Oddjob Framework
18      * will only execute a job which is in this state.
19      */

20     public final static JobState READY = new JobState("READY");
21
22     /**
23      * Indicates the job is executing.
24      */

25     public final static JobState EXECUTING = new JobState("EXECUTING");
26
27     /**
28      * Indicates job has completed.
29      */

30     public final static JobState COMPLETE = new JobState("COMPLETE");
31     
32     /**
33      * Indicates the job is not complete. Typically this is not unexpected,
34      * for instance a job which looks for a file, and a
35      * parent job will re-execute the job again at a later date.
36      */

37     public final static JobState NOT_COMPLETE = new JobState("NOT COMPLETE");
38         
39     /**
40      * Indicates an exception has occured. This is generally
41      * recoverable. Such as database failure, disk full etc.
42      */

43     public final static JobState EXCEPTION = new JobState("EXCEPTION");
44
45     /**
46      * Text to hold the name of the state.
47      */

48     private final String JavaDoc text;
49
50     private static int nextOrdinal = 0;
51     
52     private final int ordinal = nextOrdinal++;
53
54     private static final JobState[] allValues = {
55         READY, EXECUTING,
56         COMPLETE, NOT_COMPLETE,
57         EXCEPTION };
58     
59     /**
60      * Private Constructor.
61      *
62      * @param text the name of the state.
63      */

64     
65     private JobState(String JavaDoc text) {
66         
67         this.text = text;
68     }
69     
70     /**
71      * Return a meaningful description for the state.
72      */

73                 
74     public String JavaDoc toString() {
75         
76         return text;
77     }
78     
79     private Object JavaDoc readResolve() throws ObjectStreamException JavaDoc {
80         
81         return allValues[ordinal];
82     }
83     
84     /**
85      * Utility function to convert a state text to to the JobState.
86      *
87      * @param state Case insesitive text.
88      * @return The corresponding jobState or null if it's invalid.
89      */

90     public static JobState stateFor(String JavaDoc state) {
91         state = state.toUpperCase();
92         for (int i = 0; i < allValues.length; ++i) {
93             if (allValues[i].text.equals(state)) {
94                 return allValues[i];
95             }
96         }
97         return null;
98     }
99 }
100
101
Popular Tags