1 20 package org.enhydra.barracuda.core.event.helper; 21 22 import org.apache.log4j.*; 23 24 import org.enhydra.barracuda.core.event.*; 25 26 51 public class EventConnectorFactory extends DefaultListenerFactory { 52 53 protected static final Logger logger = Logger.getLogger(EventConnectorFactory.class.getName()); 54 protected Class eventHandlerClass = null; 55 56 61 public EventConnectorFactory(Class aClass) { 62 logger.debug("Creating new EventConnectorFactory --> "+aClass); 63 64 eventHandlerClass = aClass; 66 if (eventHandlerClass==null) { 67 logger.fatal("Event handler class cannot be null!", new IllegalAccessException ()); 68 } 69 70 getInstance(); 75 } 76 77 82 public BaseEventListener getInstance() { 83 if (logger.isDebugEnabled()) logger.debug("Creating instance of: " + eventHandlerClass.getName()); 84 85 BaseEventListener bel = null; 87 Exception e = null; 88 try { 89 bel = (BaseEventListener) eventHandlerClass.newInstance(); 90 } catch (IllegalAccessException iae) { 91 logger.fatal("Illegal Access Exception!", iae); 92 } catch (InstantiationException ie) { 93 logger.fatal("Error instantiating "+eventHandlerClass.getName()+"; if you defined it as an inner class, make sure its declared public static", ie); 94 } catch (ClassCastException cce) { 95 logger.fatal("Error casting "+eventHandlerClass.getName()+" to BaseEventListner. This class or its superclass must implement the BaseEventListener interface", cce); 96 } 97 98 return bel; 100 } 101 102 109 public String getListenerID() { 110 return getID(eventHandlerClass); 111 } 112 113 } 114 | Popular Tags |