SalesPoint v3.3 API

util
Class ListenerHelper

java.lang.Object
  extended by javax.swing.event.EventListenerList
      extended by util.ListenerHelper
All Implemented Interfaces:
Serializable

public class ListenerHelper
extends EventListenerList

Helper class that supports Listeners which themselves can be listened to.

The main intent is to support garbage collection by avoiding cyclic links between the listener and its event source. Listeners that use ListenerHelper (and implement HelpableListener) will be registered with their event source only as long as there are any listeners registered with them. They will however guarantee up-to-date-ness indepent of whether a listener is registered with them or not, by polling their model whenever a query is performed against them and they have no listeners.

For this mechanism to work properly such listeners must abide by the following rules:

As the Swing serialization is buggy, this class will serialize only listeners that implement SerializableListener. For this purpose, however, all methods in EventListenerList need to be overridden.

Since:
v2.0
Author:
Steffen Zschaler
See Also:
HelpableListener, needModelUpdate(), Serialized Form

Field Summary
protected  Object[] aoListeners
          The list of ListenerType - Listener pairs.
protected  HelpableListener m_hlOwner
          The listener that owns this listener helper.
 
Fields inherited from class javax.swing.event.EventListenerList
listenerList
 
Constructor Summary
ListenerHelper()
          Construct a new ListenerHelper.
ListenerHelper(HelpableListener hlOwner)
          Create a new ListenerHelper.
 
Method Summary
<T extends EventListener>
void
add(Class<T> t, T l)
          Add the listener as a listener of the specified type.
 int getListenerCount()
          Return the total number of listeners for this listenerlist
 int getListenerCount(Class t)
          Return the total number of listeners of the supplied type for this listenerlist.
 Object[] getListenerList()
          This passes back the event listener list as an array of ListenerType - listener pairs.
 void needModelUpdate()
          Make sure, the owner's model is up to date.
<T extends EventListener>
void
remove(Class<T> t, T l)
          Remove the listener as a listener of the specified type.
 String toString()
          Return a string representation of the SerializableListenerHelper.
 
Methods inherited from class javax.swing.event.EventListenerList
getListeners
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

aoListeners

protected transient Object[] aoListeners
The list of ListenerType - Listener pairs. We need to redefine this as it would otherwise be stored by the standard EventListenerList mechanism. PENDING (sz9): Need to replace direct references to listeners by SoftReferences, in order to avoid cycles and thereby memory leaks. Example: Stocks listen to their catalogs in order to maintain referential integrity. They also store a pointer to their catalog in order to be able to reference it. A cycle is created, which means that creating lots of temporary stocks is a potential memory problem.


m_hlOwner

protected HelpableListener m_hlOwner
The listener that owns this listener helper.

Constructor Detail

ListenerHelper

public ListenerHelper()
Construct a new ListenerHelper. Using this constructor will only use the improved serialization support, but not the subscribe/unsubscribe functionality.


ListenerHelper

public ListenerHelper(HelpableListener hlOwner)
Create a new ListenerHelper.

Parameters:
hlOwner - the HelpableListener that is associated to this ListenerHelper.
Method Detail

getListenerList

public Object[] getListenerList()
This passes back the event listener list as an array of ListenerType - listener pairs. Note that for performance reasons, this implementation passes back the actual data structure in which the listner data is stored internally! This method is guaranteed to pass back a non-null array, so that no null-checking is required in fire methods. A zero-length array of Object should be returned if there are currently no listeners. WARNING!!! Absolutely NO modification of the data contained in this array should be made -- if any such manipulation is necessary, it should be done on a copy of the array returned rather than the array itself.

Overrides:
getListenerList in class EventListenerList

getListenerCount

public int getListenerCount()
Return the total number of listeners for this listenerlist

Overrides:
getListenerCount in class EventListenerList

getListenerCount

public int getListenerCount(Class t)
Return the total number of listeners of the supplied type for this listenerlist.

Overrides:
getListenerCount in class EventListenerList

add

public <T extends EventListener> void add(Class<T> t,
                                          T l)
Add the listener as a listener of the specified type.

Overrides:
add in class EventListenerList
Parameters:
t - the type of the listener to be added
l - the listener to be added

remove

public <T extends EventListener> void remove(Class<T> t,
                                             T l)
Remove the listener as a listener of the specified type.

Overrides:
remove in class EventListenerList
Parameters:
t - the type of the listener to be removed
l - the listener to be removed

needModelUpdate

public void needModelUpdate()
Make sure, the owner's model is up to date. If necessary call HelpableListener.updateModel() in the owner.


toString

public String toString()
Return a string representation of the SerializableListenerHelper.

Overrides:
toString in class EventListenerList

SalesPoint v3.3 API