KickJava   Java API By Example, From Geeks To Geeks.

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


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

6
7 package org.netbeans.mdr.test;
8
9 //import java.io.File;
10
//import java.io.FileNotFoundException;
11
//import java.io.FileOutputStream;
12
//import java.io.PrintWriter;
13

14 import java.net.URL JavaDoc;
15
16 import org.netbeans.api.mdr.events.*;
17
18 import javax.jmi.reflect.*;
19 import javax.jmi.model.*;
20
21 import java.io.PrintWriter JavaDoc;
22 import java.io.PrintStream JavaDoc;
23
24 import junit.extensions.*;
25 import junit.framework.*;
26
27 /**
28  *
29  * @author mk97936
30  */

31 public class MDRAttributePreListener extends TestCase implements MDRPreChangeListener {
32     
33     // "type" of event
34
public static final int PLANNED = 0;
35     public static final int CHANGED = 1;
36     public static final int CANCELED = 2;
37     
38     private EventsList eventsList;
39     
40     // queue to test right order of events
41
protected java.util.LinkedList JavaDoc eventsQueue = new java.util.LinkedList JavaDoc();
42     
43     /** Creates a new instance of MDRListener */
44     public MDRAttributePreListener(String JavaDoc testName) {
45         super(testName);
46     }
47     
48     public void setRef(EventsList el) {
49         eventsList = el;
50     }
51
52     public void change(MDRChangeEvent e) {
53         assertEquals("Wrong order of events!", eventsQueue.getFirst(), e);
54         eventsQueue.removeFirst();
55         processEvent(e, CHANGED);
56     }
57     
58     public void changeCancelled(MDRChangeEvent e) {
59         assertEquals("Wrong order of events!", eventsQueue.getFirst(), e);
60         eventsQueue.removeFirst();
61         processEvent(e, CANCELED);
62     }
63     
64     public void plannedChange(MDRChangeEvent e) {
65         eventsQueue.add(e);
66         processEvent(e, PLANNED);
67     }
68     
69     private void processEvent(MDRChangeEvent e, int type) {
70         
71         if (e.isOfType(AttributeEvent.EVENTMASK_ATTRIBUTE) || // AttributeEvent
72
e.isOfType(AttributeEvent.EVENTMASK_CLASSATTR)) {
73             
74             // EVENT_ATTRIBUTE_ADD
75
if (e.isOfType(AttributeEvent.EVENT_ATTRIBUTE_ADD) && (type == PLANNED)) {
76                 eventsList.addEvent(((ModelElement) ((RefBaseObject)((AttributeEvent) e).getSource()).refMetaObject()).getName(),
77                                     e, System.currentTimeMillis(), EventsList._ADD | EventsList._PLANNED);
78             } else if (e.isOfType(AttributeEvent.EVENT_ATTRIBUTE_ADD) && (type == CHANGED)) {
79                 eventsList.addEvent(((ModelElement) ((RefBaseObject)((AttributeEvent) e).getSource()).refMetaObject()).getName(),
80                                     e, System.currentTimeMillis(), EventsList._ADD | EventsList._CHANGED);
81             } else if (e.isOfType(AttributeEvent.EVENT_ATTRIBUTE_ADD) && (type == CANCELED)) {
82                 eventsList.addEvent(((ModelElement) ((RefBaseObject)((AttributeEvent) e).getSource()).refMetaObject()).getName(),
83                                     e, System.currentTimeMillis(), EventsList._ADD | EventsList._CANCELED);
84             }
85             // EVENT_ATTRIBUTE_SET
86
else if (e.isOfType(AttributeEvent.EVENT_ATTRIBUTE_SET) && (type == PLANNED)) {
87                 eventsList.addEvent(((ModelElement) ((RefBaseObject)((AttributeEvent) e).getSource()).refMetaObject()).getName(),
88                                     e, System.currentTimeMillis(), EventsList._SET | EventsList._PLANNED);
89             } else if (e.isOfType(AttributeEvent.EVENT_ATTRIBUTE_SET) && (type == CHANGED)) {
90                 eventsList.addEvent(((ModelElement) ((RefBaseObject)((AttributeEvent) e).getSource()).refMetaObject()).getName(),
91                                     e, System.currentTimeMillis(), EventsList._SET | EventsList._CHANGED);
92             } else if (e.isOfType(AttributeEvent.EVENT_ATTRIBUTE_SET) && (type == CANCELED)) {
93                 eventsList.addEvent(((ModelElement) ((RefBaseObject)((AttributeEvent) e).getSource()).refMetaObject()).getName(),
94                                     e, System.currentTimeMillis(), EventsList._SET | EventsList._CANCELED);
95             }
96             // EVENT_ATTRIBUTE_REMOVE
97
else if (e.isOfType(AttributeEvent.EVENT_ATTRIBUTE_REMOVE) && (type == PLANNED)) {
98                 eventsList.addEvent(((ModelElement) ((RefBaseObject)((AttributeEvent) e).getSource()).refMetaObject()).getName(),
99                                     e, System.currentTimeMillis(), EventsList._REMOVE | EventsList._PLANNED);
100             } else if (e.isOfType(AttributeEvent.EVENT_ATTRIBUTE_REMOVE) && (type == CHANGED)) {
101                 eventsList.addEvent(((ModelElement) ((RefBaseObject)((AttributeEvent) e).getSource()).refMetaObject()).getName(),
102                                     e, System.currentTimeMillis(), EventsList._REMOVE | EventsList._CHANGED);
103             } else if (e.isOfType(AttributeEvent.EVENT_ATTRIBUTE_REMOVE) && (type == CANCELED)) {
104                 eventsList.addEvent(((ModelElement) ((RefBaseObject)((AttributeEvent) e).getSource()).refMetaObject()).getName(),
105                                     e, System.currentTimeMillis(), EventsList._REMOVE | EventsList._CANCELED);
106             }
107                        
108         }
109         
110     }
111     
112 }
113
Popular Tags