com.apelon.dts.client.events
Class DTSEventMulticaster

java.lang.Object
  extended by java.awt.AWTEventMulticaster
      extended by com.apelon.dts.client.events.DTSEventMulticaster
All Implemented Interfaces:
ClassifyListener, ConceptListener, KBTypeListener, NamespaceListener, SubsetListener, TermListener, ActionListener, AdjustmentListener, ComponentListener, ContainerListener, FocusListener, HierarchyBoundsListener, HierarchyListener, InputMethodListener, ItemListener, KeyListener, MouseListener, MouseMotionListener, MouseWheelListener, TextListener, WindowFocusListener, WindowListener, WindowStateListener, EventListener

public class DTSEventMulticaster
extends AWTEventMulticaster
implements NamespaceListener, KBTypeListener, ConceptListener, TermListener, ClassifyListener, SubsetListener

A class which implements efficient and thread-safe multi-cast event dispatching for the DTS events defined in the com.apelon.dts'client.events package. This class will manage an immutable structure consisting of a chain of event listeners and will dispatch events to those listeners. Because the structure is immutable, it is safe to use this API to add/remove listeners during the process of an event dispatch operation. However, event listeners added during the process of an event dispatch operation will not be notified of the event currently being dispatched. An example of how this class is used to implement SubsetQuery which fires "subset action occured" events:


 public SubsetQuery extends BasicQuery {
   SubsetListener subsetListener = null;

   public synchronized void addSubsetListener(SubsetListener sl) {
           subsetListener = DTSEventMulticaster.add(subsetListener, sl);
   }
   public synchronized void removeSubsetListener(SubsetListener sl) {
         subsetListener = DTSEventMulticaster.remove(subsetListener, sl);
   }
   protected  void fireSubsetEvent(SubsetEvent e) {
     if (subsetListener != null) {
       subsetListener.subsetActionOccurred(e);
     }
   }
 }
 

Any uncaught exception in the listeners during event multicast is logged as error.

Since:
DTS 3.4
Version:
DTS 3.4
Author:
Yinghua Xu, Abhay Sinha

Field Summary
 
Fields inherited from class java.awt.AWTEventMulticaster
a, b
 
Constructor Summary
protected DTSEventMulticaster(EventListener a, EventListener b)
          Creates an instance of the DTSEventMulticaster class which chains listener-a with listener-b.
 
Method Summary
static ClassifyListener add(ClassifyListener a, ClassifyListener b)
          Adds classify-listener-a with classify-listener-b and returns the resulting multicast listener.
static ConceptListener add(ConceptListener a, ConceptListener b)
          Adds concept-listener-a with concept-listener-b and returns the resulting multicast listener.
static KBTypeListener add(KBTypeListener a, KBTypeListener b)
          Adds kbtype-listener-a with kbtype-listener-b and returns the resulting multicast listener.
static NamespaceListener add(NamespaceListener a, NamespaceListener b)
          Adds namespace-listener-a with namespace-listener-b and returns the resulting multicast listener.
static SubsetListener add(SubsetListener a, SubsetListener b)
          Adds subset-listener-a with subset-listener-b and returns the resulting multicast listener.
static TermListener add(TermListener a, TermListener b)
          Adds term-listener-a with term-listener-b and returns the resulting multicast listener.
protected static EventListener addInternal(EventListener a, EventListener b)
          Returns the resulting multicast listener from adding listener-a and listener-b together.
 void classifyActionOccurred(ClassifyEvent event)
          Will chain the call to the classifyActionOccurred routine of all registered listeners.
 void conceptActionOccurred(ConceptEvent event)
          Will chain the call to the conceptActionOccurred routine of all registered listeners.
 void kbtypeActionOccurred(KBTypeEvent event)
          Will chain the call to the kbtypeActionOccurred routine of all registered listeners.
 void namespaceActionOccurred(NamespaceEvent event)
          Will chain the call to the namespaceActionOccurred routine of all registered listeners.
static ClassifyListener remove(ClassifyListener listener, ClassifyListener oldListener)
          Removes the old classify-listener from classify-listener-l and returns the resulting multicast listener.
static ConceptListener remove(ConceptListener listener, ConceptListener oldListener)
          Removes the old concept-listener from concept-listener-l and returns the resulting multicast listener.
protected  EventListener remove(EventListener oldl)
          Removes a listener from this multicaster and returns the resulting multicast listener.
static KBTypeListener remove(KBTypeListener listener, KBTypeListener oldListener)
          Removes the old kbtype-listener from kbtype-listener-l and returns the resulting multicast listener.
static NamespaceListener remove(NamespaceListener listener, NamespaceListener oldListener)
          Removes the old namespace-listener from namespace-listener-l and returns the resulting multicast listener.
static SubsetListener remove(SubsetListener listener, SubsetListener oldListener)
          Removes the old subset-listener from subset-listener-l and returns the resulting multicast listener.
static TermListener remove(TermListener listener, TermListener oldListener)
          Removes the old term-listener from term-listener-l and returns the resulting multicast listener.
protected static EventListener removeInternal(EventListener l, EventListener oldl)
          Returns the resulting multicast listener after removing the old listener from listener-l.
protected static void save(ObjectOutputStream s, String k, EventListener l)
           
 void subsetActionOccurred(SubsetEvent event)
          Will chain the call to the subsetActionOccurred routine of all registered listeners.
 void termActionOccurred(TermEvent event)
          Will chain the call to the termActionOccurred routine of all registered listeners.
 
Methods inherited from class java.awt.AWTEventMulticaster
actionPerformed, add, add, add, add, add, add, add, add, add, add, add, add, add, add, add, add, add, adjustmentValueChanged, ancestorMoved, ancestorResized, caretPositionChanged, componentAdded, componentHidden, componentMoved, componentRemoved, componentResized, componentShown, focusGained, focusLost, getListeners, hierarchyChanged, inputMethodTextChanged, itemStateChanged, keyPressed, keyReleased, keyTyped, mouseClicked, mouseDragged, mouseEntered, mouseExited, mouseMoved, mousePressed, mouseReleased, mouseWheelMoved, remove, remove, remove, remove, remove, remove, remove, remove, remove, remove, remove, remove, remove, remove, remove, remove, remove, saveInternal, textValueChanged, windowActivated, windowClosed, windowClosing, windowDeactivated, windowDeiconified, windowGainedFocus, windowIconified, windowLostFocus, windowOpened, windowStateChanged
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DTSEventMulticaster

protected DTSEventMulticaster(EventListener a,
                              EventListener b)
Creates an instance of the DTSEventMulticaster class which chains listener-a with listener-b.

Parameters:
a - listener-a
b - listener-b
See Also:
EventListener
Method Detail

add

public static NamespaceListener add(NamespaceListener a,
                                    NamespaceListener b)
Adds namespace-listener-a with namespace-listener-b and returns the resulting multicast listener.

Parameters:
a - namespace-listener-a
b - namespace-listener-b
Returns:
namespace-listener The resulting multicast listener
See Also:
NamespaceListener

add

public static KBTypeListener add(KBTypeListener a,
                                 KBTypeListener b)
Adds kbtype-listener-a with kbtype-listener-b and returns the resulting multicast listener.

Parameters:
a - kbtype-listener-a
b - kbtype-listener-b
Returns:
kbtype-listener The resulting multicast listener
See Also:
KBTypeListener

add

public static ConceptListener add(ConceptListener a,
                                  ConceptListener b)
Adds concept-listener-a with concept-listener-b and returns the resulting multicast listener.

Parameters:
a - concept-listener-a
b - concept-listener-b
Returns:
concept-listener The resulting multicast listener
See Also:
ConceptListener

add

public static TermListener add(TermListener a,
                               TermListener b)
Adds term-listener-a with term-listener-b and returns the resulting multicast listener.

Parameters:
a - term-listener-a
b - term-listener-b
Returns:
term-listener The resulting multicast listener
See Also:
TermListener

add

public static ClassifyListener add(ClassifyListener a,
                                   ClassifyListener b)
Adds classify-listener-a with classify-listener-b and returns the resulting multicast listener.

Parameters:
a - classify-listener-a
b - classify-listener-b
Returns:
classify-listener The resulting multicast listener
See Also:
ClassifyListener

add

public static SubsetListener add(SubsetListener a,
                                 SubsetListener b)
Adds subset-listener-a with subset-listener-b and returns the resulting multicast listener.

Parameters:
a - subset-listener-a
b - subset-listener-b
Returns:
subset-listener The resulting multicast listener
See Also:
SubsetListener

remove

public static NamespaceListener remove(NamespaceListener listener,
                                       NamespaceListener oldListener)
Removes the old namespace-listener from namespace-listener-l and returns the resulting multicast listener.

Parameters:
listener - namespace-listener
oldListener - the namespace-listener being removed
Returns:
namespace-listener The resulting multicast listener
See Also:
NamespaceListener

remove

public static KBTypeListener remove(KBTypeListener listener,
                                    KBTypeListener oldListener)
Removes the old kbtype-listener from kbtype-listener-l and returns the resulting multicast listener.

Parameters:
listener - kbtype-listener
oldListener - the kbtype-listener being removed
Returns:
kbtype-listener The resulting multicast listener
See Also:
KBTypeListener

remove

public static ConceptListener remove(ConceptListener listener,
                                     ConceptListener oldListener)
Removes the old concept-listener from concept-listener-l and returns the resulting multicast listener.

Parameters:
listener - concept-listener
oldListener - the concept-listener being removed
Returns:
concept-listener The resulting multicast listener
See Also:
ConceptListener

remove

public static TermListener remove(TermListener listener,
                                  TermListener oldListener)
Removes the old term-listener from term-listener-l and returns the resulting multicast listener.

Parameters:
listener - term-listener
oldListener - the term-listener being removed
Returns:
term-listener The resulting multicast listener
See Also:
TermListener

remove

public static ClassifyListener remove(ClassifyListener listener,
                                      ClassifyListener oldListener)
Removes the old classify-listener from classify-listener-l and returns the resulting multicast listener.

Parameters:
listener - classify-listener
oldListener - the classify-listener being removed
Returns:
classify-listener The resulting multicast listener
See Also:
ClassifyListener

remove

public static SubsetListener remove(SubsetListener listener,
                                    SubsetListener oldListener)
Removes the old subset-listener from subset-listener-l and returns the resulting multicast listener.

Parameters:
listener - subset-listener
oldListener - the subset-listener being removed
Returns:
subset-listener The resulting multicast listener
See Also:
SubsetListener

addInternal

protected static EventListener addInternal(EventListener a,
                                           EventListener b)
Returns the resulting multicast listener from adding listener-a and listener-b together. If listener-a is null, it returns listener-b; If listener-b is null, it returns listener-a If neither are null, then it creates and returns a new DYSEventMulticaster instance which chains a with b.

Parameters:
a - event listener-a
b - event listener-b

remove

protected EventListener remove(EventListener oldl)
Removes a listener from this multicaster and returns the resulting multicast listener.

Overrides:
remove in class AWTEventMulticaster
Parameters:
oldl - the listener to be removed

removeInternal

protected static EventListener removeInternal(EventListener l,
                                              EventListener oldl)
Returns the resulting multicast listener after removing the old listener from listener-l. If listener-l equals the old listener OR listener-l is null, returns null. Else if listener-l is an instance of AWTEventMulticaster, then it removes the old listener from it. Else, returns listener l.

Parameters:
l - the listener being removed from
oldl - the listener being removed

save

protected static void save(ObjectOutputStream s,
                           String k,
                           EventListener l)
                    throws IOException
Throws:
IOException

namespaceActionOccurred

public void namespaceActionOccurred(NamespaceEvent event)
Will chain the call to the namespaceActionOccurred routine of all registered listeners. Any unhandled exception will be caught and logged as error.

Specified by:
namespaceActionOccurred in interface NamespaceListener
Parameters:
event - NamespaceEvent object.

kbtypeActionOccurred

public void kbtypeActionOccurred(KBTypeEvent event)
Will chain the call to the kbtypeActionOccurred routine of all registered listeners. Any unhandled exception will be caught and logged as error.

Specified by:
kbtypeActionOccurred in interface KBTypeListener
Parameters:
event - KBTypeEvent object.

conceptActionOccurred

public void conceptActionOccurred(ConceptEvent event)
Will chain the call to the conceptActionOccurred routine of all registered listeners. Any unhandled exception will be caught and logged as error.

Specified by:
conceptActionOccurred in interface ConceptListener
Parameters:
event - ConceptEvent object.

termActionOccurred

public void termActionOccurred(TermEvent event)
Will chain the call to the termActionOccurred routine of all registered listeners. Any unhandled exception will be caught and logged as error.

Specified by:
termActionOccurred in interface TermListener
Parameters:
event - TermEvent object.

classifyActionOccurred

public void classifyActionOccurred(ClassifyEvent event)
Will chain the call to the classifyActionOccurred routine of all registered listeners. Any unhandled exception will be caught and logged as error.

Specified by:
classifyActionOccurred in interface ClassifyListener
Parameters:
event - ClassifyEvent object.

subsetActionOccurred

public void subsetActionOccurred(SubsetEvent event)
Will chain the call to the subsetActionOccurred routine of all registered listeners. Any unhandled exception will be caught and logged as error.

Specified by:
subsetActionOccurred in interface SubsetListener
Parameters:
event - SubsetEvent object.


Copyright © 2011. All Rights Reserved.