KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > mdr > test > MDRAttributeListener


1 /*
2  * MDRListener.java
3  *
4  * Created on 8. duben 2002, 10:55
5  */

6
7 package org.netbeans.mdr.test;
8
9 import org.netbeans.api.mdr.events.*;
10
11 import javax.jmi.reflect.*;
12 import javax.jmi.model.*;
13
14 //import java.io.PrintWriter;
15
//import java.io.PrintStream;
16

17
18 /**
19  *
20  * @author mk97936
21  */

22 public class MDRAttributeListener implements MDRChangeListener {
23     
24     // "type" of event
25
public static final int PLANNED = 0;
26     public static final int CHANGED = 1;
27     public static final int CANCELED = 2;
28     
29     //private PrintStream goldenRef = null;
30
private EventsList eventsList;
31         
32     /** Creates a new instance of MDRListener */
33     public MDRAttributeListener() {
34     }
35     
36     public void setRef(EventsList el) {
37         eventsList = el;
38     }
39
40     public void change(MDRChangeEvent e) {
41         processEvent(e, CHANGED);
42     }
43
44     private void processEvent(MDRChangeEvent e, int type) {
45         
46        if (e.isOfType(AttributeEvent.EVENTMASK_ATTRIBUTE) || // AttributeEvent
47
e.isOfType(AttributeEvent.EVENTMASK_CLASSATTR)) {
48             
49             // EVENT_ATTRIBUTE_ADD
50
if (e.isOfType(AttributeEvent.EVENT_ATTRIBUTE_ADD) && (type == PLANNED)) {
51                 eventsList.addEvent(((ModelElement) ((RefBaseObject)((AttributeEvent) e).getSource()).refMetaObject()).getName(),
52                                     e, System.currentTimeMillis(), EventsList._ADD | EventsList._PLANNED);
53             } else if (e.isOfType(AttributeEvent.EVENT_ATTRIBUTE_ADD) && (type == CHANGED)) {
54                 eventsList.addEvent(((ModelElement) ((RefBaseObject)((AttributeEvent) e).getSource()).refMetaObject()).getName(),
55                                     e, System.currentTimeMillis(), EventsList._ADD | EventsList._CHANGED);
56             } else if (e.isOfType(AttributeEvent.EVENT_ATTRIBUTE_ADD) && (type == CANCELED)) {
57                 eventsList.addEvent(((ModelElement) ((RefBaseObject)((AttributeEvent) e).getSource()).refMetaObject()).getName(),
58                                     e, System.currentTimeMillis(), EventsList._ADD | EventsList._CANCELED);
59             }
60             // EVENT_ATTRIBUTE_SET
61
else if (e.isOfType(AttributeEvent.EVENT_ATTRIBUTE_SET) && (type == PLANNED)) {
62                 eventsList.addEvent(((ModelElement) ((RefBaseObject)((AttributeEvent) e).getSource()).refMetaObject()).getName(),
63                                     e, System.currentTimeMillis(), EventsList._SET | EventsList._PLANNED);
64             } else if (e.isOfType(AttributeEvent.EVENT_ATTRIBUTE_SET) && (type == CHANGED)) {
65                 eventsList.addEvent(((ModelElement) ((RefBaseObject)((AttributeEvent) e).getSource()).refMetaObject()).getName(),
66                                     e, System.currentTimeMillis(), EventsList._SET | EventsList._CHANGED);
67             } else if (e.isOfType(AttributeEvent.EVENT_ATTRIBUTE_SET) && (type == CANCELED)) {
68                 eventsList.addEvent(((ModelElement) ((RefBaseObject)((AttributeEvent) e).getSource()).refMetaObject()).getName(),
69                                     e, System.currentTimeMillis(), EventsList._SET | EventsList._CANCELED);
70             }
71             // EVENT_ATTRIBUTE_REMOVE
72
else if (e.isOfType(AttributeEvent.EVENT_ATTRIBUTE_REMOVE) && (type == PLANNED)) {
73                 eventsList.addEvent(((ModelElement) ((RefBaseObject)((AttributeEvent) e).getSource()).refMetaObject()).getName(),
74                                     e, System.currentTimeMillis(), EventsList._REMOVE | EventsList._PLANNED);
75             } else if (e.isOfType(AttributeEvent.EVENT_ATTRIBUTE_REMOVE) && (type == CHANGED)) {
76                 eventsList.addEvent(((ModelElement) ((RefBaseObject)((AttributeEvent) e).getSource()).refMetaObject()).getName(),
77                                     e, System.currentTimeMillis(), EventsList._REMOVE | EventsList._CHANGED);
78             } else if (e.isOfType(AttributeEvent.EVENT_ATTRIBUTE_REMOVE) && (type == CANCELED)) {
79                 eventsList.addEvent(((ModelElement) ((RefBaseObject)((AttributeEvent) e).getSource()).refMetaObject()).getName(),
80                                     e, System.currentTimeMillis(), EventsList._REMOVE | EventsList._CANCELED);
81             }
82                        
83         }
84         
85     }
86     
87 }
88
Popular Tags