com.std.util
Class ObservableEvent

java.lang.Object
extended by com.std.util.ObservableEvent

public class ObservableEvent
extends java.lang.Object

This class represents an object which is observable. Other objects may register their intent to be notified when this object changes; and when this object does change, it will trigger the update method of each observer. Note that the notifyObservers() method of this class is unrelated to the notify() of Object.

Author:
xxx
See Also:
Observable

Field Summary
(package private) static long serialVersionUID
           
 
Constructor Summary
ObservableEvent(java.lang.Class<?>... args)
          instantiates a new Event to be invoked using the specified arguments
 
Method Summary
 boolean addObserverMethod(java.lang.Object o, java.lang.String method)
          registers an instance method to be called when this event is invoked
 boolean addStaticObserverMethod(java.lang.Class<?> c, java.lang.String method)
          registers a static method to be called when this event is invoked
 void clearChanged()
          Reset this ObservableEvent's state to unchanged.
 int countObservers()
          Returns the number of observers for this object.
 boolean deleteObserverMethod(java.lang.Object o, java.lang.String method)
          removes an instance method from registration
 void deleteObservers()
          Deletes all observer methods of this ObservableEvent.
 boolean deleteStaticObserverMethod(java.lang.Class<?> c, java.lang.String method)
          removes a static method from registration
 boolean hasChanged()
          True if setChanged has been called more recently than clearChanged.
 void notifyObserverMethods(java.lang.Object... args)
          invoke all the Observers Note that though the order of notification is unspecified in subclasses, in ObservableEvent it is in the order of registration.
 void setChanged()
          Marks this Observable as having changed.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

serialVersionUID

static final long serialVersionUID
See Also:
Constant Field Values
Constructor Detail

ObservableEvent

public ObservableEvent(java.lang.Class<?>... args)
instantiates a new Event to be invoked using the specified arguments

Parameters:
args - the classes and order of the arguments to be passed
Method Detail

addObserverMethod

public boolean addObserverMethod(java.lang.Object o,
java.lang.String method)
registers an instance method to be called when this event is invoked

Parameters:
o - instance the method should be called on
method - name of the method to be called
Returns:
true if the handler has been successfully registered
Throws:
java.lang.IllegalArgumentException - if the method doesn't exist on the specified instance

addStaticObserverMethod

public boolean addStaticObserverMethod(java.lang.Class<?> c,
java.lang.String method)
registers a static method to be called when this event is invoked

Parameters:
c - class the method should be called on
method - name of the method to be called
Returns:
true if the handler has been successfully registered
Throws:
java.lang.NoSuchMethodException - if the method doesn't exist on the specified class

clearChanged

public void clearChanged()
Reset this ObservableEvent's state to unchanged. This is called automatically by notifyObservers once all observer methods have been notified.

See Also:
#notifyObserverMethods(Object ... args)

countObservers

public int countObservers()
Returns the number of observers for this object.

Returns:
number of observer methods for this

deleteObserverMethod

public boolean deleteObserverMethod(java.lang.Object o,
java.lang.String method)
removes an instance method from registration

Parameters:
o - instance of the method that should be removed
method - name of the method to be removed
Returns:
true if the handler has been successfully removed
Throws:
java.lang.NoSuchMethodException - if the method doesn't exist on the specified instance

deleteObservers

public void deleteObservers()
Deletes all observer methods of this ObservableEvent.


deleteStaticObserverMethod

public boolean deleteStaticObserverMethod(java.lang.Class<?> c,
java.lang.String method)
removes a static method from registration

Parameters:
c - class of the method that should be removed
method - name of the method to be removed
Returns:
true if the handler has been successfully removed
Throws:
java.lang.NoSuchMethodException - if the method doesn't exist on the specified class

hasChanged

public boolean hasChanged()
True if setChanged has been called more recently than clearChanged.

Returns:
whether or not this ObservableEvent has changed

notifyObserverMethods

public void notifyObserverMethods(java.lang.Object... args)
invoke all the Observers Note that though the order of notification is unspecified in subclasses, in ObservableEvent it is in the order of registration. NOTE: does not break on invocation exception.

Parameters:
args - arguments to be passed to the registered methods

setChanged

public void setChanged()
Marks this Observable as having changed.