org.argouml.model.uml
Class UmlModelEventPump

java.lang.Object
  |
  +--org.argouml.model.uml.UmlModelEventPump

public final class UmlModelEventPump
extends java.lang.Object

This class implements an event pump for all modelevents (MEvents with the current NSUML model). Two kinds of listeners can be registred to the pump: listeners to class events and listeners to object events. The pump dispatches all events fired by objects of a certain class to the class listeners (listeners that are registred via addClassModelEventListener). Furthermore, it dispatches all events to listeners that are registered for a certain object if this object fired the original event.

Maybe this class should dispatch a thread to handle the incoming event in the future.

Since:
Oct 14, 2002

Field Summary
private  ClassListenerHashMap _classListenerMap
           
private  EventTreeDefinition _definition
           
private static UmlModelEventPump _instance
           
private  EventListenerHashMap _listenerMap
          The 'map' with the eventlistenerlists per modelelement
static java.lang.String REMOVE
           
 
Constructor Summary
private UmlModelEventPump()
          Constructor for UmlModelEventPump, initialises the NSUML event policy.
 
Method Summary
 void addClassModelEventListener(MElementListener listener, java.lang.Class modelClass, java.lang.String eventName)
          Convinience method to add a listener that only listens to one specific event
 void addClassModelEventListener(MElementListener listener, java.lang.Class modelClass, java.lang.String[] eventNames)
          Adds a listener that listens to all modelevents that are named eventNames and that occur to instances of a given modelClass.
 void addEventSource(java.lang.Class cSource, java.util.Map mpNameMap)
          Make event types for a single event source available to this UMLModelEventPump.
 void addEventSourcesFromDocument(org.w3c.dom.Document doc)
          Make all event sources described by the given document available to the UMLModelEventPump.
 void addModelEventListener(java.lang.Object listener, java.lang.Object modelelement)
          Adds a listener to all events fired by some modelelement.
 void addModelEventListener(java.lang.Object listener, java.lang.Object modelelement, java.lang.String eventName)
          Convenience method to add a listener that only listens to one specific event.
 void addModelEventListener(java.lang.Object listener, java.lang.Object modelelement, java.lang.String[] eventNames)
          Adds a listener to modelevents that are fired by some given modelelement and that have the name eventNames.
(package private)  void cleanUp()
          Clears the hashmaps with listeners.
(package private)  void cleanUp(MBase element)
          Method to remove some element from the listenerObjectMap.
private  void executeAddClassModelEventListener(MElementListener listener, java.lang.Class modelClass, java.lang.String eventName)
          Does the actual adding
private  void executeRemoveClassModelEventListener(MElementListener listener, java.lang.Class modelClass, java.lang.String eventName)
          Executes the removal of a listener to a class
 void flushModelEvents()
          changes the NSUML event policy to flush model events.
private  java.lang.Class formatClass(java.lang.Class inputClass)
          Retrieves the implementation class belonging to some given class.
(package private)  ClassListenerHashMap getClassListenerMap()
           
(package private)  EventListenerHashMap getEventListenerMap()
           
private  MElementListener[] getListenerList(MElementEvent e)
           
static UmlModelEventPump getPump()
          Singleton access method
 void listRoleItemSet(MElementEvent e)
           
 void propertySet(MElementEvent e)
           
 void recovered(MElementEvent e)
           
 void removeClassModelEventListener(MElementListener listener, java.lang.Class modelClass)
          Removes a listener that listens to all modelevents fired by instances of modelClass.
 void removeClassModelEventListener(MElementListener listener, java.lang.Class modelClass, java.lang.String eventName)
          Convinience method to remove a listener that listens to events named eventName that are fired by instances of modelClass
 void removeClassModelEventListener(MElementListener listener, java.lang.Class modelClass, java.lang.String[] eventNames)
          Removes a listener that listens to all modelevents fired by instances of modelClass and that have the original name eventNames.
 void removed(MElementEvent e)
           
 void removeModelEventListener(java.lang.Object listener, java.lang.Object handle)
          Removes a listener that listens to all events fired by the given modelelement.
 void removeModelEventListener(java.lang.Object listener, java.lang.Object handle, java.lang.String eventName)
          Convenience method to remove a listener to some event.
 void removeModelEventListener(java.lang.Object listener, java.lang.Object handle, java.lang.String[] eventNames)
          Removes a listener that listens to modelevents with name eventNames that are fired by the given modelelement.
 void roleAdded(MElementEvent e)
           
 void roleRemoved(MElementEvent e)
           
 void startPumpingEvents()
          changes the NSUML event policy in order to start udating the ui.
 void stopPumpingEvents()
          changes the NSUML event policy in order to stop udating the ui.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

REMOVE

public static final java.lang.String REMOVE
See Also:
Constant Field Values

_instance

private static UmlModelEventPump _instance

_listenerMap

private EventListenerHashMap _listenerMap
The 'map' with the eventlistenerlists per modelelement


_classListenerMap

private ClassListenerHashMap _classListenerMap

_definition

private EventTreeDefinition _definition
Constructor Detail

UmlModelEventPump

private UmlModelEventPump()
Constructor for UmlModelEventPump, initialises the NSUML event policy.

Method Detail

getPump

public static UmlModelEventPump getPump()
Singleton access method

Returns:
UmlModelEventPump

addClassModelEventListener

public void addClassModelEventListener(MElementListener listener,
                                       java.lang.Class modelClass,
                                       java.lang.String[] eventNames)
Adds a listener that listens to all modelevents that are named eventNames and that occur to instances of a given modelClass.

If you want the listener to be registred for remove events (that is: an instance of the class the listener is listening too is removed), then you have to register for the eventname "remove".

Parameters:
listener - is the listener to add.
modelClass - is the given model class
eventNames - is a array of strings with event names.
Throws:
java.lang.IllegalArgumentException - if one of the arguments is null or if the modelClass is not a subclass of MBase.
java.lang.IllegalStateException - if the listener is allready registred

addClassModelEventListener

public void addClassModelEventListener(MElementListener listener,
                                       java.lang.Class modelClass,
                                       java.lang.String eventName)
Convinience method to add a listener that only listens to one specific event

Parameters:
listener - The listener to add
modelClass - The listener should listen to instances of this class
eventName - The name of the event the listener wants to listen too.

executeAddClassModelEventListener

private void executeAddClassModelEventListener(MElementListener listener,
                                               java.lang.Class modelClass,
                                               java.lang.String eventName)
Does the actual adding

Parameters:
listener - The listener to add
modelClass - The listener should listen to instances of this class
eventName - The name of the event the listener wants to listen

formatClass

private java.lang.Class formatClass(java.lang.Class inputClass)
Retrieves the implementation class belonging to some given class. For example, retrieves ClassImpl.class if the input was Class.class or ClassImpl.class.

Parameters:
inputClass - An interface or implementation class from NSUML
Returns:
The implementation class from NSUML

removeClassModelEventListener

public void removeClassModelEventListener(MElementListener listener,
                                          java.lang.Class modelClass,
                                          java.lang.String[] eventNames)
Removes a listener that listens to all modelevents fired by instances of modelClass and that have the original name eventNames.

Parameters:
listener - The listener to remove
modelClass - The class the listener does not want to listen to instances anymore
eventNames - The eventnames the listener does not want to listen to anymore

removeClassModelEventListener

public void removeClassModelEventListener(MElementListener listener,
                                          java.lang.Class modelClass,
                                          java.lang.String eventName)
Convinience method to remove a listener that listens to events named eventName that are fired by instances of modelClass

Parameters:
listener - The listener to remove
modelClass - The class the listener does not want to listen to instances anymore
eventName - The eventname the listener does not want to listen to anymore

removeClassModelEventListener

public void removeClassModelEventListener(MElementListener listener,
                                          java.lang.Class modelClass)
Removes a listener that listens to all modelevents fired by instances of modelClass.

Parameters:
listener - The listener to remove
modelClass - The class the listener does not want to listen to instances anymore

executeRemoveClassModelEventListener

private void executeRemoveClassModelEventListener(MElementListener listener,
                                                  java.lang.Class modelClass,
                                                  java.lang.String eventName)
Executes the removal of a listener to a class

Parameters:
listener - The listener to remove
modelClass - The class the listener does not want to listen to instances anymore
eventName - The eventname the listener does not want to listen to anymore

addModelEventListener

public void addModelEventListener(java.lang.Object listener,
                                  java.lang.Object modelelement,
                                  java.lang.String[] eventNames)
Adds a listener to modelevents that are fired by some given modelelement and that have the name eventNames.

If you want the listener to be registred for remove events (that is: the instance the listener is listening too is removed), then you have to register for the eventname "remove"

Parameters:
listener - The listener to add
modelelement - The modelelement the listener should be added too
eventNames - The array of eventnames the listener should listen to

addModelEventListener

public void addModelEventListener(java.lang.Object listener,
                                  java.lang.Object modelelement,
                                  java.lang.String eventName)
Convenience method to add a listener that only listens to one specific event.

Parameters:
listener - The listener to add.
modelelement - The modelelement the listener should be added to.
eventName - The eventname the listener should listen to.

addModelEventListener

public void addModelEventListener(java.lang.Object listener,
                                  java.lang.Object modelelement)
Adds a listener to all events fired by some modelelement. Note: Due to the fact that ALL events are pumped for some modelelement, this is a rather powerfull method but also one that can hog performance. Use this with care!

Parameters:
listener - is the listener to add
modelelement - is the model element

removeModelEventListener

public void removeModelEventListener(java.lang.Object listener,
                                     java.lang.Object handle,
                                     java.lang.String[] eventNames)
Removes a listener that listens to modelevents with name eventNames that are fired by the given modelelement.

Parameters:
listener - The listener to remove
handle - The modelelement that fires the events the listener is listening to
eventNames - The list of event names the listener is interested in

removeModelEventListener

public void removeModelEventListener(java.lang.Object listener,
                                     java.lang.Object handle)
Removes a listener that listens to all events fired by the given modelelement.

Parameters:
listener - is the listener
handle - is the model element

removeModelEventListener

public void removeModelEventListener(java.lang.Object listener,
                                     java.lang.Object handle,
                                     java.lang.String eventName)
Convenience method to remove a listener to some event.

Parameters:
listener - is the listener to remove
handle - is the object
eventName - is the name of the event

cleanUp

void cleanUp(MBase element)
Method to remove some element from the listenerObjectMap. Used by delete on UmlFactory to make sure all listeners are removed.

Parameters:
element -

addEventSourcesFromDocument

public void addEventSourcesFromDocument(org.w3c.dom.Document doc)
Make all event sources described by the given document available to the UMLModelEventPump. The document must match the pattern given by the following example:
 <eventtree>
   <source classname="classname of a model element">
     <eventtype name="event fired by this model element">
       <type>1</type>
     </eventtype>
   </source>
 </eventtree>
 
The classname is fully qualified.

The type is one of the numbers defined in MElementEvent. Each of the elements can be used multiple times. This operation is particularly provided for use by modules which add custom model elements.

Parameters:
doc - the document, the contents of which should be made available. This must be preparsed.

addEventSource

public void addEventSource(java.lang.Class cSource,
                           java.util.Map mpNameMap)

Make event types for a single event source available to this UMLModelEventPump.

This operation is particularly provided for use by modules which add custom model elements.

Parameters:
cSource - the source class for which to make event types available.
mpNameMap - a map of the event types to add for the source class. The keys are Strings indicating the names of events, while the values are int[] which contain all the event types the indicated event represents. The specific int values used can be found in MElementEvent.

listRoleItemSet

public void listRoleItemSet(MElementEvent e)
See Also:
MElementListener#listRoleItemSet(MElementEvent)

getListenerList

private MElementListener[] getListenerList(MElementEvent e)

propertySet

public void propertySet(MElementEvent e)
See Also:
MElementListener#propertySet(MElementEvent)

recovered

public void recovered(MElementEvent e)
See Also:
MElementListener#recovered(MElementEvent)

removed

public void removed(MElementEvent e)
See Also:
MElementListener#removed(MElementEvent)

roleAdded

public void roleAdded(MElementEvent e)
See Also:
MElementListener#roleAdded(MElementEvent)

roleRemoved

public void roleRemoved(MElementEvent e)
See Also:
MElementListener#roleRemoved(MElementEvent)

cleanUp

void cleanUp()
Clears the hashmaps with listeners. This is only needed by the JUnit tests. Therefore the visibility is 'default'.


getClassListenerMap

ClassListenerHashMap getClassListenerMap()

getEventListenerMap

EventListenerHashMap getEventListenerMap()

stopPumpingEvents

public void stopPumpingEvents()
changes the NSUML event policy in order to stop udating the ui.


startPumpingEvents

public void startPumpingEvents()
changes the NSUML event policy in order to start udating the ui.


flushModelEvents

public void flushModelEvents()
changes the NSUML event policy to flush model events.



ArgoUML © 1996-2004 (20040306)ArgoUML HomepageArgoUML Developers' pageArgoUML Cookbook