1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/**
* $Revision$
* $Date$
*
* Copyright (C) 2005-2008 Jive Software. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jivesoftware.openfire.muc;
import org.xmpp.packet.JID;
import org.xmpp.packet.Message;
import java.util.Collection;
import java.util.concurrent.ConcurrentLinkedQueue;
/**
* Dispatches MUC events. The following events are supported:
* <ul>
* <li><b>occupantJoined</b> --> Someone joined a room.</li>
* <li><b>occupantLeft</b> --> Someone left a room.</li>
* <li><b>nicknameChanged</b> --> A nickname was changed in a room.</li>
* <li><b>messageReceived</b> --> A message was received in a room.</li>
* <li><b>roomCreated</b> --> A room was created.</li>
* <li><b>roomDestryod</b> --> A room was destroyed.</li>
* </ul>
* Use {@link #addListener(MUCEventListener)} and {@link #removeListener(MUCEventListener)}
* to add or remove {@link MUCEventListener}.
*
* @author Daniel Henninger
*/
public class MUCEventDispatcher {
private static Collection<MUCEventListener> listeners =
new ConcurrentLinkedQueue<MUCEventListener>();
public static void addListener(MUCEventListener listener) {
listeners.add(listener);
}
public static void removeListener(MUCEventListener listener) {
listeners.remove(listener);
}
public static void occupantJoined(JID roomJID, JID user, String nickname) {
for (MUCEventListener listener : listeners) {
listener.occupantJoined(roomJID, user, nickname);
}
}
public static void occupantLeft(JID roomJID, JID user) {
for (MUCEventListener listener : listeners) {
listener.occupantLeft(roomJID, user);
}
}
public static void nicknameChanged(JID roomJID, JID user, String oldNickname, String newNickname) {
for (MUCEventListener listener : listeners) {
listener.nicknameChanged(roomJID, user, oldNickname, newNickname);
}
}
public static void messageReceived(JID roomJID, JID user, String nickname, Message message) {
for (MUCEventListener listener : listeners) {
listener.messageReceived(roomJID, user, nickname, message);
}
}
public static void privateMessageRecieved(JID toJID, JID fromJID, Message message) {
for (MUCEventListener listener : listeners) {
listener.privateMessageRecieved(toJID, fromJID, message);
}
}
public static void roomCreated(JID roomJID) {
for (MUCEventListener listener : listeners) {
listener.roomCreated(roomJID);
}
}
public static void roomDestroyed(JID roomJID) {
for (MUCEventListener listener : listeners) {
listener.roomDestroyed(roomJID);
}
}
public static void roomSubjectChanged(JID roomJID, JID user, String newSubject) {
for (MUCEventListener listener : listeners) {
listener.roomSubjectChanged(roomJID, user, newSubject);
}
}
}