1 11 12 package org.jivesoftware.messenger.event; 13 14 import org.jivesoftware.util.Log; 15 import org.jivesoftware.messenger.group.Group; 16 17 import java.util.List ; 18 import java.util.Map ; 19 import java.util.concurrent.CopyOnWriteArrayList ; 20 21 68 public class GroupEventDispatcher { 69 70 private static List <GroupEventListener> listeners = 71 new CopyOnWriteArrayList <GroupEventListener>(); 72 73 private GroupEventDispatcher() { 74 } 76 77 82 public static void addListener(GroupEventListener listener) { 83 if (listener == null) { 84 throw new NullPointerException (); 85 } 86 listeners.add(listener); 87 } 88 89 94 public static void removeListener(GroupEventListener listener) { 95 listeners.remove(listener); 96 } 97 98 105 public static void dispatchEvent(Group group, EventType eventType, Map params) { 106 for (GroupEventListener listener : listeners) { 107 try { 108 switch (eventType) { 109 case group_created: { 110 listener.groupCreated(group, params); 111 break; 112 } 113 case group_deleting: { 114 listener.groupDeleting(group, params); 115 break; 116 } 117 case member_added: { 118 listener.memberAdded(group, params); 119 break; 120 } 121 case member_removed: { 122 listener.memberRemoved(group, params); 123 break; 124 } 125 case admin_added: { 126 listener.adminAdded(group, params); 127 break; 128 } 129 case admin_removed: { 130 listener.adminRemoved(group, params); 131 break; 132 } 133 case group_modified: { 134 listener.groupModified(group, params); 135 break; 136 } 137 default: 138 break; 139 } 140 } 141 catch (Exception e) { 142 Log.error(e); 143 } 144 } 145 } 146 147 150 public enum EventType { 151 152 155 group_created, 156 157 162 group_deleting, 163 164 167 group_modified, 168 169 172 member_added, 173 174 177 member_removed, 178 179 182 admin_added, 183 184 187 admin_removed; 188 } 189 } | Popular Tags |