org.barracudamvc.core.event.helper
Class EventConnectorFactory

java.lang.Object
  extended by org.barracudamvc.core.event.DefaultListenerFactory
      extended by org.barracudamvc.core.event.helper.EventConnectorFactory
All Implemented Interfaces:
ListenerFactory

public class EventConnectorFactory
extends DefaultListenerFactory

This class associates a specific event handler class with an event by extending DefaultListenerFactory and making implementation details in the gateways much simpler... Without this class, each instance of a listener factory must create a separate anonymous class and provide the implementation for getInstance() and getListenerID().

With this class, the association of an event to a handler is a reduced to a single line:

specifyLocalEventInterests(new EventConnectorFactory(Handler.class), Event.class);

IMPORTANT NOTE: When using this class, the passed-in event handler must either be a non-inner class or an inner class which is declared public static. Otherwise, when the getInstance() method attempts to instantiate the handler a java.lang.InstantiationException will get thrown which will show up as a java.lang.NullPointerException. This is because getInstance() returns null if it fails to instantiate the handler. This won't be caught at compile time, so be careful!

Since:
1.0.1 (2002-02-15)
Version:
%I%, %G%
Author:
Stephen Peterson , Jacob Kjome

Field Summary
protected  Class eventHandlerClass
           
protected static org.apache.log4j.Logger logger
           
 
Fields inherited from class org.barracudamvc.core.event.DefaultListenerFactory
id
 
Constructor Summary
EventConnectorFactory(Class aClass)
          Constructor
 
Method Summary
 BaseEventListener getInstance()
          Get an instance of the underlying BaseEventListener
 String getListenerID()
          Get the Listener ID associated with this class of listener.
 
Methods inherited from class org.barracudamvc.core.event.DefaultListenerFactory
getID, notifyAlways
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

protected static final org.apache.log4j.Logger logger

eventHandlerClass

protected Class eventHandlerClass
Constructor Detail

EventConnectorFactory

public EventConnectorFactory(Class aClass)
Constructor

Parameters:
aClass - the handler class to associate with an event
Method Detail

getInstance

public BaseEventListener getInstance()
Get an instance of the underlying BaseEventListener

Specified by:
getInstance in interface ListenerFactory
Specified by:
getInstance in class DefaultListenerFactory
Returns:
get an instance of the BaseEventListener

getListenerID

public String getListenerID()
Get the Listener ID associated with this class of listener. This will generally either be the class name of the listener that the factory creates

Specified by:
getListenerID in interface ListenerFactory
Specified by:
getListenerID in class DefaultListenerFactory
Returns:
the listener ID that describes this factory


Copyright © 2006 BarracudaMVC.org All Rights Reserved.