1 20 package org.enhydra.barracuda.core.event.helper; 21 22 import java.io.*; 23 import java.util.*; 24 25 import org.apache.log4j.*; 26 27 import org.enhydra.barracuda.core.event.*; 28 import org.enhydra.barracuda.plankton.*; 29 30 38 public class EventForwardingFactory extends DefaultListenerFactory { 39 40 protected static final Logger logger = Logger.getLogger(EventForwardingFactory.class.getName()); 42 43 protected String id = null; 45 protected BaseEvent fevent = null; 46 47 53 public EventForwardingFactory (BaseEvent ifevent) { 54 if (logger.isInfoEnabled()) logger.info("Creating new EventForwardingFactory -->"+ifevent.getClass().getName()); 55 fevent = ifevent; 56 } 57 58 63 public BaseEventListener getInstance() { 64 return new EventHandler(); 65 } 66 67 74 public String getListenerID() { 75 return getID(fevent.getClass()); 76 } 77 78 81 class EventHandler extends DefaultBaseEventListener { 82 83 protected String idStr = null; 84 85 public void handleEvent(EventContext context) throws EventException { 86 BaseEvent event = context.getEvent(); 87 DispatchQueue queue = context.getQueue(); 88 if (logger.isInfoEnabled()) logger.info("Got event:"+event); 89 90 try { 93 BaseEvent newEvent = (BaseEvent) fevent.getClass().newInstance(); 94 if (logger.isInfoEnabled()) logger.info("Forwarding to:"+newEvent); 95 newEvent.setSource(event); 96 queue.addEvent(newEvent); 97 event.setHandled(true); 98 } catch (Exception e) { 99 throw new EventException("Error forwarding Event", e); 100 } 101 } 102 103 109 public String getListenerID() { 110 if (idStr==null) { 111 idStr = DefaultBaseEvent.getClassID(fevent.getClass()); 112 } 113 return idStr; 114 } 115 } 116 } 117 | Popular Tags |