1 16 17 package org.apache.commons.latka.event; 18 19 import java.util.ArrayList ; 20 import java.util.Iterator ; 21 import java.util.List ; 22 23 32 public class LatkaEventPublisher implements LatkaEventListener { 33 34 35 protected List _list = new ArrayList (); 36 37 41 public void addListener(LatkaEventListener listener) { 42 _list.add(listener); 43 } 44 45 49 public void broadcastEvent(LatkaEvent event) { 50 Iterator iter = _list.iterator(); 51 while (iter.hasNext()) { 52 broadcastEvent(event, (LatkaEventListener) iter.next()); 53 } 54 } 55 56 61 protected void broadcastEvent(LatkaEvent event, LatkaEventListener listener) 62 { 63 if (event instanceof RequestSucceededEvent) { 64 listener.requestSucceeded((RequestEvent) event); 65 } else if (event instanceof RequestFailedEvent) { 66 listener.requestFailed((RequestEvent) event); 67 } else if (event instanceof RequestSkippedEvent) { 68 listener.requestSkipped((RequestEvent) event); 69 } else if (event instanceof RequestErrorEvent) { 70 listener.requestError((RequestEvent) event); 71 } else if (event instanceof SuiteCompletedEvent) { 72 listener.suiteCompleted((SuiteEvent) event); 73 } else if (event instanceof ReportMessageEvent) { 74 listener.reportMessage((ReportMessageEvent) event); 75 } 76 } 77 78 82 public void requestSucceeded(RequestEvent event) { 83 broadcastEvent(event); 84 } 85 86 90 public void requestFailed(RequestEvent event) { 91 broadcastEvent(event); 92 } 93 94 98 public void requestSkipped(RequestEvent event) { 99 broadcastEvent(event); 100 } 101 102 106 public void requestError(RequestEvent event) { 107 broadcastEvent(event); 108 } 109 110 114 public void reportMessage(ReportMessageEvent event) { 115 broadcastEvent(event); 116 } 117 118 122 public void suiteCompleted(SuiteEvent event) { 123 broadcastEvent(event); 124 } 125 126 } 127 | Popular Tags |