Packageorg.springextensions.actionscript.context.support
SVN browsingAbstractApplicationContext.as
FisheyeAbstractApplicationContext.as
Classpublic class AbstractApplicationContext
InheritanceAbstractApplicationContext Inheritance DefaultListableObjectFactory Inheritance AbstractObjectFactory Inheritance flash.events.EventDispatcher
ImplementsIConfigurableApplicationContext
SubclassesMXMLApplicationContext, XMLApplicationContext

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
 InheritedexplicitSingletonNames : Array
The names of the explicit singletons registered in this factory.
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
 Inheritedparent : IObjectFactory
AbstractObjectFactory
  parentContext : IApplicationContext
[read-only] Returns the parent application context or null if no parent is set.
AbstractApplicationContext
 Inheritedproperties : Properties
AbstractObjectFactory
 InheritedtypeConverter : ITypeConverter
The current type converter implementation
AbstractObjectFactory
Protected Properties
 PropertyDefined by
 InheritedearlySingletonCache : Object
Cache of early cached singletons for circular references
AbstractObjectFactory
 InheritedexplicitSingletonCache : Object
Cache of singleton objects registered without object definition
AbstractObjectFactory
 InheritedobjectPostProcessors : Array
Object post processors to apply when creating objects
AbstractObjectFactory
 InheritedreferenceResolvers : Array
Reference resolvers used when creating objects
AbstractObjectFactory
 InheritedsingletonCache : Object
Cache of created singleton objects via an object definition
AbstractObjectFactory
Public Methods
 MethodDefined by
  
Creates a new AbstractApplicationContext
AbstractApplicationContext
  
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 an object postprocessor to this 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
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
 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
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
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
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
  
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
  
registerSingleton(name:String, object:Object):void
AbstractApplicationContext
 Inherited
removeObjectDefinition(objectName:String):void
Removes the definition with the given name from the registry
DefaultListableObjectFactory
 Inherited
resolveReference(property:Object):Object
Resolves a property in an object definition.
AbstractObjectFactory
 Inherited
wire(object:*, objectDefinition:IObjectDefinition, objectName:String = null):void
AbstractObjectFactory
Protected Methods
 MethodDefined by
 Inherited
buildObject(name:String, constructorArguments:Array = null):*
Builds an object for the given name and returns it.
AbstractObjectFactory
 Inherited
createObjectViaInstanceFactoryMethod(objectName:String, methodName:String, args:Array = null):*
AbstractObjectFactory
 Inherited
createObjectViaStaticFactoryMethod(clazz:Class, applicationDomain:ApplicationDomain, factoryMethodName:String, args:Array = null):*
AbstractObjectFactory
  
Invokes all object factory post processors.
AbstractApplicationContext
  
loadComplete():void
TODO
AbstractApplicationContext
  
Hook method defined in XmlObjectFactory to add the ApplicationContextAwareProcessor.
AbstractApplicationContext
  
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
  
Will search all object definitions for implementations of IObjectPostProcessor.
AbstractApplicationContext
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
parentContextproperty
parentContext:IApplicationContext  [read-only]

Returns the parent application context or null if no parent is set.

Implementation
    public function get parentContext():IApplicationContext
Constructor detail
AbstractApplicationContext()constructor
public function AbstractApplicationContext(parent:IApplicationContext = null)

Creates a new AbstractApplicationContext

Parameters
parent:IApplicationContext (default = null)
Method detail
addObjectFactoryPostProcessor()method
public function addObjectFactoryPostProcessor(objectFactoryPostProcessor:IObjectFactoryPostProcessor, index:int = -1):void

Adds an IObjectFactoryPostProcessor instance to the current XMLApplicationContext

Parameters
objectFactoryPostProcessor:IObjectFactoryPostProcessor — An IObjectFactoryPostProcessor instance which is allowed to read the configuration metadata and potentially change it before the container has actually instantiated any other objects.
 
index:int (default = -1) — An optional index for the objectFactoryPostProcessor list that the specified IObjectFactoryPostProcessor will be inserted at
invokeObjectFactoryPostProcessors()method 
protected function invokeObjectFactoryPostProcessors():void

Invokes all object factory post processors.

load()method 
public function load():void
loadComplete()method 
protected function loadComplete():void

TODO

prepareApplicationContext()method 
protected function prepareApplicationContext():void

Hook method defined in XmlObjectFactory to add the ApplicationContextAwareProcessor.

See also

registerObjectFactoryPostProcessors()method 
protected function registerObjectFactoryPostProcessors():void

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.

registerObjectPostProcessors()method 
protected function registerObjectPostProcessors():void

Will search all object definitions for implementations of IObjectPostProcessor.

If they are found they will be added using addObjectPostProcessor.

If the implementation also implements IObjectFactoryAware, it will receive a reference to the XMLApplicationContext.

See also

registerSingleton()method 
public override function registerSingleton(name:String, object:Object):voidParameters
name:String
 
object:Object