1 package com.teamkonzept.lib; 2 3 import java.util.Hashtable ; 4 import java.util.Vector ; 5 6 16 public class ConfigurationManager 17 { 18 19 21 23 26 private static ConfigurationManager SINGLETON = null; 27 28 29 31 34 private Hashtable registry = null; 35 36 37 39 42 private ConfigurationManager () 43 { 44 this.registry = new Hashtable (); 45 } 46 47 48 50 55 public static synchronized ConfigurationManager getInstance () 56 { 57 if (SINGLETON == null) 58 { 59 SINGLETON = new ConfigurationManager(); 60 } 61 62 return SINGLETON; 63 } 64 65 66 68 77 public synchronized void registerConfigurationListener (ConfigurationListener listener, 78 Object context) 79 { 80 if (listener == null || 81 context == null) 82 { 83 return; 85 } 86 87 Vector registrees = (Vector ) registry.get(context); 89 90 if (registrees == null) 91 { 92 registrees = new Vector (); 94 } 95 96 registrees.addElement(listener); 98 99 registry.put(context, registrees); 101 } 102 103 112 public synchronized void deregisterConfigurationListener (ConfigurationListener listener, 113 Object context) 114 { 115 if (listener == null || 116 context == null) 117 { 118 return; 120 } 121 122 Vector registrees = (Vector ) registry.get(context); 124 125 if (registrees == null) 126 { 127 return; 129 } 130 131 registrees.removeElement(listener); 133 134 if (registrees.size() > 0) 136 { 137 registry.put(context, registrees); 138 } 139 else 140 { 141 registry.remove(context); 142 } 143 } 144 145 152 public synchronized void notifyListeners (Object context) 153 throws TKException 154 { 155 if (context == null) 156 { 157 return; 159 } 160 161 Vector registrees = (Vector ) registry.get(context); 163 164 if (registrees == null) 165 { 166 return; 168 } 169 170 for (int i = 0; i < registrees.size(); i++) 173 { 174 ((ConfigurationListener) registrees.elementAt(i)).configurationChanged(); 176 } 177 } 178 179 } 180 | Popular Tags |