Spring Actionscript offers an easy way to process actionscript metadata annotations. The main interface of interest for this task is IMetadataProcessor Describes an object that can process an instance that is annotated with specific metadata..
Here's what it looks like up close:
public interface IMetadataProcessor {
function get metadataNames():Array;
function get processBeforeInitialization():Boolean;
function process(instance:Object, container:IMetaDataContainer, name:String, objectName:String):void;
}The basic properties have already been implemented by the AbstractMetadataProcessor Abstract base class for <code>IMetadataProcessor</code> implementations. base class which can be used for convenience.
Let's take a look at the various properties and methods and see what they do and mean.
metadataNames - This is an Array of metadata names that will trigger the process() method of the IMetadataProcessor Describes an object that can process an instance that is annotated with specific metadata. implementation.
processBeforeInitialization - When set to true the IMetadataProcessor Describes an object that can process an instance that is annotated with specific metadata. instance will be able to process the annotated instance before it has been initialized by the Spring Actionscript container.
process Processes the specified <code>Object</code>. - This method will contain the processing logic that is associated with the various names specified by the metadataNames property.
The process() Processes the specified <code>Object</code>. method will naturally be the most important aspect in any implementation of the IMetadataProcessor Describes an object that can process an instance that is annotated with specific metadata. interface. It receives three parameters:
instance - This is the object instance that was encountered with the specified metadata name on its class or its methods or properties.
container - The IMetaDataContainer that is associated with the instance, this can be any of these subclasses: Type, Method, Accessor, Constant, Variable.
name - The metadata name that triggered the invocation of the process() Processes the specified <code>Object</code>. method.
objectName - The name of the object definition in the Spring Actionscript container.
To use the IMetadataProcessor Describes an object that can process an instance that is annotated with specific metadata. in an application add the implementation as an object definition to the application context configuration like this:
<object id="mvcEventsProcessor" class="org.springextensions.actionscript.core.mvc.MVCRouteEventsMetaDataProcessor"/>
After that the processor is ready to go, when used in combination
with the autowiring stage processor (as described in this section) it will
process both objects created by the container and components that were
added to the stage.
Credit where credit is due: This type of metadata handling was pioneered by the Swiz Framework team, the Spring Actionscript team both acknowledges and appreciates their work.
The order in which IMetadataProcessors Describes an object that can process an instance that is annotated with specific metadata. are executed is controlled by the IOrdered Interface that can be implemented by objects that should be orderable, for example in a Collection. interface. See the 'Controlling collection order' section for more information on this interface.