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 35 public class EventRedirectFactory extends DefaultListenerFactory { 36 37 protected static final Logger logger = Logger.getLogger(EventRedirectFactory.class.getName()); 39 40 protected String id = null; 42 protected BaseEvent fevent = null; 43 44 50 public EventRedirectFactory (BaseEvent ifevent) { 53 if (logger.isInfoEnabled()) logger.info("Creating new EventRedirectFactory -->"+ifevent.getClass().getName()); 54 fevent = ifevent; 55 } 56 57 62 public BaseEventListener getInstance() { 63 return new EventHandler(); 64 } 65 66 73 public String getListenerID() { 74 return getID(fevent.getClass()); 75 } 76 77 80 class EventHandler extends DefaultBaseEventListener { 81 82 protected String idStr = null; 83 84 public void handleEvent(EventContext context) throws EventException { 85 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("Redirecting to:"+newEvent); 95 throw new ClientSideRedirectException(newEvent); 96 } catch (InstantiationException e) { 97 throw new EventException("Error redirecting Event", e); 98 } catch (IllegalAccessException e) { 99 throw new EventException("Error redirecting 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 |