| Package | org.springextensions.actionscript.ioc.factory.config |
| SVN browsing | EventHandlerMetaDataPostProcessor.as |
| Fisheye | EventHandlerMetaDataPostProcessor.as |
| Class | public class EventHandlerMetaDataPostProcessor |
| Inheritance | EventHandlerMetaDataPostProcessor AbstractMetadataProcessor |
| Implements | IDisposable, IMetadataProcessor, IObjectFactoryAware |
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 eventhandler is for a specific event class, add the fully qualified classname to the metadata like this: [EventHandler(clazz="com.classes.events.MyEventClass")].
These metadata annotations can be stacked, so this is also valid:
[EventHandler(class="com.classes.events.MyEventClass1")] [EventHandler(class="com.classes.events.MyEventClass2")]
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
Documentation reference: eventbus event handling using metadata annotations
| Property | Defined by | ||
|---|---|---|---|
| isDisposed : Boolean [read-only]
| EventHandlerMetaDataPostProcessor | ||
![]() | metadataNames : Array
The names of the metadata annotations that the current
IMetadataProcessor processes. | AbstractMetadataProcessor | |
| objectFactory : IObjectFactory
[write-only]
| EventHandlerMetaDataPostProcessor | ||
![]() | processBeforeInitialization : Boolean
If
true the IMetadataProcessor instance will be able to process the annotated
instance before it has been initialized by the container. | AbstractMetadataProcessor | |
| Method | Defined by | ||
|---|---|---|---|
|
Creates a new
EventHandlerMetaDataPostProcessor instance. | EventHandlerMetaDataPostProcessor | ||
|
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. | EventHandlerMetaDataPostProcessor | ||
|
process(instance:Object, container:IMetaDataContainer, name:String, objectName:String):void
| EventHandlerMetaDataPostProcessor | ||
|
removeEventClassListener(eventClass:Class, handler:Function = null):void
| EventHandlerMetaDataPostProcessor | ||
|
removeEventListener(eventName:String, handler:Function = null):void
| EventHandlerMetaDataPostProcessor | ||
| Method | Defined by | ||
|---|---|---|---|
|
getEventClassName(method:Method, metaData:MetaData):String
| EventHandlerMetaDataPostProcessor | ||
|
getEventName(method:Method, metaData:MetaData):String
Returns the name of the event to listen to.
| EventHandlerMetaDataPostProcessor | ||
|
getEventNameFromMetaData(metaData:MetaData):String
Returns the name of the event from the given metadata.
| EventHandlerMetaDataPostProcessor | ||
|
getEventNameFromMethod(method:Method):String
Returns the event name based on the given method.
| EventHandlerMetaDataPostProcessor | ||
|
getProperties(metaData:MetaData):Array
| EventHandlerMetaDataPostProcessor | ||
![]() |
init(processBefore:Boolean, metadataNames:Array):void
Initializes the current
AbstractMetadataProcessor. | AbstractMetadataProcessor | |
|
processMetaData(object:Object, method:Method, metaData:MetaData):void
| EventHandlerMetaDataPostProcessor | ||
|
trim(element:*, index:int, arr:Array):void
| EventHandlerMetaDataPostProcessor | ||
| isDisposed | property |
isDisposed:Boolean [read-only]Implementation
public function get isDisposed():Boolean
| objectFactory | property |
objectFactory:IObjectFactory [write-only]Implementation
public function set objectFactory(value:IObjectFactory):void
| EventHandlerMetaDataPostProcessor | () | constructor |
public function EventHandlerMetaDataPostProcessor()
Creates a new EventHandlerMetaDataPostProcessor instance.
| dispose | () | method |
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(method:Method, metaData:MetaData):StringParameters
method:Method |
|
metaData:MetaData |
String |
| getEventName | () | method |
protected function getEventName(method:Method, metaData:MetaData):StringReturns the name of the event to listen to.
Parametersmethod: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.
ParametersmetaData: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".
Parametersmethod:Method |
String |
| getProperties | () | method |
protected function getProperties(metaData:MetaData):ArrayParameters
metaData:MetaData |
Array |
| process | () | method |
public override function process(instance:Object, container:IMetaDataContainer, name:String, objectName:String):voidParameters
instance:Object |
|
container:IMetaDataContainer |
|
name:String |
|
objectName:String |
| processMetaData | () | method |
protected function processMetaData(object:Object, method:Method, metaData:MetaData):voidParameters
object:Object |
|
method:Method |
|
metaData:MetaData |
| removeEventClassListener | () | method |
public function removeEventClassListener(eventClass:Class, handler:Function = null):voidParameters
eventClass:Class |
|
handler:Function (default = null) |
| removeEventListener | () | method |
public function removeEventListener(eventName:String, handler:Function = null):voidParameters
eventName:String |
|
handler:Function (default = null) |
| trim | () | method |
protected function trim(element:*, index:int, arr:Array):voidParameters
element:* |
|
index:int |
|
arr:Array |