Packageorg.springextensions.actionscript.eventbus.process
Classpublic class EventHandlerMetadataProcessor
InheritanceEventHandlerMetadataProcessor Inheritance AbstractEventBusMetadataProcessor Inheritance AbstractSpringMetadataProcessor Inheritance 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

EventBus


Public Properties
 PropertyDefined By
 InheritedeventBusUserRegistry : IEventBusUserRegistry
[read-only]
AbstractEventBusMetadataProcessor
 InheritedisDisposed : Boolean
[read-only]
AbstractEventBusMetadataProcessor
 InheritedobjectFactory : IObjectFactory
[write-only]
AbstractEventBusMetadataProcessor
 InheritedprocessBeforeInitialization : Boolean
AbstractSpringMetadataProcessor
Protected Properties
 PropertyDefined By
 InheritedobjFactory : IObjectFactory
AbstractEventBusMetadataProcessor
Public Methods
 MethodDefined 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
Protected Methods
 MethodDefined 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
 Inherited
getTopics(metaData:Metadata, object:Object):Array
AbstractEventBusMetadataProcessor
  
getUseWeak(metaData:Metadata):Boolean
EventHandlerMetadataProcessor
  
processMetaData(object:Object, method:Method, metaData:Metadata):void
EventHandlerMetadataProcessor
Public Constants
 ConstantDefined 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
Protected Constants
 ConstantDefined By
 InheritedCLASS_KEY : String = clazz
[static] The "clazz" property of the EventHandler metadata
AbstractEventBusMetadataProcessor
 InheritedCOMMA : String = ,
[static]
AbstractEventBusMetadataProcessor
 InheritedNAME_KEY : String = name
[static] The "name" property of the EventHandler metadata
AbstractEventBusMetadataProcessor
 InheritedTOPIC_PROPERTIES_KEY : String = topicProperties
[static] The "topicProperties" property of the EventHandler metadata
AbstractEventBusMetadataProcessor
 InheritedTOPICS_KEY : String = topics
[static] The "topic" property of the EventHandler metadata
AbstractEventBusMetadataProcessor
Constructor Detail
EventHandlerMetadataProcessor()Constructor
public function EventHandlerMetadataProcessor()

Creates a new EventHandlerMetaDataPostProcessor instance.

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

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):Vector.<String>

Parameters

metaData:Metadata

Returns
Vector.<String>
getUseWeak()method 
protected function getUseWeak(metaData:Metadata):Boolean

Parameters

metaData:Metadata

Returns
Boolean
process()method 
override public function process(target:Object, metadataName:String, params:Array = null):*

Parameters

target:Object
 
metadataName:String
 
params:Array (default = null)

Returns
*
processMetaData()method 
protected function processMetaData(object:Object, method:Method, metaData:Metadata):void

Parameters

object:Object
 
method:Method
 
metaData:Metadata

Constant Detail
CLASS_KEYConstant
public static const CLASS_KEY:String = clazz

COMMAConstant 
public static const COMMA:String = ,

EMPTYConstant 
public static const EMPTY:String

EVENT_HANDLER_METADATAConstant 
public static const EVENT_HANDLER_METADATA:String = EventHandler

HANDLER_SUFFIXConstant 
public static const HANDLER_SUFFIX:String = Handler

PROPERTIES_KEYConstant 
public static const PROPERTIES_KEY:String = properties

SPACE_CHARConstant 
public static const SPACE_CHAR:String =

TRUE_VALUEConstant 
public static const TRUE_VALUE:String = true

USEWEAK_KEYConstant 
public static const USEWEAK_KEY:String = useWeakReference