Packageorg.as3commons.reflect
Classpublic class MetadataUtils
InheritanceMetadataUtils Inheritance Object

This class provides utility methods concerning metadata. Retrieved metadata is cached and cleared with the set interval.

See also

CLEAR_CACHE_INTERVAL


Public Properties
 PropertyDefined By
  CLEAR_CACHE_INTERVAL : uint = 60000
[static] The interval (in miliseconds) at which the cache will be cleared.
MetadataUtils
Public Methods
 MethodDefined By
  
clearCache():void
[static] Allows you to clear the internal cache.
MetadataUtils
  
findClassMetadata(clazz:Class, metadataName:String, applicationDomain:ApplicationDomain = null):Metadata
[static] Find a single Metadata of metadataName from the supplied Class, traversing its interfaces and super classes if no annotation can be found on the given class itself.
MetadataUtils
  
findMetadataDeclaringClass(metadataName:String, clazz:Class, applicationDomain:ApplicationDomain = null):Class
[static] Find the first Class in the inheritance hierarchy of the specified clazz (including the specified clazz itself) that declares metdata for the specified metadataName, or null if not found.
MetadataUtils
  
getFromObject(object:Object):XML
[static] Will return the metadata for the given object or class.
MetadataUtils
  
getFromString(className:String, applicationDomain:ApplicationDomain = null):XML
[static] Will retrieve the metadata for the given class.
MetadataUtils
Property Detail
CLEAR_CACHE_INTERVALproperty
public static var CLEAR_CACHE_INTERVAL:uint = 60000

The interval (in miliseconds) at which the cache will be cleared. Note that this value is only used on the first call to getFromObject.

The default value is 60000 (one minute).

Method Detail
clearCache()method
public static function clearCache():void

Allows you to clear the internal cache.

findClassMetadata()method 
public static function findClassMetadata(clazz:Class, metadataName:String, applicationDomain:ApplicationDomain = null):Metadata

Find a single Metadata of metadataName from the supplied Class, traversing its interfaces and super classes if no annotation can be found on the given class itself.

The algorithm operates as follows: Searches for an annotation on the given class and returns it if found. Else searches all interfaces that the given class declares, returning the annotation from the first matching candidate, if any. Else proceeds with introspection of the superclass of the given class, checking the superclass itself; if no annotation found there, proceeds with the interfaces that the superclass declares. Recursing up through the entire superclass hierarchy if no match is found.

Parameters

clazz:Class — the class on which to look for the metadata
 
metadataName:String — the name of the metadata for which to look
 
applicationDomain:ApplicationDomain (default = null)

Returns
Metadata — the metadata tag if found, or null if none is found
findMetadataDeclaringClass()method 
public static function findMetadataDeclaringClass(metadataName:String, clazz:Class, applicationDomain:ApplicationDomain = null):Class

Find the first Class in the inheritance hierarchy of the specified clazz (including the specified clazz itself) that declares metdata for the specified metadataName, or null if not found. If the supplied clazz is null, null will be returned.

If the supplied clazz is an interface, only the interface itself will be checked; the inheritance hierarchy for interfaces will not be traversed.

Parameters

metadataName:String — the name corresponding to the metadata tag
 
clazz:Class — the Class object corresponding to the class on which to check for the annotation, or null.
 
applicationDomain:ApplicationDomain (default = null)

Returns
Class — the first Class in the inheritance hierarchy of the specified clazz which declares an annotation for the specified metadataName, or null if not found.
getFromObject()method 
public static function getFromObject(object:Object):XML

Will return the metadata for the given object or class. If metadata has already been requested for this type, it will be retrieved from cache. Note that the metadata will allways be that of the class, even if you pass an instance.

In order to get instance specific metadata, use the 'factory' property.

The reason we do not allow retrieval of instance metadata is because then we would need to cache the metadata double. Metadata takes up a significant amount of memory.

Parameters

object:Object — The object from which you want to grab the metadata

Returns
XML — The class metadata of the given object.
getFromString()method 
public static function getFromString(className:String, applicationDomain:ApplicationDomain = null):XML

Will retrieve the metadata for the given class. Note that in order to access properties and methods you need to grab the 'factory' part of the metadata.

Parameters

className:String — The name of the class that you want to retrieve metadata from. The className may be in the following forms: package.Class or package::Class
 
applicationDomain:ApplicationDomain (default = null)

Returns
XML