| Package | org.springextensions.actionscript.eventbus.process |
| Class | public class EventHandlerMetadataProcessor |
| Inheritance | EventHandlerMetadataProcessor AbstractEventBusMetadataProcessor AbstractSpringMetadataProcessor org.as3commons.metadata.process.impl.AbstractMetadataProcessor |
| Subclasses | EventHandlerMetadataDestroyer |
IMetadataProcessor implementation that adds EventBus event handlers based on the annotations found in the object's class.
These annotations mark a public method as an event handler of an event dispatched on the EventBus.
The metadata annotation takes the form of [EventHandler] in its simplest form. The name of the event will then be deducted from the method name. For instance, if you have an event called "saveUser", the handler is supposed to have the same name, or the same name with "Handler" attached to it. So "saveUser" and "saveUserHandler" are both valid handler names.
If the name of the event and the event handler are different, or for clarity reasons, you can specify the event name via the "name" argument on the metadata. For example [EventHandler(name="saveUser")] is a valid form. You can also leave out the key of the name argument and just type [EventHandler("saveUser")].
By default, an event handler function is expected to have a single argument of type Event (or any subclass).
However if the event argument has additional properties, you can specify these properties directly as
arguments of the handler function. For example if you have a UserEvent class with a property "user" of type
User, the handler signature can look like this: function saveUser(user:User):void
If the custom event class has multiple properties of the same type, for example a "userA" and "userB" property both of type User, Spring ActionScript will not be able to figure out what properties correspond to the arguments of the handler function. In that case you need to specify the name of the properties in the metadata. e.g. [EventHandler(properties="userA, userB")]
If the event handler is for a specific event class, add the fully qualified classname to the metadata like this: [EventHandler(clazz="com.classes.events.MyEventClass")].
To determine if the event listener will be added using a weak reference, set the useWeakReference property like this:
[EventHandler(clazz="com.classes.events.MyEventClass",useWeakReference="true")]
To subscribe the event listener for a specific topic or topics, use this extra argument: [EventHandler(clazz="com.classes.events.MyEventClass",topics="topic1,topic2")]
These metadata annotations can be stacked, so this is also valid:
[EventHandler(clazz="com.classes.events.MyEventClass1")] [EventHandler(clazz="com.classes.events.MyEventClass2",topics="topic1")]
Finally, to use the EventHandlerMetaDataPostProcessor in an application, add an object definition
to the XML configuration like this:
<object id="eventhandlerProcessor" class="org.springextensions.actionscript.ioc.factory.config.EventHandlerMetaDataPostProcessor"/>
This way the processor will be automatically registered with the application context.
See also
| Method | Defined By | ||
|---|---|---|---|
Creates a new EventHandlerMetaDataPostProcessor instance. | EventHandlerMetadataProcessor | ||
dispose():void [override]
Loops through all the event handlers that have been previously added by the
current EventHandlerMetaDataPostProcessor, removes them and
clears and nulls the internal cache. | EventHandlerMetadataProcessor | ||
process(target:Object, metadataName:String, params:Array = null):* [override]
| EventHandlerMetadataProcessor | ||
| Method | Defined By | ||
|---|---|---|---|
getEventClassName(metaData:Metadata):String | EventHandlerMetadataProcessor | ||
getEventName(method:Method, metaData:Metadata):String
Returns the name of the event to listen to. | EventHandlerMetadataProcessor | ||
getEventNameFromMetaData(metaData:Metadata):String
Returns the name of the event from the given metadata. | EventHandlerMetadataProcessor | ||
getEventNameFromMethod(method:Method):String
Returns the event name based on the given method. | EventHandlerMetadataProcessor | ||
getProperties(metaData:Metadata):Vector.<String> | EventHandlerMetadataProcessor | ||
![]() | getTopics(metaData:Metadata, object:Object):Array | AbstractEventBusMetadataProcessor | |
getUseWeak(metaData:Metadata):Boolean | EventHandlerMetadataProcessor | ||
processMetaData(object:Object, method:Method, metaData:Metadata):void | EventHandlerMetadataProcessor | ||
| Constant | Defined By | ||
|---|---|---|---|
| CLASS_KEY : String = clazz [static] | EventHandlerMetadataProcessor | ||
| COMMA : String = , [static] | EventHandlerMetadataProcessor | ||
| EMPTY : String [static] | EventHandlerMetadataProcessor | ||
| EVENT_HANDLER_METADATA : String = EventHandler [static] | EventHandlerMetadataProcessor | ||
| HANDLER_SUFFIX : String = Handler [static] | EventHandlerMetadataProcessor | ||
| PROPERTIES_KEY : String = properties [static] | EventHandlerMetadataProcessor | ||
| SPACE_CHAR : String = [static] | EventHandlerMetadataProcessor | ||
| TRUE_VALUE : String = true [static] | EventHandlerMetadataProcessor | ||
| USEWEAK_KEY : String = useWeakReference [static] | EventHandlerMetadataProcessor | ||
| EventHandlerMetadataProcessor | () | Constructor |
public function EventHandlerMetadataProcessor()
Creates a new EventHandlerMetaDataPostProcessor instance.
| dispose | () | method |
override public function dispose():void
Loops through all the event handlers that have been previously added by the
current EventHandlerMetaDataPostProcessor, removes them and
clears and nulls the internal cache.
| getEventClassName | () | method |
protected function getEventClassName(metaData:Metadata):String
Parameters
metaData:Metadata |
String —
|
| getEventName | () | method |
protected function getEventName(method:Method, metaData:Metadata):StringReturns the name of the event to listen to.
Parameters
method:Method | |
metaData:Metadata |
String — the name of the event
|
| getEventNameFromMetaData | () | method |
protected function getEventNameFromMetaData(metaData:Metadata):StringReturns the name of the event from the given metadata. This will either be the value of the argument with the "name" key, or the value of the argument without a key.
Parameters
metaData:Metadata |
String |
| getEventNameFromMethod | () | method |
protected function getEventNameFromMethod(method:Method):StringReturns the event name based on the given method. We assume that the name of the method corresponds to a event, or to the name of the event followed by "Handler".
Parameters
method:Method |
String |
| getProperties | () | method |
protected function getProperties(metaData:Metadata):Vector.<String>
Parameters
metaData:Metadata |
Vector.<String> —
|
| getUseWeak | () | method |
protected function getUseWeak(metaData:Metadata):Boolean
Parameters
metaData:Metadata |
Boolean —
|
| process | () | method |
override public function process(target:Object, metadataName:String, params:Array = null):*
Parameters
target:Object | |
metadataName:String | |
params:Array (default = null) |
* |
| processMetaData | () | method |
protected function processMetaData(object:Object, method:Method, metaData:Metadata):void
Parameters
object:Object | |
method:Method | |
metaData:Metadata |
| CLASS_KEY | Constant |
public static const CLASS_KEY:String = clazz| COMMA | Constant |
public static const COMMA:String = ,| EMPTY | Constant |
public static const EMPTY:String| EVENT_HANDLER_METADATA | Constant |
public static const EVENT_HANDLER_METADATA:String = EventHandler| HANDLER_SUFFIX | Constant |
public static const HANDLER_SUFFIX:String = Handler| PROPERTIES_KEY | Constant |
public static const PROPERTIES_KEY:String = properties| SPACE_CHAR | Constant |
public static const SPACE_CHAR:String = | TRUE_VALUE | Constant |
public static const TRUE_VALUE:String = true| USEWEAK_KEY | Constant |
public static const USEWEAK_KEY:String = useWeakReference