NU-CCS-99-04.ps
[ Readme
| Copyright
| Tutorial
| Download
| Feedback
]
Next: How Are the New
Up: How Are the Existing
Previous: Binding Properties
The process of connecting events is, from the
user's point of view, similar to binding bean
properties, e.g., connecting bean events is done in
five steps. However, the underlying mechanism
is much different.
- 1.
- Selecting the source.
As described in Section 1,
selecting a new current-bean will change
the BeanBoxFrame's menu bar based on the
characteristics of the selected bean. In the
Edit menu item, just under the Events item,
there is a submenu that consists of all the
event names the selected bean can announce.
This is obtained using introspection. Under
every event name, there is another submenu
that lists all method names of the listener
interface for the selected event.
- 2.
- Selecting a receiving method from the
event listener interface. When the user clicks
on one of the listener's methods, BeanBox
responds to that ActionEvent by calling its
doEventHookup() method. Based on the
event's name and the name of the listener's
method, that method will then find the
EventSetDescriptor of the selected event and
the Method object for the named method.
- 3.
- Selecting the target. After the user selects an
event, BeanBox waits for the user to click
with the mouse on a target bean. The selected
bean is the bean that will eventually respond
to the event fired by the source bean via the
selected listener's method.
- 4.
- Selecting the method to be invoked.
Once
the target bean has been selected, the BeanBox
will create a new instance of
EventTargetDialog, passing to it the wrappers
of the source and the target beans, the event
descriptor, and the listener's method. The
EventTargetDialog will then introspect the
target bean in hopes of finding a method that
either matches the event listener method or
has no arguments and no return value. If any
matching methods are found, it will make a
list and let the user choose one. The chosen
method will be the one that is invoked on the
target bean in response to the source bean
announcing an event on the selected listener
method.
- 5.
- Making a connection. When the user selects
a target method, all the needed information
for making the connection is available, and
the EventTargetDialog calls the hookup()
method of HookupManager, which will
actually generate the connection. The
connection is established by generating a new
adapter class that implements the listener
interface of the selected event. The
implementation of the listener methods is
trivial. In the selected method case, it calls the
selected method in the target bean, and, in any
other case, the method body is left empty.
HookupManager also takes care of compiling
on the fly the newly created adapter class,
creating a new instance of it, setting the target
object to that instance, and registering it with
the source bean. Creating a new class is
unavoidable because the listener can be of any
user defined type, unlike in the binding-properties
case where the listener is always of
the PropertyChangeListener type.
NU-CCS-99-04.ps
[ Readme
| Copyright
| Tutorial
| Download
| Feedback
]
Next: How Are the New
Up: How Are the Existing
Previous: Binding Properties
David H. Lorenz
3/17/2000