Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
LatkaEventPublisher |
|
| 1.7777777777777777;1.778 |
1 | /* | |
2 | * Copyright 1999-2001,2004 The Apache Software Foundation. | |
3 | * | |
4 | * Licensed under the Apache License, Version 2.0 (the "License"); | |
5 | * you may not use this file except in compliance with the License. | |
6 | * You may obtain a copy of the License at | |
7 | * | |
8 | * http://www.apache.org/licenses/LICENSE-2.0 | |
9 | * | |
10 | * Unless required by applicable law or agreed to in writing, software | |
11 | * distributed under the License is distributed on an "AS IS" BASIS, | |
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
13 | * See the License for the specific language governing permissions and | |
14 | * limitations under the License. | |
15 | */ | |
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 | /** | |
24 | * A {@link LatkaEventListener} that publishes the incoming events to other | |
25 | * listeners | |
26 | * | |
27 | * @author Morgan Delagrange | |
28 | * @author <a href="mailto:dion@multitask.com.au">dIon Gillard</a> | |
29 | * @version | |
30 | * $Id: LatkaEventPublisher.java 155424 2005-02-26 13:09:29Z dirkv $ | |
31 | */ | |
32 | 0 | public class LatkaEventPublisher implements LatkaEventListener { |
33 | ||
34 | /** the listeners to publish events to */ | |
35 | 0 | protected List _list = new ArrayList(); |
36 | ||
37 | /** | |
38 | * add a {@link LatkaEventListener} to the list of publishees. | |
39 | * @param listener a {@link LatkaEventListener} | |
40 | */ | |
41 | public void addListener(LatkaEventListener listener) { | |
42 | 0 | _list.add(listener); |
43 | 0 | } |
44 | ||
45 | /** | |
46 | * Send the provided event object to all registered listeners | |
47 | * @param event an event to be sent | |
48 | */ | |
49 | public void broadcastEvent(LatkaEvent event) { | |
50 | 0 | Iterator iter = _list.iterator(); |
51 | 0 | while (iter.hasNext()) { |
52 | 0 | broadcastEvent(event, (LatkaEventListener) iter.next()); |
53 | } | |
54 | 0 | } |
55 | ||
56 | /** | |
57 | * Send the provided event to the provided listener | |
58 | * @param event an event to be sent | |
59 | * @param listener the listener to send it to | |
60 | */ | |
61 | protected void broadcastEvent(LatkaEvent event, LatkaEventListener listener) | |
62 | { | |
63 | 0 | if (event instanceof RequestSucceededEvent) { |
64 | 0 | listener.requestSucceeded((RequestEvent) event); |
65 | 0 | } else if (event instanceof RequestFailedEvent) { |
66 | 0 | listener.requestFailed((RequestEvent) event); |
67 | 0 | } else if (event instanceof RequestSkippedEvent) { |
68 | 0 | listener.requestSkipped((RequestEvent) event); |
69 | 0 | } else if (event instanceof RequestErrorEvent) { |
70 | 0 | listener.requestError((RequestEvent) event); |
71 | 0 | } else if (event instanceof SuiteCompletedEvent) { |
72 | 0 | listener.suiteCompleted((SuiteEvent) event); |
73 | 0 | } else if (event instanceof ReportMessageEvent) { |
74 | 0 | listener.reportMessage((ReportMessageEvent) event); |
75 | } | |
76 | 0 | } |
77 | ||
78 | /** | |
79 | * send the supplied event to all listeners | |
80 | * @param event an event to be broadcast | |
81 | */ | |
82 | public void requestSucceeded(RequestEvent event) { | |
83 | 0 | broadcastEvent(event); |
84 | 0 | } |
85 | ||
86 | /** | |
87 | * send the supplied event to all listeners | |
88 | * @param event an event to be broadcast | |
89 | */ | |
90 | public void requestFailed(RequestEvent event) { | |
91 | 0 | broadcastEvent(event); |
92 | 0 | } |
93 | ||
94 | /** | |
95 | * send the supplied event to all listeners | |
96 | * @param event an event to be broadcast | |
97 | */ | |
98 | public void requestSkipped(RequestEvent event) { | |
99 | 0 | broadcastEvent(event); |
100 | 0 | } |
101 | ||
102 | /** | |
103 | * send the supplied event to all listeners | |
104 | * @param event an event to be broadcast | |
105 | */ | |
106 | public void requestError(RequestEvent event) { | |
107 | 0 | broadcastEvent(event); |
108 | 0 | } |
109 | ||
110 | /** | |
111 | * send the supplied event to all listeners | |
112 | * @param event a message event to be broadcast | |
113 | */ | |
114 | public void reportMessage(ReportMessageEvent event) { | |
115 | 0 | broadcastEvent(event); |
116 | 0 | } |
117 | ||
118 | /** | |
119 | * send the supplied event to all listeners | |
120 | * @param event an event to be broadcast | |
121 | */ | |
122 | public void suiteCompleted(SuiteEvent event) { | |
123 | 0 | broadcastEvent(event); |
124 | 0 | } |
125 | ||
126 | } |