1 23 24 package org.apache.slide.event; 25 26 import java.util.*; 27 28 33 public class EventCollection extends EventObject { 34 List collection = new ArrayList(); 35 36 public final static Collected COLLECTED = new Collected(); 37 public final static VetoableCollected VETOABLE_COLLECTED = new VetoableCollected(); 38 39 public final static String GROUP = "event-collection"; 40 public final static AbstractEventMethod[] methods = new AbstractEventMethod[] { COLLECTED, VETOABLE_COLLECTED }; 41 42 public EventCollection(Object source) { 43 super(source); 44 } 45 46 public void addEvent(AbstractEventMethod method, EventObject event) { 47 synchronized ( collection ) { 48 collection.add(new Event(method, event)); 49 } 50 } 51 52 public List getCollection() { 53 return collection; 54 } 55 56 public String toString() { 57 String NEWLINE = System.getProperty("line.separator"); 58 StringBuffer buffer = new StringBuffer (256); 59 buffer.append(getClass().getName()).append("[collected events="); 60 synchronized ( collection ) { 61 for ( Iterator i = collection.iterator(); i.hasNext(); ) { 62 buffer.append(NEWLINE); 63 Event event = (Event)i.next(); 64 if ( event.getEvent() instanceof RemoteInformation ) { 65 StringBuffer infoBuffer = new StringBuffer (); 66 String [][] information = ((RemoteInformation)event.getEvent()).getInformation(); 67 boolean first = true; 68 for ( int j = 0; j < information.length; j++ ) { 69 if ( !first ) infoBuffer.append(", "); 70 first = false; 71 infoBuffer.append(information[j][0]).append("=").append(information[j][1]); 72 } 73 buffer.append("["+event.getClass().getName()+" [name="+event.getMethod().getId()+", information: "+infoBuffer.toString()+"]]"); 74 } else { 75 buffer.append("["+event.getClass().getName()+" [name="+event.getMethod().getId()+"]]"); 76 } 77 } 78 } 79 buffer.append("]"); 80 return buffer.toString(); 81 } 82 83 public static class Collected extends EventMethod { 84 public Collected() { 85 super(GROUP, "collected"); 86 } 87 88 public void fireEvent(EventListener listener, EventObject event) { 89 if (listener instanceof EventCollectionListener ) { 90 ((EventCollectionListener)listener).collected((EventCollection)event); 91 } 92 } 93 } 94 95 public static class VetoableCollected extends VetoableEventMethod { 96 public VetoableCollected() { 97 super(GROUP, "vetoable-collected"); 98 } 99 100 public void fireVetaoableEvent(EventListener listener, EventObject event) throws VetoException { 101 if (listener instanceof EventCollectionListener ) { 102 ((EventCollectionListener)listener).vetoableCollected((EventCollection)event); 103 } 104 } 105 } 106 107 public class Event { 108 private AbstractEventMethod method; 109 private EventObject event; 110 111 public Event(AbstractEventMethod method, EventObject event) { 112 this.method = method; 113 this.event = event; 114 } 115 116 public AbstractEventMethod getMethod() { 117 return method; 118 } 119 120 public EventObject getEvent() { 121 return event; 122 } 123 } 124 } | Popular Tags |