KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > hudson > model > Actionable


1 package hudson.model;
2
3 import org.kohsuke.stapler.StaplerRequest;
4 import org.kohsuke.stapler.StaplerResponse;
5
6 import java.util.List JavaDoc;
7 import java.util.Vector JavaDoc;
8
9 /**
10  * {@link ModelObject} that can have additional {@link Action}s.
11  *
12  * @author Kohsuke Kawaguchi
13  */

14 public abstract class Actionable extends AbstractModelObject {
15     /**
16      * Actions contributed to this model object.
17      */

18     private List JavaDoc<Action> actions;
19
20     /**
21      * Gets actions contributed to this build.
22      *
23      * <p>
24      * A new {@link Action} can be added by {@code getActions().add(...)}.
25      *
26      * @return
27      * may be empty but never null.
28      */

29     public synchronized List JavaDoc<Action> getActions() {
30         if(actions==null)
31             actions = new Vector JavaDoc<Action>();
32         return actions;
33     }
34
35     public Action getAction(int index) {
36         if(actions==null) return null;
37         return actions.get(index);
38     }
39
40     public <T extends Action> T getAction(Class JavaDoc<T> type) {
41         for (Action a : getActions())
42             if (type.isInstance(a))
43                 return type.cast(a);
44         return null;
45     }
46
47     public Object JavaDoc getDynamic(String JavaDoc token, StaplerRequest req, StaplerResponse rsp) {
48         for (Action a : getActions()) {
49             if(a.getUrlName().equals(token))
50                 return a;
51         }
52         return null;
53     }
54 }
55
Popular Tags