ilog.views.event
Class IlvListenerList

java.lang.Object
  extended by ilog.views.event.IlvListenerList
All Implemented Interfaces:
Serializable

public class IlvListenerList
extends Object
implements Serializable

IlvListenerList implements a thread-safe collection of event listeners backed by a list.

Here is some example code that shows how a class can use an IlvListenerList for registering event listeners and dispatching events to them:


   public class MyClass {
       IlvListenerList xyzListeners = new IlvListenerList();

       public void addXYZListener (XYZListener aListener) {
           xyzListeners.add(aListener);}

       public void removeXYZListener (XYZListener aListener) {
           xyzListeners.remove(aListener);}

       public void notifyXYZListeners () {
           Object[] listeners = xyzListeners.getListernerList();
           XYZEvent event = new XYZEvent(this);
           for (int i = 0 ; i < listeners.length; i ++) {
               XYZListener xyzListener = (XYZListener) listeners[i];
               xyzListener.xyzHappened(event);}}
       }
 

See Also:
Serialized Form

Constructor Summary
IlvListenerList()
          Creates a IlvListenerList.
 
Method Summary
 void add(EventListener l)
          Adds the listener.
 int getListenerCount()
          Returns the number of listeners for this listener list.
 Object[] getListenerList()
          This passes back the event listener list as an array of listerner.
 boolean remove(EventListener l)
          Removes the listener.
 String toString()
          Returns a string representation of the EventListenerList.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

IlvListenerList

public IlvListenerList()
Creates a IlvListenerList.

Method Detail

getListenerList

public final Object[] getListenerList()
This passes back the event listener list as an array of listerner. Note that this implementation passes back the actual data structure in which the listener 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.


getListenerCount

public final int getListenerCount()
Returns the number of listeners for this listener list.


add

public final void add(EventListener l)
Adds the listener.

Parameters:
l - The listener to be added.

remove

public final boolean remove(EventListener l)
Removes the listener.

Parameters:
l - The listener to be removed.
Returns:
true if the listener was found.

toString

public String toString()
Returns a string representation of the EventListenerList.

Overrides:
toString in class Object


Copyright © 1996-2007 ILOG S.A. All rights reserved.   Documentation homepage.   . All Rights Reserved.