1 6 7 package org.netbeans.mdr.test; 8 9 14 import java.net.URL ; 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 ; 22 import java.io.PrintStream ; 23 24 import junit.extensions.*; 25 import junit.framework.*; 26 27 31 public class MDRAttributePreListener extends TestCase implements MDRPreChangeListener { 32 33 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 protected java.util.LinkedList eventsQueue = new java.util.LinkedList (); 42 43 44 public MDRAttributePreListener(String 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) || e.isOfType(AttributeEvent.EVENTMASK_CLASSATTR)) { 73 74 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 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 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 |