Class ListenerMethod
- java.lang.Object
-
- com.vaadin.event.ListenerMethod
-
- All Implemented Interfaces:
Serializable,EventListener
public class ListenerMethod extends Object implements EventListener, Serializable
One registered event listener. This class contains the listener object reference, listened event type, the trigger method to call when the event fires, and the optional argument list to pass to the method and the index of the argument to replace with the event object.
This Class provides several constructors that allow omission of the optional arguments, and giving the listener method directly, or having the constructor to reflect it using merely the name of the method.
It should be pointed out that the method
receiveEvent(EventObject event)is the one that filters out the events that do not match with the given event type and thus do not result in calling of the trigger method.- Since:
- 3.0
- Author:
- Vaadin Ltd.
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description classListenerMethod.MethodExceptionException that wraps an exception thrown by an invoked method.
-
Constructor Summary
Constructors Constructor Description ListenerMethod(Class<?> eventType, SerializableEventListener listener, Method method)Constructs a new event listener from a trigger method.ListenerMethod(Class<?> eventType, SerializableEventListener listener, Method method, Object[] arguments)Constructs a new event listener from the trigger method and it's arguments.ListenerMethod(Class<?> eventType, SerializableEventListener listener, Method method, Object[] arguments, int eventArgumentIndex)Constructs a new event listener from a trigger method, it's arguments and the argument index specifying which one is replaced with the event object when the trigger method is called.ListenerMethod(Class<?> eventType, SerializableEventListener listener, String methodName)Constructs a new event listener from a trigger method name.ListenerMethod(Class<?> eventType, SerializableEventListener listener, String methodName, Object[] arguments)Constructs a new event listener from a trigger method name and it's arguments.ListenerMethod(Class<?> eventType, SerializableEventListener listener, String methodName, Object[] arguments, int eventArgumentIndex)Constructs a new event listener from a trigger method name, it's arguments and the argument index specifying which one is replaced with the event object.ListenerMethod(Class<?> eventType, Object target, Method method)Deprecated.ListenerMethod(Class<?> eventType, Object target, Method method, Object[] arguments)Deprecated.ListenerMethod(Class<?> eventType, Object target, Method method, Object[] arguments, int eventArgumentIndex)Deprecated.ListenerMethod(Class<?> eventType, Object target, String methodName)Deprecated.ListenerMethod(Class<?> eventType, Object target, String methodName, Object[] arguments)Deprecated.ListenerMethod(Class<?> eventType, Object target, String methodName, Object[] arguments, int eventArgumentIndex)Deprecated.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanequals(Object obj)ObjectgetTarget()Returns the target object which contains the trigger method.inthashCode()booleanisOrExtendsType(Class<?> eventType)Compares the type of this ListenerMethod to the given type.booleanisType(Class<?> eventType)Compares the type of this ListenerMethod to the given type.booleanmatches(Class<?> eventType, Object target)Checks if the given object and event match with the ones stored in this listener.booleanmatches(Class<?> eventType, Object target, Method method)Checks if the given object, event and method match with the ones stored in this listener.voidreceiveEvent(EventObject event)Receives one event from theEventRouterand calls the trigger method if it matches with the criteria defined for the listener.
-
-
-
Constructor Detail
-
ListenerMethod
@Deprecated public ListenerMethod(Class<?> eventType, Object target, Method method, Object[] arguments, int eventArgumentIndex) throws IllegalArgumentException
Deprecated.Constructs a new event listener from a trigger method, it's arguments and the argument index specifying which one is replaced with the event object when the trigger method is called.
This constructor gets the trigger method as a parameter so it does not need to reflect to find it out.
- Parameters:
eventType- the event type that is listener listens to. All events of this kind (or its subclasses) result in calling the trigger method.target- the object instance that contains the trigger methodmethod- the trigger methodarguments- the arguments to be passed to the trigger methodeventArgumentIndex- An index to the argument list. This index points out the argument that is replaced with the event object before the argument set is passed to the trigger method. If the eventArgumentIndex is negative, the triggering event object will not be passed to the trigger method, though it is still called.- Throws:
IllegalArgumentException- ifmethodis not a member oftarget.
-
ListenerMethod
public ListenerMethod(Class<?> eventType, SerializableEventListener listener, Method method, Object[] arguments, int eventArgumentIndex) throws IllegalArgumentException
Constructs a new event listener from a trigger method, it's arguments and the argument index specifying which one is replaced with the event object when the trigger method is called.
This constructor gets the trigger method as a parameter so it does not need to reflect to find it out.
- Parameters:
eventType- the event type that is listener listens to. All events of this kind (or its subclasses) result in calling the trigger method.listener- the listener instance that contains the trigger methodmethod- the trigger methodarguments- the arguments to be passed to the trigger methodeventArgumentIndex- An index to the argument list. This index points out the argument that is replaced with the event object before the argument set is passed to the trigger method. If the eventArgumentIndex is negative, the triggering event object will not be passed to the trigger method, though it is still called.- Throws:
IllegalArgumentException- ifmethodis not a member oftarget.
-
ListenerMethod
@Deprecated public ListenerMethod(Class<?> eventType, Object target, String methodName, Object[] arguments, int eventArgumentIndex) throws IllegalArgumentException
Deprecated.Constructs a new event listener from a trigger method name, it's arguments and the argument index specifying which one is replaced with the event object. The actual trigger method is reflected from
object, andjava.lang.IllegalArgumentExceptionis thrown unless exactly one match is found.- Parameters:
eventType- the event type that is listener listens to. All events of this kind (or its subclasses) result in calling the trigger method.target- the object instance that contains the trigger method.methodName- the name of the trigger method. If the object does not contain the method or it contains more than one matching methodsjava.lang.IllegalArgumentExceptionis thrown.arguments- the arguments to be passed to the trigger method.eventArgumentIndex- An index to the argument list. This index points out the argument that is replaced with the event object before the argument set is passed to the trigger method. If the eventArgumentIndex is negative, the triggering event object will not be passed to the trigger method, though it is still called.- Throws:
IllegalArgumentException- unless exactly one matchmethodNameis found intarget.
-
ListenerMethod
public ListenerMethod(Class<?> eventType, SerializableEventListener listener, String methodName, Object[] arguments, int eventArgumentIndex) throws IllegalArgumentException
Constructs a new event listener from a trigger method name, it's arguments and the argument index specifying which one is replaced with the event object. The actual trigger method is reflected from
object, andjava.lang.IllegalArgumentExceptionis thrown unless exactly one match is found.- Parameters:
eventType- the event type that is listener listens to. All events of this kind (or its subclasses) result in calling the trigger method.listener- the listener instance that contains the trigger method.methodName- the name of the trigger method. If the object does not contain the method or it contains more than one matching methodsjava.lang.IllegalArgumentExceptionis thrown.arguments- the arguments to be passed to the trigger method.eventArgumentIndex- An index to the argument list. This index points out the argument that is replaced with the event object before the argument set is passed to the trigger method. If the eventArgumentIndex is negative, the triggering event object will not be passed to the trigger method, though it is still called.- Throws:
IllegalArgumentException- unless exactly one matchmethodNameis found intarget.
-
ListenerMethod
@Deprecated public ListenerMethod(Class<?> eventType, Object target, Method method, Object[] arguments) throws IllegalArgumentException
Deprecated.Constructs a new event listener from the trigger method and it's arguments. Since the the index to the replaced parameter is not specified the event triggering this listener will not be passed to the trigger method.
This constructor gets the trigger method as a parameter so it does not need to reflect to find it out.
- Parameters:
eventType- the event type that is listener listens to. All events of this kind (or its subclasses) result in calling the trigger method.target- the object instance that contains the trigger method.method- the trigger method.arguments- the arguments to be passed to the trigger method.- Throws:
IllegalArgumentException- ifmethodis not a member oftarget.
-
ListenerMethod
public ListenerMethod(Class<?> eventType, SerializableEventListener listener, Method method, Object[] arguments) throws IllegalArgumentException
Constructs a new event listener from the trigger method and it's arguments. Since the the index to the replaced parameter is not specified the event triggering this listener will not be passed to the trigger method.
This constructor gets the trigger method as a parameter so it does not need to reflect to find it out.
- Parameters:
eventType- the event type that is listener listens to. All events of this kind (or its subclasses) result in calling the trigger method.listener- the listener instance that contains the trigger method.method- the trigger method.arguments- the arguments to be passed to the trigger method.- Throws:
IllegalArgumentException- ifmethodis not a member oftarget.
-
ListenerMethod
@Deprecated public ListenerMethod(Class<?> eventType, Object target, String methodName, Object[] arguments) throws IllegalArgumentException
Deprecated.Constructs a new event listener from a trigger method name and it's arguments. Since the the index to the replaced parameter is not specified the event triggering this listener will not be passed to the trigger method.
The actual trigger method is reflected from
target, andjava.lang.IllegalArgumentExceptionis thrown unless exactly one match is found.- Parameters:
eventType- the event type that is listener listens to. All events of this kind (or its subclasses) result in calling the trigger method.target- the object instance that contains the trigger method.methodName- the name of the trigger method. If the object does not contain the method or it contains more than one matching methodsjava.lang.IllegalArgumentExceptionis thrown.arguments- the arguments to be passed to the trigger method.- Throws:
IllegalArgumentException- unless exactly one matchmethodNameis found inobject.
-
ListenerMethod
public ListenerMethod(Class<?> eventType, SerializableEventListener listener, String methodName, Object[] arguments) throws IllegalArgumentException
Constructs a new event listener from a trigger method name and it's arguments. Since the the index to the replaced parameter is not specified the event triggering this listener will not be passed to the trigger method.
The actual trigger method is reflected from
listener, andjava.lang.IllegalArgumentExceptionis thrown unless exactly one match is found.- Parameters:
eventType- the event type that is listener listens to. All events of this kind (or its subclasses) result in calling the trigger method.listener- the listener instance that contains the trigger method.methodName- the name of the trigger method. If the object does not contain the method or it contains more than one matching methodsjava.lang.IllegalArgumentExceptionis thrown.arguments- the arguments to be passed to the trigger method.- Throws:
IllegalArgumentException- unless exactly one matchmethodNameis found inobject.
-
ListenerMethod
@Deprecated public ListenerMethod(Class<?> eventType, Object target, Method method) throws IllegalArgumentException
Deprecated.Constructs a new event listener from a trigger method. Since the argument list is unspecified no parameters are passed to the trigger method when the listener is triggered.
This constructor gets the trigger method as a parameter so it does not need to reflect to find it out.
- Parameters:
eventType- the event type that is listener listens to. All events of this kind (or its subclasses) result in calling the trigger method.target- the object instance that contains the trigger method.method- the trigger method.- Throws:
IllegalArgumentException- ifmethodis not a member ofobject.
-
ListenerMethod
public ListenerMethod(Class<?> eventType, SerializableEventListener listener, Method method) throws IllegalArgumentException
Constructs a new event listener from a trigger method. Since the argument list is unspecified no parameters are passed to the trigger method when the listener is triggered.
This constructor gets the trigger method as a parameter so it does not need to reflect to find it out.
- Parameters:
eventType- the event type that is listener listens to. All events of this kind (or its subclasses) result in calling the trigger method.listener- the listener instance that contains the trigger method.method- the trigger method.- Throws:
IllegalArgumentException- ifmethodis not a member ofobject.
-
ListenerMethod
@Deprecated public ListenerMethod(Class<?> eventType, Object target, String methodName) throws IllegalArgumentException
Deprecated.Constructs a new event listener from a trigger method name. Since the argument list is unspecified no parameters are passed to the trigger method when the listener is triggered.
The actual trigger method is reflected from
object, andjava.lang.IllegalArgumentExceptionis thrown unless exactly one match is found.- Parameters:
eventType- the event type that is listener listens to. All events of this kind (or its subclasses) result in calling the trigger method.target- the object instance that contains the trigger method.methodName- the name of the trigger method. If the object does not contain the method or it contains more than one matching methodsjava.lang.IllegalArgumentExceptionis thrown.- Throws:
IllegalArgumentException- unless exactly one matchmethodNameis found intarget.
-
ListenerMethod
public ListenerMethod(Class<?> eventType, SerializableEventListener listener, String methodName) throws IllegalArgumentException
Constructs a new event listener from a trigger method name. Since the argument list is unspecified no parameters are passed to the trigger method when the listener is triggered.
The actual trigger method is reflected from
listener, andjava.lang.IllegalArgumentExceptionis thrown unless exactly one match is found.- Parameters:
eventType- the event type that is listener listens to. All events of this kind (or its subclasses) result in calling the trigger method.listener- the listener instance that contains the trigger method.methodName- the name of the trigger method. If the object does not contain the method or it contains more than one matching methodsjava.lang.IllegalArgumentExceptionis thrown.- Throws:
IllegalArgumentException- unless exactly one matchmethodNameis found intarget.
-
-
Method Detail
-
receiveEvent
public void receiveEvent(EventObject event)
Receives one event from theEventRouterand calls the trigger method if it matches with the criteria defined for the listener. Only the events of the same or subclass of the specified event class result in the trigger method to be called.- Parameters:
event- the fired event. Unless the trigger method's argument list and the index to the to be replaced argument is specified, this event will not be passed to the trigger method.
-
matches
public boolean matches(Class<?> eventType, Object target)
Checks if the given object and event match with the ones stored in this listener.- Parameters:
target- the object to be matched against the object stored by this listener.eventType- the type to be tested for equality against the type stored by this listener.- Returns:
trueiftargetis the same object as the one stored in this object andeventTypeequals the event type stored in this object. *
-
matches
public boolean matches(Class<?> eventType, Object target, Method method)
Checks if the given object, event and method match with the ones stored in this listener.- Parameters:
target- the object to be matched against the object stored by this listener.eventType- the type to be tested for equality against the type stored by this listener.method- the method to be tested for equality against the method stored by this listener.- Returns:
trueiftargetis the same object as the one stored in this object,eventTypeequals with the event type stored in this object andmethodequals with the method stored in this object.
-
isType
public boolean isType(Class<?> eventType)
Compares the type of this ListenerMethod to the given type.- Parameters:
eventType- The type to compare with- Returns:
- true if this type of this ListenerMethod matches the given type, false otherwise
-
isOrExtendsType
public boolean isOrExtendsType(Class<?> eventType)
Compares the type of this ListenerMethod to the given type.- Parameters:
eventType- The type to compare with- Returns:
- true if this event type can be assigned to the given type, false otherwise
-
getTarget
public Object getTarget()
Returns the target object which contains the trigger method.- Returns:
- The target object
-
-