Class ActionInvoker
- java.lang.Object
-
- net.sf.jguiraffe.gui.builder.action.ActionInvoker
-
- All Implemented Interfaces:
InvocationHandler
public class ActionInvoker extends Object implements InvocationHandler
A class that allows to combine actions with event listeners.
This class can be used to create an event listener proxy for an arbitrary event listener interface that will delegate to a specified
FormAction
object. By defining anEventFilter
it can be exactly specified, which event should cause the action to be invoked.The purpose of this class is to serve as a bridge between the event listener API and the action API. This is especially useful when event listeners are to be defined in builder scripts: Then it is easy to route to actions, which are defined by action tags anyway.
Internally this class makes use of the Proxy mechanism supported by Java 1.3 and higher. For the passed in event listener interface(s) a proxy object is created. Every invocation of one of the proxy's methods will cause the specified filter to be called to check whether the current event object matches the filter's criteria. If this is the case and if the action is enabled, its
execute()
method will be invoked.Instances of
ActionInvoker
should be created using the static factory methods. These methods return an object, which can be passed to one of the interfaces that was passed to the factory method. Then it can be registered as the corresponding event listener at the desired form component.- Version:
- $Id: ActionInvoker.java 205 2012-01-29 18:29:57Z oheger $
- Author:
- Oliver Heger
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static Object
create(Class<?>[] listenerClasses, FormAction action, EventFilter filter)
Creates an action invoker proxy that implements all the specified listener interfaces.static Object
create(Class<?> listenerClass, FormAction action)
Creates an action invoker proxy for the specified listener interface that will invoke the given action whenever a method of the listener interface is called.static Object
create(Class<?> listenerClass, FormAction action, EventFilter filter)
Creates an action invoker proxy for the specified listener interface that will invoke the given action when an event is triggered that is accepted by the passed in filter.Object
invoke(Object obj, Method meth, Object[] args)
Callback method that is invoked whenever a method on an associated event listener interface is called.
-
-
-
Method Detail
-
invoke
public Object invoke(Object obj, Method meth, Object[] args) throws Throwable
Callback method that is invoked whenever a method on an associated event listener interface is called. This implementation will pass the first method argument (or null if there is none) to the associated event filter. If it is accepted by the filter, the associated action will be executed if it is enabled. If the first method argument is of type
, it will be passed to the action'sBuilderEvent
execute()
method; otherwise null will be passed.- Specified by:
invoke
in interfaceInvocationHandler
- Parameters:
obj
- the current object instancemeth
- the method to be invokedargs
- the method arguments- Returns:
- the method's return value (null in this case)
- Throws:
Throwable
- for all occurring exceptions
-
create
public static Object create(Class<?> listenerClass, FormAction action)
Creates an action invoker proxy for the specified listener interface that will invoke the given action whenever a method of the listener interface is called. The returned object can be casted to the specified listener class and then registered at a component.- Parameters:
listenerClass
- the class of the listener interfaceaction
- the action to be invoked (must not be null)- Returns:
- the event listener proxy
-
create
public static Object create(Class<?> listenerClass, FormAction action, EventFilter filter)
Creates an action invoker proxy for the specified listener interface that will invoke the given action when an event is triggered that is accepted by the passed in filter. The returned object can be casted to the specified listener class and then registered at a component.- Parameters:
listenerClass
- the class of the listener interfaceaction
- the action to be invoked (must not be null)filter
- the event filter (can be null, then all events will be accepted)- Returns:
- the event listener proxy
-
create
public static Object create(Class<?>[] listenerClasses, FormAction action, EventFilter filter)
Creates an action invoker proxy that implements all the specified listener interfaces. It will invoke the given action when an event is triggered that is accepted by the passed in filter. The returned object can be casted to all the specified listener classes and then registered at a component.- Parameters:
listenerClasses
- an array of the classes of the listener interfacesaction
- the action to be invoked (must not be null)filter
- the event filter (can be null, then all events will be accepted)- Returns:
- the event listener proxy
-
-