1 package com.teamkonzept.webman.mainint.events; 2 3 import java.util.*; 4 5 import com.teamkonzept.web.*; 6 import com.teamkonzept.lib.*; 7 import org.apache.log4j.Category; 8 9 13 public abstract class CachedEventDistributor extends DefaultEventDistributor implements ErrorCodes 14 { 15 private Hashtable cache = new Hashtable(); 16 17 18 static Category cat = Category.getInstance(CachedEventDistributor.class); 19 20 21 public void handleEvent(TKEvent evt) throws TKException 22 { 23 cat.debug("Got Event: " + evt); 24 TKEventHandler handler = (TKEventHandler)cache.get(evt.getName()); 25 if (handler == null) 26 { 27 for (int i=0; i < handlerList.size();i++) 28 { 29 handler = (TKEventHandler)handlerList.elementAt(i); 30 if (handler.isHandler(evt)) 31 { 32 cache.put(evt.getName(), handler); 33 handler.handleEvent(evt); 34 return; 35 } 36 } 37 throw new TKException("Invalid Event !" + evt.getName(),INVALID_EVENT, NORMAL_SEVERITY, false, null); 38 } 39 handler.handleEvent(evt); 40 } 41 42 45 public void removeEventHandler(TKEventHandler handler) 46 { 47 Enumeration keys = cache.keys(); 49 while (keys.hasMoreElements()) 50 { 51 Object obj = keys.nextElement(); 52 if (cache.get(obj) == handler) 53 cache.remove(obj); 54 } 55 super.removeEventHandler(handler); 56 } 57 58 } 59 | Popular Tags |