1 20 package org.enhydra.barracuda.core.event; 21 22 import java.io.*; 23 import java.util.*; 24 import javax.servlet.*; 25 import javax.servlet.http.*; 26 27 import org.apache.log4j.*; 28 29 38 public abstract class DefaultBaseEventListener implements BaseEventListener { 39 40 protected static final Logger localLogger = Logger.getLogger(DefaultBaseEventListener.class.getName()); 42 43 protected String idStr = null; 45 46 54 public void handleEvent(EventContext context) throws EventException { 55 if (context==null) return; 57 BaseEvent event = context.getEvent(); 58 try { 59 if (localLogger.isDebugEnabled()) localLogger.debug("Entering "+this.getListenerID()); 60 if (event instanceof ControlEvent && context instanceof ControlEventContext) { 61 handleControlEvent((ControlEventContext) context); 62 } else if (event instanceof ViewEvent && context instanceof ViewEventContext) { 63 handleViewEvent((ViewEventContext) context); 64 } else { 65 handleOtherEvent(context); 66 } 67 } catch (ServletException e) { 68 throw new EventException("Unexpected Servlet Error", e); 69 } catch (IOException e) { 70 throw new EventException("Unexpected IOException", e); 71 } finally { 72 event.setHandled(isHandled()); 73 if (localLogger.isDebugEnabled()) localLogger.debug("Exiting "+this.getListenerID()); 74 } 75 } 76 77 78 86 public void handleControlEvent(ControlEventContext context) throws EventException, ServletException, IOException { 87 String msg = "Invoked handleControlEvent()...this method should have been extended"; 93 localLogger.warn(msg); 94 throw new UnhandledEventException(msg, context); 95 } 96 97 105 public void handleViewEvent(ViewEventContext context) throws EventException, ServletException, IOException { 106 String msg = "Invoked handleViewEvent()...this method should have been extended"; 112 localLogger.warn(msg); 113 throw new UnhandledEventException(msg, context); 114 } 115 116 122 public void handleOtherEvent(EventContext context) throws EventException { 123 String msg = "Invoked handleOtherEvent()...this method should have been extended"; 129 localLogger.warn(msg); 130 throw new UnhandledEventException(msg, context); 131 } 132 133 142 public boolean isHandled() { 143 return true; 144 } 145 146 152 public String getListenerID() { 153 if (idStr==null) { 154 idStr = DefaultBaseEvent.getClassID(this.getClass()); 155 } 156 return idStr; 157 } 158 } 159 | Popular Tags |