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 an EventFilter
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.
Modifier and Type | Method and 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.
|
public Object invoke(Object obj, Method meth, Object[] args) throws Throwable
BuilderEvent
,
it will be passed to the action's execute()
method;
otherwise null will be passed.invoke
in interface InvocationHandler
obj
- the current object instancemeth
- the method to be invokedargs
- the method argumentsThrowable
- for all occurring exceptionspublic static Object create(Class<?> listenerClass, FormAction action)
listenerClass
- the class of the listener interfaceaction
- the action to be invoked (must not be null)public static Object create(Class<?> listenerClass, FormAction action, EventFilter filter)
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)public static Object create(Class<?>[] listenerClasses, FormAction action, EventFilter filter)
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)Copyright © 2016 The JGUIraffe Team. All rights reserved.