1 11 12 package org.jivesoftware.messenger.event; 13 14 import org.jivesoftware.util.Log; 15 import org.jivesoftware.messenger.user.User; 16 17 import java.util.List ; 18 import java.util.Map ; 19 import java.util.concurrent.CopyOnWriteArrayList ; 20 21 77 public class UserEventDispatcher { 78 79 private static List <UserEventListener> listeners = 80 new CopyOnWriteArrayList <UserEventListener>(); 81 82 private UserEventDispatcher() { 83 } 85 86 91 public static void addListener(UserEventListener listener) { 92 if (listener == null) { 93 throw new NullPointerException (); 94 } 95 listeners.add(listener); 96 } 97 98 103 public static void removeListener(UserEventListener listener) { 104 listeners.remove(listener); 105 } 106 107 114 public static void dispatchEvent(User user, EventType eventType, Map params) { 115 for (UserEventListener listener : listeners) { 116 try { 117 switch (eventType) { 118 case user_created: { 119 listener.userCreated(user, params); 120 break; 121 } 122 case user_deleting: { 123 listener.userDeleting(user, params); 124 break; 125 } 126 case user_modified: { 127 listener.userModified(user, params); 128 break; 129 } 130 default: 131 break; 132 } 133 } 134 catch (Exception e) { 135 Log.error(e); 136 } 137 } 138 } 139 140 143 public enum EventType { 144 145 148 user_created, 149 150 155 user_deleting, 156 157 160 user_modified, 161 } 162 } | Popular Tags |