KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > kilim > description > Trigger


1 package org.objectweb.kilim.description;
2
3 import java.util.ArrayList JavaDoc;
4 import java.util.List JavaDoc;
5 import java.util.Iterator JavaDoc;
6
7 import org.objectweb.kilim.KilimException;
8
9 /**
10  * @author horn
11  */

12
13 public abstract class Trigger extends TemplateElementImpl {
14     /** strings to be used to print event idents */
15     public static final String JavaDoc[] EVENT_TYPE_NAME = { "Unbind" , "Bind"};
16     
17     /** integer constants used to identify bind events */
18     public static final int BIND = 1;
19     /** integer constants used to identify unbind events */
20     public static final int UNBIND = 2;
21     
22     private String JavaDoc sourceName;
23     private int kind;
24     private List JavaDoc transformers;
25         
26     protected Trigger(String JavaDoc aName, int aKind) {
27         sourceName = aName;
28         kind = aKind;
29     }
30         
31     /**
32      * returns the kind of the trigger event. It is one of TRIGGER.BIND or' TRIGGER.UNBIND.
33      * @return int
34      */

35     public int getEventKind() {
36         return kind;
37     }
38     
39     /**
40      * @see org.objectweb.kilim.description.Trigger#getName()
41      */

42     public String JavaDoc getSourceName() {
43         return sourceName;
44     }
45         
46     /**
47      * @see org.objectweb.kilim.description.Trigger#getName()
48      */

49     public void setSourceName(String JavaDoc aName) {
50         sourceName = aName;
51     }
52
53     /**
54      * @see org.objectweb.kilim.description.Trigger#addTransformer(Transformer)
55      */

56     public void addTransformer(BasicElement aTransformer) throws KilimException {
57         if (aTransformer == null) {
58             throw new KilimException("illegal null value for transformer when added to a trigger in template " + getContainingTemplate().getName());
59         }
60         
61         if (!aTransformer.performsAction()) {
62             //throw new KilimException("attempt to add a non transformer to a trigger");
63
}
64         
65         String JavaDoc name = null;
66         
67         if (transformers == null) {
68             transformers = new ArrayList JavaDoc();
69         }
70
71         if (transformers.contains(aTransformer)) {
72                 throw new KilimException("attempt to add an already defined transformer in a trigger in template " + getContainingTemplate().getName());
73         }
74         transformers.add(aTransformer);
75     }
76     
77     /**
78      * @see org.objectweb.kilim.description.Trigger#removeTransformer(String)
79      */

80     public void removeTransformer(BasicElement aTransformer) throws KilimException {
81         if (aTransformer == null) {
82             throw new KilimException("illegal null value for transformer when removed to a trigger in template " + getContainingTemplate().getName());
83         }
84         
85         if (!aTransformer.performsAction()) {
86             throw new KilimException("attempt to remove a non transformer from a trigger in template " + getContainingTemplate().getName());
87         }
88         
89         if (transformers == null) {
90             throw new KilimException("attempt to remove a transformer from an empty trigger in template " + getContainingTemplate().getName());
91         }
92
93         transformers.remove(aTransformer);
94     }
95         
96     /**
97      * @see org.objectweb.kilim.description.Trigger#getTransformers()
98      */

99     public Iterator JavaDoc getTransformers() {
100         if (transformers == null) {
101             return KILIM.EMPTY_ITERATOR;
102         }
103         return transformers.iterator();
104     }
105 }
Popular Tags