|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectbuoy.event.EventProcessor
public abstract class EventProcessor
This class allows you to use anonymous inner classes as event handlers in unsigned applets and other situations where a SecurityManager prevents use of the AccessibleObject API. If you are writing an application, a signed applet, or any other type of program which is not restricted by a security manager, you can ignore this class.
The Buoy event handling mechanism uses reflection to invoke methods on event listeners. Normally, this can only be done if the method and the class which defines it are both public. Since anonymous inner classes are never public, their methods cannot be directly used for handling events.
These access restrictions can be circumvented by using the AccessibleObject API. This allows any method to be invoked, regardless of whether it is public or not. That is why Buoy applications are free to use private methods, as well as methods of non-public classes, for handling events. Unfortunately, the AccessibleObject API cannot be used when a SecurityManager is in place.
This class provides an alternate method for handling events with anonymous inner classes. To use it,
your inner class extends EventProcessor and overrides handleEvent()
:
widget.addEventLink(CommandEvent.class, new EventProcessor() { public void handleEvent(Object event) { // Handle the event } });
Because processEvent()
is defined by the public class EventProcessor
,
Buoy is free to invoke it by reflection. It then invokes your handleEvent()
method.
This arrangement has only two minor disadvantages compared to the standard one. First, your
handleEvent()
method must be public, which is usually not an issue for an
anonymous inner class. Second, because its signature is fixed by the parent class, it must always
take an argument of type Object
rather than a more specific event type.
Constructor Summary | |
---|---|
EventProcessor()
|
Method Summary | |
---|---|
abstract void |
handleEvent(java.lang.Object event)
|
void |
processEvent(java.lang.Object event)
This simply calls handleEvent(). |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public EventProcessor()
Method Detail |
---|
public void processEvent(java.lang.Object event)
public abstract void handleEvent(java.lang.Object event)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |