freemarker.template
Class GenericEventMulticaster<E extends java.util.EventListener>

java.lang.Object
  extended by freemarker.template.GenericEventMulticaster<E>

public final class GenericEventMulticaster<E extends java.util.EventListener>
extends java.lang.Object

A generic event multicaster class. The client owns an object of this class, and calls the fireEvent(java.util.EventObject, freemarker.template.ListenerAdapter) method to fire events.

Version:
$Id: GenericEventMulticaster.java 1153 2013-04-15 10:59:37Z run2000 $

Constructor Summary
GenericEventMulticaster()
          Default constructor.
 
Method Summary
 void addEventListener(E listener)
          Adds an event listener.
 void fireEvent(java.util.EventObject event, ListenerAdapter adapter)
          Fires an event to all the listeners of this multicaster, using a ListenerAdapter.
 E[] getEventListeners()
          Gets all the registered event listeners.
 boolean isEmpty()
          To shortcut event firing: if there's nothing listening, don't bother creating an EventObject.
 void removeEventListener(E listener)
          Removes an event listener that was previously added.
 java.lang.String toString()
          Returns a string representation of the object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

GenericEventMulticaster

public GenericEventMulticaster()
Default constructor.

Method Detail

addEventListener

public void addEventListener(E listener)
Adds an event listener. The order in which the listeners are added determines the order that the listeners receive each event.

Parameters:
listener - the event listener to be registered

removeEventListener

public void removeEventListener(E listener)
Removes an event listener that was previously added. If a listener was added more than once, only the first instance is removed.

Parameters:
listener - the event listener to be unregistered

getEventListeners

public E[] getEventListeners()
Gets all the registered event listeners. This method was added for compatibility with JavaBeans as of JDK 1.4.


isEmpty

public boolean isEmpty()
To shortcut event firing: if there's nothing listening, don't bother creating an EventObject.

Returns:
true if there are no registered listeners, otherwise false

fireEvent

public void fireEvent(java.util.EventObject event,
                      ListenerAdapter adapter)
Fires an event to all the listeners of this multicaster, using a ListenerAdapter. If any listener throws an exception, we immediately abort sending the event to any other listeners.

Parameters:
event - the event to be sent to each of the listeners
adapter - adapts the event listeners to this multicaster
See Also:
ListenerAdapter

toString

public java.lang.String toString()
Returns a string representation of the object.

Overrides:
toString in class java.lang.Object
Returns:
a string representation of the object.