KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > hudson > model > listeners > JobListener


1 package hudson.model.listeners;
2
3 import hudson.model.Hudson;
4 import hudson.model.Job;
5 import hudson.model.Item;
6 import hudson.ExtensionPoint;
7
8 /**
9  * Receives notifications about jobs.
10  *
11  * <p>
12  * This is an abstract class so that methods added in the future won't break existing listeners.
13  *
14  * @author Kohsuke Kawaguchi
15  * @see Hudson#addListener(JobListener)
16  */

17 public abstract class JobListener implements ExtensionPoint {
18     /**
19      * Called after a new job is created and added to {@link Hudson}.
20      */

21     public void onCreated(Job j) {
22     }
23
24     /**
25      * Called after all the jobs are loaded from disk into {@link Hudson}
26      * object.
27      *
28      * @since 1.68
29      */

30     public void onLoaded() {
31     }
32
33     /**
34      * Called right before a job is going to be deleted.
35      *
36      * At this point the data files of the job is already gone.
37      */

38     public void onDeleted(Job j) {
39     }
40
41     public static final class JobListenerAdapter extends ItemListener {
42         private final JobListener listener;
43
44         public JobListenerAdapter(JobListener listener) {
45             this.listener = listener;
46         }
47
48         public void onCreated(Item item) {
49             if(item instanceof Job)
50                 listener.onCreated((Job)item);
51         }
52
53         public void onLoaded() {
54             listener.onLoaded();
55         }
56
57         public void onDeleted(Item item) {
58             if(item instanceof Job)
59                 listener.onDeleted((Job)item);
60         }
61
62         public boolean equals(Object JavaDoc o) {
63             if (this == o) return true;
64             if (o == null || getClass() != o.getClass()) return false;
65
66             JobListenerAdapter that = (JobListenerAdapter) o;
67
68             return this.listener.equals(that.listener);
69
70         }
71
72         public int hashCode() {
73             return listener.hashCode();
74         }
75     }
76 }
77
Popular Tags