|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.virtuosotechnologies.lib.util.EventBroadcaster
A helper class for broadcasting events.
This class is meant to be used internally by any class that needs to broadcast events. It provides the following facilities:
This class is fully synchronized and thread-safe.
Constructor Summary | |
EventBroadcaster(Class listenerClass)
Constructor. |
Method Summary | |
void |
addListenerStrong(EventListener listener)
Add a listener to the set of listeners. |
void |
addListenerWeak(EventListener listener)
Add a listener to the set of listeners. |
void |
fireAbortableEvent(Method method,
EventObject event)
Fires an event. |
void |
fireAbortableEvent(String methodName,
EventObject event)
Fires an event. |
void |
fireEvent(Method method,
EventObject event)
Fires an event. |
void |
fireEvent(String methodName,
EventObject event)
Fires an event. |
Class |
getListenerClass()
Returns the listener class associated with this broadcaster. |
static Method |
getListenerMethod(Class listenerClass,
String name,
Class eventClass)
A helper for listener interfaces that want to provide static Method members for fast access to their methods. |
List |
getListenersAsList()
Returns a copy of the set of listeners as a list. |
Set |
getListenersAsSet()
Returns a copy of the set of listeners as a set. |
static Method |
getUniqueListenerMethod(Class listenerClass)
A helper for listener interfaces that want to provide static Method members for fast access to their methods. |
boolean |
isVerbose()
Get verbose mode (for debugging) |
void |
removeAllListeners()
Removes all listeners from the set of listeners. |
void |
removeListener(EventListener listener)
Removes a listener from the set of listeners. |
void |
setName(String name)
Set identifying name that will be returned from toString (for debugging) |
void |
setVerbose(boolean verbose)
Set verbose mode (for debugging) |
String |
toString()
toString override. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
public EventBroadcaster(Class listenerClass)
listenerClass
- the type of listener that will listen to
this broadcaster. Normally, you should pass the class of the
listener interface.Method Detail |
public static Method getListenerMethod(Class listenerClass, String name, Class eventClass)
listenerClass
- class object for the listenername
- name of the methodeventClass
- class of the event parameter.
ClassCastException
- the listener wasn't an EventListener,
or the event wasn't an EventObject.
IllegalArgumentException
- no such method.public static Method getUniqueListenerMethod(Class listenerClass)
listenerClass
- class object for the listener
ClassCastException
- the listener wasn't an EventListener,
or the parameter taken by its unique method wasn't an EventObject.
IllegalArgumentException
- no methods, or multiple methods,
or the unique method took no parameters of multiple parameters.public boolean isVerbose()
public void setVerbose(boolean verbose)
verbose
- verbose modepublic void setName(String name)
name
- identifying namepublic String toString()
public Class getListenerClass()
public void addListenerWeak(EventListener listener)
addListenerWeak(new MyListener());
listener
- a reference to the listener to add. It must be
castable to the listener class associated with this broadcaster.
ClassCastException
- the listener isn't castable to the
associated listener classpublic void addListenerStrong(EventListener listener)
listener
- a reference to the listener to add. It must be
castable to the listener class associated with this broadcaster.
ClassCastException
- the listener isn't castable to the
associated listener classpublic void removeListener(EventListener listener)
listener
- a reference to the listener to remove.public void removeAllListeners()
public Set getListenersAsSet()
public List getListenersAsList()
public void fireEvent(String methodName, EventObject event)
This version of fireEvent may be a little slow because it looks up the method object from the name and parameters via reflection. If an event is to be fired rapidly, you may want to create and cache the method object yourself, and call the other version of fireEvent() that takes a method object.
methodName
- name of method to invokeevent
- event object to send
IllegalArgumentException
- the given method was not
found in the listener class, or it is not accessible
because it is private or protected.
IllegalStateException
- the method threw a checked
exception.public void fireEvent(Method method, EventObject event)
method
- method to invokeevent
- event object to send
IllegalArgumentException
- the given method is not
accessible because it is private or protected.
IllegalStateException
- the method threw a checked
exception.public void fireAbortableEvent(String methodName, EventObject event) throws EventAbortedException
This version of fireEvent may be a little slow because it looks up the method object from the name and parameters via reflection. If an event is to be fired rapidly, you may want to create and cache the method object yourself, and call the other version of fireEvent() that takes a method object.
methodName
- name of method to invokeevent
- event object to send
EventAbortedException
- event aborted by a listener
IllegalArgumentException
- the given method was not
found in the listener class, or it is not accessible
because it is private or protected.
IllegalStateException
- the method threw a checked
exception.public void fireAbortableEvent(Method method, EventObject event) throws EventAbortedException
method
- method to invokeevent
- event object to send
EventAbortedException
- event aborted by a listener
IllegalArgumentException
- the given method is not
accessible because it is private or protected.
IllegalStateException
- the method threw a checked
exception.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |