Packageorg.springextensions.actionscript.context.support
SVN browsingXMLApplicationContext.as
FisheyeXMLApplicationContext.as
Classpublic class XMLApplicationContext
InheritanceXMLApplicationContext Inheritance AbstractApplicationContext Inheritance DefaultListableObjectFactory Inheritance AbstractObjectFactory Inheritance flash.events.EventDispatcher
ImplementsIConfigurableApplicationContext, IStageProcessorRegistryAware
SubclassesFlexXMLApplicationContext

The XMLApplicationContext is the object factory used in ActionScript projects, in Flex projects you want to use the FlexXMLApplicationContext class.

Important: the schemaLocation within the application context xml file (in the example http://www.springactionscript.org/schema/objects/spring-actionscript-objects-1.0.xsd) should contain the version of spring actionscript you are using.

Using the XMLApplicationContext

The following example retrieves an object from the application context

  public class MyApplication {
      private var _xmlApplicationContext:XMLApplicationContext;
      public function MyApplication() {
      _xmlApplicationContext = new XMLApplicationContext("applicationContext.xml");
      _xmlApplicationContext.addEventListener(Event.COMPLETE, _applicationContextCompleteHandler);
      _xmlApplicationContext.load();
    }
      private function _applicationContextCompleteHandler(e:Event):void {
      var someObject:SomeObject = _xmlApplicationContext.getObject("someObject");
    }
  }
  

The applicationContext.xml could look something like this:

A simple application context xml file

An applicationcontext.xml file with one object defined

  <?xml version="1.0" encoding="utf-8"?>
  <objects xmlns="http://www.springactionscript.org/objects"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xsi:schemaLocation="http://www.springactionscript.org/schema/objects/spring-actionscript-objects-1.0.xsd"
  >
    <object id="someObject" class="package.SomeClass" />
    </objects>
  

Object post processors

In order to manipulate instantiated objects before (or after) they are created you can use object post processors. Post processors can be defined like this:

  <object class="org.springextensions.actionscript.factory.config.SpecialObjectPostProcessor" />
  

The XMLApplicationContext will automatically add them if they implement the IObjectPostProcessor interface.

Authors: Christophe Herreman, Erik Westra
Version: $Revision: 21 $, $Date: 2008-11-01 22:58:42 +0100 (za, 01 nov 2008) $, $Author: dmurat $
Since: 0.1

See also

org.springextensions.actionscript.ioc.factory.config.IObjectPostProcessor
XMLApplicationContext.addObjectPostProcessor()


Documentation reference: instantiating a container


Public Properties
 PropertyDefined by
 InheritedallowObjectDefinitionOverriding : Boolean
Set whether it should be allowed to override object definitions by registering a different definition with the same name, automatically replacing the former.
DefaultListableObjectFactory
 InheritedapplicationDomain : ApplicationDomain
AbstractObjectFactory
 InheritedautowireProcessor : IAutowireProcessor
AbstractObjectFactory
  configLocations : Array
[read-only]
XMLApplicationContext
 InheritedexplicitSingletonNames : Array
The names of the explicit singletons registered in this factory.
AbstractObjectFactory
 InheritedhasDestructionAwareObjectPostProcessors : Boolean
AbstractObjectFactory
 InheritedisDisposed : Boolean
AbstractObjectFactory
 InheritednumObjectDefinitions : uint
The number of object definitions in this registry.
DefaultListableObjectFactory
 InheritednumObjectPostProcessors : int
Returns the number of object post processors.
AbstractObjectFactory
 InheritedobjectDefinitionNames : Array
The names of the registered object definitions.
DefaultListableObjectFactory
 InheritedobjectDefinitions : Object
AbstractObjectFactory
 InheritedobjectFactoryPostProcessors : Array
AbstractApplicationContext
 InheritedobjectPostProcessors : Array
AbstractObjectFactory
 Inheritedparent : IObjectFactory
Optional parent factory that can be used to create objects that can't be created by the current instance.
AbstractObjectFactory
 InheritedparentContext : IApplicationContext
Returns the parent application context or null if no parent is set.
AbstractApplicationContext
  parser : XMLObjectDefinitionsParser
Contains the parser of the XML definitions.
XMLApplicationContext
 Inheritedproperties : Properties
AbstractObjectFactory
  stageProcessorRegistry : IStageProcessorRegistry
XMLApplicationContext
 InheritedtypeConverter : ITypeConverter
The current type converter implementation
AbstractObjectFactory
 InheriteduseParentObjectFactoryPostProcessors : Boolean
AbstractApplicationContext
Protected Properties
 PropertyDefined by
  configurationCompleted : Boolean
XMLApplicationContext
  currentConfigLocation : String = ""
XMLApplicationContext
 InheritedearlySingletonCache : Object
Cache of early cached singletons for circular references
AbstractObjectFactory
 InheritedexplicitSingletonCache : Object
Cache of singleton objects registered without object definition
AbstractObjectFactory
 InheritedreferenceResolvers : Array
Reference resolvers used when creating objects
AbstractObjectFactory
 InheritedsingletonCache : Object
Cache of created singleton objects via an object definition
AbstractObjectFactory
  _xml : XML
XMLApplicationContext
Public Methods
 MethodDefined by
  
XMLApplicationContext(source:* = null, parent:IApplicationContext = null)
Creates a new XMLApplicationContext
XMLApplicationContext
  
addConfig(config:XML):void
XMLApplicationContext
  
addConfigLocation(configLocation:String):void
XMLApplicationContext
  
addEmbeddedConfig(config:Class):void
XMLApplicationContext
  
Adds a namespace handler to the parser of this application context.
XMLApplicationContext
 Inherited
addObjectFactoryPostProcessor(objectFactoryPostProcessor:IObjectFactoryPostProcessor, index:int = -1):void
Adds an IObjectFactoryPostProcessor instance to the current XMLApplicationContext
AbstractApplicationContext
 Inherited
addObjectPostProcessor(objectPostProcessor:IObjectPostProcessor):void

If the specified IObjectPostProcessor implements IApplicationDomainAware the current AbstractObjectFactory.applicationDomain will be injected.

Adds the specified IObjectPostProcessor to the current object factory.
AbstractObjectFactory
 Inherited
addReferenceResolver(referenceResolver:IReferenceResolver):void
This method adds a reference resolver that will be used to resolve property references.
AbstractObjectFactory
 Inherited
canCreate(objectName:String):Boolean
Determines if the object factory is able to create the object with the given name.
AbstractObjectFactory
 Inherited
AbstractObjectFactory
 Inherited
clearObjectFromInternalCache(name:String):Object
Removes an object from the internal object definition cache.
AbstractObjectFactory
 Inherited
containsObject(objectName:String):Boolean
Determines if the object factory contains a definition with the given name.
AbstractObjectFactory
 Inherited
containsObjectDefinition(objectName:String):Boolean
Determines if an object definition with the given name exists
DefaultListableObjectFactory
 Inherited
createInstance(clazz:Class, constructorArguments:Array = null):*
Creates an instance of the specified Class, wires the instance and returns it.
AbstractObjectFactory
  
dispose():void
XMLApplicationContext
 Inherited
getClassForInstance(object:Object):Class
AbstractObjectFactory
 Inherited
getClassForName(className:String):Class
AbstractObjectFactory
 Inherited
getObject(name:String, constructorArguments:Array = null):*
Will retrieve an object by it's name/id If the definition is a singleton it will be retrieved from cache if possible.
AbstractObjectFactory
 Inherited
Returns the object definition registered with the given name.
DefaultListableObjectFactory
 Inherited
getObjectDefinitionsOfType(type:Class):Array
Returns the object definitions in this registry that are of the specified Class.
DefaultListableObjectFactory
 Inherited
getObjectNamesForType(type:Class):Array
Returns the names of all object definitions and explicit singletons in this factory that are of the given type.
DefaultListableObjectFactory
 Inherited
getObjectPostProcessors(objectPostProcessorClass:Class):Array
Retrieves the object processors of the specified Class.
AbstractObjectFactory
 Inherited
getObjectsOfType(type:Class):Object
Returns all object definitions and explicit singletons that are of the given type.
DefaultListableObjectFactory
 Inherited
getType(objectName:String):Class
Returns the type that is defined on the object definition.
AbstractObjectFactory
 Inherited
getUsedTypes():Array
Returns a unique list of all Classes that are used by the IObjectDefinitions in the current IObjectDefinitionRegistry.
DefaultListableObjectFactory
 Inherited
isFactoryObject(objectName:String):Boolean
Determines if an object is a IFactoryObject implementation.
AbstractObjectFactory
 Inherited
isPrototype(objectName:String):Boolean
Determines if the definition with the given name is a prototype.
AbstractObjectFactory
 Inherited
isSingleton(objectName:String):Boolean
Determines if the definition with the given name is a singleton.
AbstractObjectFactory
 Inherited
load():void
AbstractApplicationContext
 Inherited

Checks if the objectdefinition is an implementation of IFactoryObject, if so the factory will be pre-instantiated, not the result of the factory.

Instantiates all definitions that are defined as singleton and are not lazy.
DefaultListableObjectFactory
 Inherited
registerCustomEditor(requiredType:Class, propertyEditor:IPropertyEditor):void
Registers a custom property editor.
AbstractObjectFactory
 Inherited
registerObjectDefinition(objectName:String, objectDefinition:IObjectDefinition):void
Registers the given objectDefinition under the given name.
DefaultListableObjectFactory
 Inherited
registerSingleton(name:String, object:Object):void
AbstractApplicationContext
 Inherited
removeObjectDefinition(objectName:String):void
Removes the definition with the given name from the registry
DefaultListableObjectFactory
 Inherited
Removes the specified IObjectPostProcessor from the current object factory.
AbstractObjectFactory
 Inherited
resolveReference(property:Object):Object
Resolves a property in an object definition.
AbstractObjectFactory
 Inherited
wire(object:*, objectDefinition:IObjectDefinition = null, objectName:String = null):void
AbstractObjectFactory
Protected Methods
 MethodDefined by
  
Checks if the given xml data contains any <import/> tags.
XMLApplicationContext
 Inherited
buildObject(name:String, constructorArguments:Array = null):*
Builds an object for the given name and returns it.
AbstractObjectFactory
  
If the _loader variable is not null the onLoaderComplete and onIOError event handlers are removed.
XMLApplicationContext
 Inherited
clearFromCache(cache:Object, name:String):Object
AbstractObjectFactory
  
completeHandler(event:Event):void
Event.COMPLETE event handler added in context constructor.
XMLApplicationContext
 Inherited
createObjectViaInstanceFactoryMethod(objectName:String, methodName:String, args:Array = null):*
AbstractObjectFactory
 Inherited
createObjectViaStaticFactoryMethod(clazz:Class, applicationDomain:ApplicationDomain, factoryMethodName:String, args:Array = null):*
AbstractObjectFactory
  
doLoad():void
This method will internally do the following:
  • Load all configuration entries (if any)
  • Load all imports (if any)
  • Load all property files (if any)
  • Give the result to the XMLObjectDefinitionsParser
Does the actual loading after the application context has been prepared.
XMLApplicationContext
  
getBaseURL(url:String):String
Returns the base url of the file this loading is loading.
XMLApplicationContext
 Inherited
init():void
AbstractObjectFactory
  
initXMLObjectFactory(source:*):void
Initializes the XMLObjectFactoryInit instance
XMLApplicationContext
 Inherited
Invokes all object factory post processors.
AbstractApplicationContext
 Inherited
loadComplete():void
AbstractApplicationContext
  
loadConfigLocation(configLocation:String):void
Will load a configLocation
XMLApplicationContext
  
parse():void
Parses the xml.
XMLApplicationContext
 Inherited
DefaultListableObjectFactory
 Inherited
Hook method defined in XmlObjectFactory to add the ApplicationContextAwareProcessor.
AbstractApplicationContext
 Inherited
Looks for implementations of IObjectFactoryPostProcessor in the object definition of this context and add an instance of each one as a object factory post processor.
AbstractApplicationContext
 Inherited
Will search all object definitions for implementations of IObjectPostProcessor.
AbstractApplicationContext
 Inherited
DefaultListableObjectFactory
Events
 EventSummaryDefined by
 Inherited Dispatched after an object has been instantiated and wired by the current object factory AbstractObjectFactory
 Inherited Dispatched right before an object is returned by the current object factory AbstractObjectFactory
Public Constants
 ConstantDefined by
 InheritedOBJECT_FACTORY_PREFIX : String = "&"
[static] Used to dereference an IFactoryObject instance and distinguish it from objects created by the IFactoryObject.
AbstractObjectFactory
 InheritedTHIS : String = "this"
[static]
AbstractObjectFactory
Property detail
configLocationsproperty
configLocations:Array  [read-only]

Implementation
    public function get configLocations():Array
configurationCompletedproperty 
protected var configurationCompleted:Boolean
currentConfigLocationproperty 
protected var currentConfigLocation:String = ""
parserproperty 
public var parser:XMLObjectDefinitionsParser

Contains the parser of the XML definitions. The instance is created in the constructor if it does not exist already.

The default value is an instance of XMLObjectDefinitionsParser.

stageProcessorRegistryproperty 
stageProcessorRegistry:IStageProcessorRegistry  [read-write]

Implementation
    public function get stageProcessorRegistry():IStageProcessorRegistry
    public function set stageProcessorRegistry(value:IStageProcessorRegistry):void
_xmlproperty 
protected var _xml:XML
Constructor detail
XMLApplicationContext()constructor
public function XMLApplicationContext(source:* = null, parent:IApplicationContext = null)

Creates a new XMLApplicationContext

Parameters
source:* (default = null)
 
parent:IApplicationContext (default = null)
Method detail
addConfig()method
public function addConfig(config:XML):void

Parameters
config:XML
addConfigLocation()method 
public function addConfigLocation(configLocation:String):void

Parameters
configLocation:String
addEmbeddedConfig()method 
public function addEmbeddedConfig(config:Class):void

Parameters
config:Class
addImportLocationsIfAny()method 
protected function addImportLocationsIfAny(xml:XML):void

Checks if the given xml data contains any <import/> tags. If any are found, their corresponding xml file is added to the load queue.

Parameters
xml:XML
addNamespaceHandler()method 
public function addNamespaceHandler(handler:INamespaceHandler):void

Adds a namespace handler to the parser of this application context.

Parameters
handler:INamespaceHandler
cleanupLoader()method 
protected function cleanupLoader():void

If the _loader variable is not null the onLoaderComplete and onIOError event handlers are removed.

completeHandler()method 
protected function completeHandler(event:Event):void

Event.COMPLETE event handler added in context constructor. Attempts to wire all the components that are already on the stage cache. Assigns the systemManager property with the current application's systemManager and adds the stageWireObjectHandler() method as an Event.ADDED listener on the systemManager.

Parameters
event:Event — The specified Event.COMPLETE event
dispose()method 
public override function dispose():void
doLoad()method 
protected override function doLoad():void

This method will internally do the following:

Does the actual loading after the application context has been prepared. Subclasses should override this method without calling super.doLoad(), since the default behavior will trigger the loadComplete() method immediately. Subclasses should not forget to call loadComplete() after the (asynchronous) loading is done.

See also

getBaseURL()method 
protected function getBaseURL(url:String):String

Returns the base url of the file this loading is loading.

Parameters
url:String

Returns
String
initXMLObjectFactory()method 
protected function initXMLObjectFactory(source:*):void

Initializes the XMLObjectFactoryInit instance

Parameters
source:*
loadConfigLocation()method 
protected function loadConfigLocation(configLocation:String):void

Will load a configLocation

Parameters
configLocation:String
parse()method 
protected function parse():void

Parses the xml.