Top Description Inners Constructors Methods
org.apache.commons.lang3.event

public Class EventUtils

extends Object
Class Inheritance
Imports
java.lang.reflect.InvocationHandler, .Method, .Proxy, java.util.Arrays, .HashSet, .Set, org.apache.commons.lang3.reflect.MethodUtils

Provides some useful event-based utility methods.
Since
3.0

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class

Constructor Summary

AccessConstructor and Description
public
EventUtils()
Deprecated TODO Make private in 4.0.

Make private in 4.0.

Method Summary

Modifier and TypeMethod and Description
public static <
the event listener type.
L
>
void
addEventListener(final Object
the event source.
eventSource
,
final Class<L>
the event listener type.
listenerType
,
final L
the listener.
listener
)

Adds an event listener to the specified source.

public static <
the event listener type.
L
>
void
bindEventsToMethod(final Object
the target object.
target
,
final String
the name of the method to be called.
methodName
,
final Object
the object which is generating events (JButton, JList, etc.).
eventSource
,
final Class<L>
the listener interface (ActionListener.class, SelectionListener.class, etc.).
listenerType
,
final String...
the event types (method names) from the listener interface (if none specified, all will be supported).
eventTypes
)

Binds an event listener to a specific method on a specific object.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

EventUtilsback to summary
public EventUtils()

Deprecated

TODO Make private in 4.0.

Make private in 4.0.

Annotations
@Deprecated

Method Detail

addEventListenerback to summary
public static <L> void addEventListener(final Object eventSource, final Class<L> listenerType, final L listener)

Adds an event listener to the specified source. This looks for an "add" method corresponding to the event type (addActionListener, for example).

Parameters
<L>
the event listener type.
eventSource:Object

the event source.

listenerType:Class<L>

the event listener type.

listener:L

the listener.

Exceptions
IllegalArgumentException:
if the object doesn't support the listener type.
bindEventsToMethodback to summary
public static <L> void bindEventsToMethod(final Object target, final String methodName, final Object eventSource, final Class<L> listenerType, final String... eventTypes)

Binds an event listener to a specific method on a specific object.

Parameters
<L>
the event listener type.
target:Object

the target object.

methodName:String

the name of the method to be called.

eventSource:Object

the object which is generating events (JButton, JList, etc.).

listenerType:Class<L>

the listener interface (ActionListener.class, SelectionListener.class, etc.).

eventTypes:String[]

the event types (method names) from the listener interface (if none specified, all will be supported).

org.apache.commons.lang3.event back to summary

private final Class EventUtils.EventBindingInvocationHandler

extends Object
implements InvocationHandler
Class Inheritance
  • java.lang.Object
  • org.apache.commons.lang3.event.EventUtils.EventBindingInvocationHandler
All Implemented Interfaces
java.lang.reflect.InvocationHandler

Field Summary

Modifier and TypeField and Description
private final Set<String>
private final String
private final Object

Constructor Summary

AccessConstructor and Description
pack-priv
EventBindingInvocationHandler(final Object
the target object for method invocations.
target
,
final String
the name of the method to be invoked.
methodName
,
final String[]
the names of the supported event types.
eventTypes
)

Creates a new instance of EventBindingInvocationHandler.

Method Summary

Modifier and TypeMethod and Description
private boolean

Returns:

a flag whether the parameters could be matched.
hasMatchingParametersMethod
(final Method
the listener method invoked.
method
)

Checks whether a method for the passed in parameters can be found.

public Object

Returns:

the result of the method call.
invoke
(final Object
the proxy instance.
proxy
,
final Method
the method to be invoked.
method
,
final Object[]
the parameters for the method invocation.
parameters
)

Implements java.lang.reflect.InvocationHandler.invoke.

Handles a method invocation on the proxy object.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

eventTypesback to summary
private final Set<String> eventTypes
methodNameback to summary
private final String methodName
targetback to summary
private final Object target

Constructor Detail

EventBindingInvocationHandlerback to summary
pack-priv EventBindingInvocationHandler(final Object target, final String methodName, final String[] eventTypes)

Creates a new instance of EventBindingInvocationHandler.

Parameters
target:Object

the target object for method invocations.

methodName:String

the name of the method to be invoked.

eventTypes:String[]

the names of the supported event types.

Method Detail

hasMatchingParametersMethodback to summary
private boolean hasMatchingParametersMethod(final Method method)

Checks whether a method for the passed in parameters can be found.

Parameters
method:Method

the listener method invoked.

Returns:boolean

a flag whether the parameters could be matched.

invokeback to summary
public Object invoke(final Object proxy, final Method method, final Object[] parameters) throws Throwable

Implements java.lang.reflect.InvocationHandler.invoke.

Handles a method invocation on the proxy object.

Parameters
proxy:Object

the proxy instance.

method:Method

the method to be invoked.

parameters:Object[]

the parameters for the method invocation.

Returns:Object

the result of the method call.

Annotations
@Override
Exceptions
Throwable:
if an error occurs
SecurityException:
if an underlying accessible object's method denies the request.
See Also
SecurityManager#checkPermission