KickJava   Java API By Example, From Geeks To Geeks.

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


1 package org.oddjob.state;
2
3 import java.util.Date JavaDoc;
4
5 import org.oddjob.Stateful;
6
7
8 /**
9  * An implementation of a JobStateListener designer to be overriden.
10  *
11  * @author Rob Gordon
12  */

13
14 abstract public class AbstractJobStateListener implements JobStateListener {
15
16     /**
17      * This is the catch all method that all other methods call if they
18      * haven't been overridden.
19      *
20      * @param event The state event.
21      */

22     public final void jobStateChange(JobStateEvent event) {
23         JobState state = event.getJobState();
24         Stateful source = (Stateful)event.getSource();
25         Date JavaDoc time = event.getTime();
26         Throwable JavaDoc throwable = event.getException();
27         if (state == JobState.READY) {
28             jobStateReady(source, time);
29         }
30         else if (state == JobState.EXECUTING) {
31             jobStateExecuting(source, time);
32         }
33         else if (state == JobState.COMPLETE) {
34             jobStateComplete(source, time);
35             hasFinishedRunning(event);
36         }
37         else if (state == JobState.NOT_COMPLETE) {
38             jobStateNotComplete(source, time);
39             hasFinishedRunning(event);
40         }
41         else if (state == JobState.EXCEPTION) {
42             jobStateException(source, time, throwable);
43             hasFinishedRunning(event);
44         }
45         else {
46             throw new IllegalStateException JavaDoc("Unknown state! - this should never happen.");
47         }
48     }
49
50     protected void jobStateReady(Stateful source, Date JavaDoc time) {
51     }
52     
53     protected void jobStateExecuting(Stateful source, Date JavaDoc time) {
54     }
55     
56     protected void jobStateComplete(Stateful source, Date JavaDoc time) {
57     }
58     
59     protected void jobStateNotComplete(Stateful source, Date JavaDoc time) {
60     }
61     
62     protected void jobStateException(Stateful source, Date JavaDoc time, Throwable JavaDoc throwable) {
63     }
64     
65     protected void hasFinishedRunning(JobStateEvent e) {
66     }
67 }
68
Popular Tags