1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.xnap.chat;
21
22 import java.util.List;
23 import java.util.Vector;
24
25 /***
26 * This is a utility class that can be used by {@link ChatProvider}
27 * classes for handling channel event listeners.
28 */
29 public class ChatProviderSupport {
30
31
32
33 private Object source;
34 private List listeners = new Vector();
35
36
37
38 /***
39 * Constructs a ChatProviderSupport object.
40 *
41 * @param source the object to be given as the source for any events
42 */
43 public ChatProviderSupport(Object source)
44 {
45 this.source = source;
46 }
47
48
49
50 public void addChatProviderListener(ChatProviderListener l)
51 {
52 listeners.add(l);
53 }
54
55 public void removeChatProviderListener(ChatProviderListener l)
56 {
57 listeners.remove(l);
58 }
59
60 public void fireMessageReceived(String message)
61 {
62 Object[] array = listeners.toArray();
63
64 if (array != null) {
65 ChatProviderEvent event
66 = new ChatProviderEvent(source, message);
67
68 for (int i = array.length - 1; i >= 0; i--) {
69 ((ChatProviderListener)array[i]).messageReceived(event);
70 }
71 }
72 }
73
74 public void fireChannelsUpdated()
75 {
76 Object[] array = listeners.toArray();
77
78 if (array != null) {
79 ChatProviderEvent event = new ChatProviderEvent(source);
80
81 for (int i = array.length - 1; i >= 0; i--) {
82 ((ChatProviderListener)array[i]).channelsUpdated(event);
83 }
84 }
85 }
86
87 }