|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.apache.commons.lang3.event.EventListenerSupport<L>
L
- the type of event listener that is supported by this proxy.public class EventListenerSupport<L>
An EventListenerSupport object can be used to manage a list of event
listeners of a particular type. The class provides
addListener(Object)
and removeListener(Object)
methods
for registering listeners, as well as a fire()
method for firing
events to the listeners.
public class MyActionEventSource
{
private EventListenerSupport actionListeners =
EventListenerSupport.create(ActionListener.class);
public void someMethodThatFiresAction()
{
ActionEvent e = new ActionEvent(this, ActionEvent.ACTION_PERFORMED, "somethingCool");
actionListeners.fire().actionPerformed(e);
}
}
Serializing an EventListenerSupport
instance will result in any
non-Serializable
listeners being silently dropped.
Nested Class Summary | |
---|---|
protected class |
EventListenerSupport.ProxyInvocationHandler
An invocation handler used to dispatch the event(s) to all the listeners. |
Constructor Summary | |
---|---|
EventListenerSupport(Class<L> listenerInterface)
Creates an EventListenerSupport object which supports the provided listener interface. |
|
EventListenerSupport(Class<L> listenerInterface,
ClassLoader classLoader)
Creates an EventListenerSupport object which supports the provided listener interface using the specified class loader to create the JDK dynamic proxy. |
Method Summary | ||
---|---|---|
void |
addListener(L listener)
Registers an event listener. |
|
static
|
create(Class<T> listenerInterface)
Creates an EventListenerSupport object which supports the specified listener type. |
|
protected InvocationHandler |
createInvocationHandler()
Create the EventListenerSupport.ProxyInvocationHandler responsible for broadcasting calls
to the managed listeners. |
|
L |
fire()
Returns a proxy object which can be used to call listener methods on all of the registered event listeners. |
|
L[] |
getListeners()
Get an array containing the currently registered listeners. |
|
void |
removeListener(L listener)
Unregisters an event listener. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public EventListenerSupport(Class<L> listenerInterface)
listenerInterface
- the type of listener interface that will receive
events posted using this class.
NullPointerException
- if listenerInterface
is
null
.
IllegalArgumentException
- if listenerInterface
is
not an interface.public EventListenerSupport(Class<L> listenerInterface, ClassLoader classLoader)
listenerInterface
- the listener interface.classLoader
- the class loader.
NullPointerException
- if listenerInterface
or
classLoader
is null
.
IllegalArgumentException
- if listenerInterface
is
not an interface.Method Detail |
---|
public static <T> EventListenerSupport<T> create(Class<T> listenerInterface)
T
- the type of the listener interfacelistenerInterface
- the type of listener interface that will receive
events posted using this class.
NullPointerException
- if listenerInterface
is
null
.
IllegalArgumentException
- if listenerInterface
is
not an interface.public L fire()
public void addListener(L listener)
listener
- the event listener (may not be null
).
NullPointerException
- if listener
is
null
.public void removeListener(L listener)
listener
- the event listener (may not be null
).
NullPointerException
- if listener
is
null
.public L[] getListeners()
EventListenerSupport
instance.
protected InvocationHandler createInvocationHandler()
EventListenerSupport.ProxyInvocationHandler
responsible for broadcasting calls
to the managed listeners. Subclasses can override to provide custom behavior.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |