1 11 12 package org.jivesoftware.util; 13 14 import org.jivesoftware.util.Log; 15 16 import java.util.List ; 17 import java.util.Map ; 18 import java.util.concurrent.CopyOnWriteArrayList ; 19 20 36 public class PropertyEventDispatcher { 37 38 private static List <PropertyEventListener> listeners = 39 new CopyOnWriteArrayList <PropertyEventListener>(); 40 41 private PropertyEventDispatcher() { 42 } 44 45 50 public static void addListener(PropertyEventListener listener) { 51 if (listener == null) { 52 throw new NullPointerException (); 53 } 54 listeners.add(listener); 55 } 56 57 62 public static void removeListener(PropertyEventListener listener) { 63 listeners.remove(listener); 64 } 65 66 73 public static void dispatchEvent(String property, EventType eventType, Map params) { 74 for (PropertyEventListener listener : listeners) { 75 try { 76 switch (eventType) { 77 case property_set: { 78 listener.propertySet(property, params); 79 break; 80 } 81 case property_deleted: { 82 listener.propertyDeleted(property, params); 83 break; 84 } 85 case xml_property_set: { 86 listener.xmlPropertySet(property, params); 87 break; 88 } 89 case xml_property_deleted: { 90 listener.xmlPropertyDeleted(property, params); 91 break; 92 } 93 default: 94 break; 95 } 96 } 97 catch (Exception e) { 98 Log.error(e); 99 } 100 } 101 } 102 103 106 public enum EventType { 107 108 111 property_set, 112 113 116 property_deleted, 117 118 121 xml_property_set, 122 123 126 xml_property_deleted; 127 } 128 } | Popular Tags |