Packageorg.springextensions.actionscript.ioc.factory.config
SVN browsingEventHandlerMetaDataPostProcessor.as
FisheyeEventHandlerMetaDataPostProcessor.as
Classpublic class EventHandlerMetaDataPostProcessor
InheritanceEventHandlerMetaDataPostProcessor Inheritance AbstractMetadataProcessor
ImplementsIDisposable, 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

EventBus


Documentation reference: eventbus event handling using metadata annotations


Public Properties
 PropertyDefined by
  isDisposed : Boolean
[read-only]
EventHandlerMetaDataPostProcessor
 InheritedmetadataNames : Array
The names of the metadata annotations that the current IMetadataProcessor processes.
AbstractMetadataProcessor
  objectFactory : IObjectFactory
[write-only]
EventHandlerMetaDataPostProcessor
 InheritedprocessBeforeInitialization : Boolean
If true the IMetadataProcessor instance will be able to process the annotated instance before it has been initialized by the container.
AbstractMetadataProcessor
Public Methods
 MethodDefined 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
Protected Methods
 MethodDefined 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
 Inherited
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
Property detail
isDisposedproperty
isDisposed:Boolean  [read-only]Implementation
    public function get isDisposed():Boolean
objectFactoryproperty 
objectFactory:IObjectFactory  [write-only]Implementation
    public function set objectFactory(value:IObjectFactory):void
Constructor detail
EventHandlerMetaDataPostProcessor()constructor
public function EventHandlerMetaDataPostProcessor()

Creates a new EventHandlerMetaDataPostProcessor instance.

Method detail
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

Returns
String
getEventName()method 
protected function getEventName(method:Method, metaData:MetaData):String

Returns the name of the event to listen to.

Parameters
method:Method
 
metaData:MetaData

Returns
String — the name of the event
getEventNameFromMetaData()method 
protected function getEventNameFromMetaData(metaData:MetaData):String

Returns 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

Returns
String
getEventNameFromMethod()method 
protected function getEventNameFromMethod(method:Method):String

Returns 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

Returns
String
getProperties()method 
protected function getProperties(metaData:MetaData):ArrayParameters
metaData:MetaData

Returns
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