org.argouml.model.uml
Class UmlModelEventPump

java.lang.Object
  extended byorg.argouml.model.uml.UmlModelEventPump
All Implemented Interfaces:
EventListener, ru.novosoft.uml.MElementListener

public final class UmlModelEventPump
extends Object
implements ru.novosoft.uml.MElementListener

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.

This class is part of the NSUML-dependant API of the model component. Use the NSUML-free Model.getPump() and the ModelEventPump interface everywhere except within the NSUML-implementation. 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  EventListenerHashMap listenerMap
          The 'map' with the eventlistenerlists per modelelement.
private static Logger LOG
          The Logger.
private  boolean pumping
          Indicate wether we pump events to listeners yes or no.
static String REMOVE
          "remove".
private static UmlModelEventPump theInstance
           
 
Constructor Summary
private UmlModelEventPump()
          Constructor for UmlModelEventPump, initialises the NSUML event policy.
 
Method Summary
 void addClassModelEventListener(ru.novosoft.uml.MElementListener listener, Object metaType, String eventName)
          Convinience method to add a listener that only listens to one specific event.
 void addClassModelEventListener(ru.novosoft.uml.MElementListener listener, Object metaType, 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(Class cSource, Map mpNameMap)
          Make event types for a single event source available to this UMLModelEventPump.
 void addEventSourcesFromDocument(Document doc)
          Make all event sources described by the given document available to the UMLModelEventPump.
 void addModelEventListener(Object listener, Object modelelement)
          Adds a listener to all events fired by some modelelement.
 void addModelEventListener(Object listener, Object modelelement, String eventName)
          Convenience method to add a listener that only listens to one specific event.
 void addModelEventListener(Object listener, Object modelelement, String[] eventNames)
          Adds a listener to modelevents that are fired by some given modelelement and that have the name eventNames.
 void cleanUp()
          Clears the hashmaps with listeners.
(package private)  void cleanUp(ru.novosoft.uml.MBase element)
          Method to remove some element from the listenerObjectMap.
private  void executeAddClassModelEventListener(ru.novosoft.uml.MElementListener listener, Class modelClass, String eventName)
          Does the actual adding.
private  void executeRemoveClassModelEventListener(ru.novosoft.uml.MElementListener listener, Class modelClass, String eventName)
          Executes the removal of a listener to a class.
 void flushModelEvents()
          changes the NSUML event policy to flush model events.
private  Class formatClass(Class inputClass)
          Retrieves the implementation class belonging to some given class.
(package private)  ClassListenerHashMap getClassListenerMap()
           
(package private)  EventListenerHashMap getEventListenerMap()
           
private  ru.novosoft.uml.MElementListener[] getListenerList(ru.novosoft.uml.MElementEvent e)
           
static UmlModelEventPump getPump()
          Singleton access method.
 void listRoleItemSet(ru.novosoft.uml.MElementEvent e)
           
 void propertySet(ru.novosoft.uml.MElementEvent e)
           
 void recovered(ru.novosoft.uml.MElementEvent e)
           
 void removeClassModelEventListener(ru.novosoft.uml.MElementListener listener, Object metaType, String eventName)
          Convinience method to remove a listener that listens to events named eventName that are fired by instances of modelClass.
 void removeClassModelEventListener(ru.novosoft.uml.MElementListener listener, Object metaType, String[] eventNames)
          Removes a listener that listens to all modelevents fired by instances of modelClass and that have the original name eventNames.
 void removed(ru.novosoft.uml.MElementEvent e)
           
 void removeModelEventListener(Object listener, Object handle)
          Removes a listener that listens to all events fired by the given modelelement.
 void removeModelEventListener(Object listener, Object handle, String eventName)
          Convenience method to remove a listener to some event.
 void removeModelEventListener(Object listener, Object handle, String[] eventNames)
          Removes a listener that listens to modelevents with name eventNames that are fired by the given modelelement.
 void roleAdded(ru.novosoft.uml.MElementEvent e)
           
 void roleRemoved(ru.novosoft.uml.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

LOG

private static final Logger LOG
The Logger.


pumping

private boolean pumping
Indicate wether we pump events to listeners yes or no. There is some fault in the NSUML implementation but where...


REMOVE

public static final String REMOVE
"remove".

See Also:
Constant Field Values

theInstance

private static UmlModelEventPump theInstance

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(ru.novosoft.uml.MElementListener listener,
                                       Object metaType,
                                       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 registered 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.
metaType - is the given model class
eventNames - is a array of strings with event names.
Throws:
IllegalArgumentException - if one of the arguments is null or if the modelClass is not a subclass of MBase.
IllegalStateException - if the listener is allready registred

addClassModelEventListener

public void addClassModelEventListener(ru.novosoft.uml.MElementListener listener,
                                       Object metaType,
                                       String eventName)
Convinience method to add a listener that only listens to one specific event.

Parameters:
listener - The listener to add
metaType - 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(ru.novosoft.uml.MElementListener listener,
                                               Class modelClass,
                                               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 Class formatClass(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(ru.novosoft.uml.MElementListener listener,
                                          Object metaType,
                                          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
metaType - 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(ru.novosoft.uml.MElementListener listener,
                                          Object metaType,
                                          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
metaType - The class the listener does not want to listen to instances anymore
eventName - The eventname the listener does not want to listen to anymore

executeRemoveClassModelEventListener

private void executeRemoveClassModelEventListener(ru.novosoft.uml.MElementListener listener,
                                                  Class modelClass,
                                                  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(Object listener,
                                  Object modelelement,
                                  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(Object listener,
                                  Object modelelement,
                                  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(Object listener,
                                  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(Object listener,
                                     Object handle,
                                     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(Object listener,
                                     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(Object listener,
                                     Object handle,
                                     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(ru.novosoft.uml.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(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(Class cSource,
                           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(ru.novosoft.uml.MElementEvent e)
Specified by:
listRoleItemSet in interface ru.novosoft.uml.MElementListener
See Also:
MElementListener.listRoleItemSet(MElementEvent)

getListenerList

private ru.novosoft.uml.MElementListener[] getListenerList(ru.novosoft.uml.MElementEvent e)

propertySet

public void propertySet(ru.novosoft.uml.MElementEvent e)
Specified by:
propertySet in interface ru.novosoft.uml.MElementListener
See Also:
MElementListener.propertySet(MElementEvent)

recovered

public void recovered(ru.novosoft.uml.MElementEvent e)
Specified by:
recovered in interface ru.novosoft.uml.MElementListener
See Also:
MElementListener.recovered(MElementEvent)

removed

public void removed(ru.novosoft.uml.MElementEvent e)
Specified by:
removed in interface ru.novosoft.uml.MElementListener
See Also:
MElementListener.removed(MElementEvent)

roleAdded

public void roleAdded(ru.novosoft.uml.MElementEvent e)
Specified by:
roleAdded in interface ru.novosoft.uml.MElementListener
See Also:
MElementListener.roleAdded(MElementEvent)

roleRemoved

public void roleRemoved(ru.novosoft.uml.MElementEvent e)
Specified by:
roleRemoved in interface ru.novosoft.uml.MElementListener
See Also:
MElementListener.roleRemoved(MElementEvent)

cleanUp

public void cleanUp()
Clears the hashmaps with listeners. This is only needed by the JUnit tests. It's an implementation detail that the visibility is public. THIS METHOD SHOULD NOT BE USED OUTSIDE JUNIT TESTS.


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 (20050222)ArgoUML HomepageArgoUML Developers' pageArgoUML Cookbook