Packageorg.springextensions.actionscript.context.support
Classpublic class XMLApplicationContext
InheritanceXMLApplicationContext Inheritance XMLObjectFactory Inheritance DefaultListableObjectFactory Inheritance AbstractObjectFactory Inheritance flash.events.EventDispatcher
ImplementsIConfigurableApplicationContext
SubclassesFlexXMLApplicationContext

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

Important: the schemeLocation within the application context xml file (in the example http://www.pranaframework.org/schema/objects/prana-objects-0.6.xsd) should contain the version of prana 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.pranaframework.org/objects"
            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
            xsi:schemaLocation="http://www.pranaframework.org/objects http://www.pranaframework.org/schema/objects/prana-objects-0.6.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
addObjectPostProcessor()


Public Properties
 PropertyDefined by
 InheritedallowObjectDefinitionOverriding : Boolean
Whether to allow re-registration of a different definition with the same name
DefaultListableObjectFactory
 InheritedconfigLocations : Array
Returns an array of configuration locations.
XMLObjectFactory
 InheritednumObjectDefinitions : int
Returns the number of definitions present in the object definition registry
DefaultListableObjectFactory
 InheritednumObjectPostProcessors : int
Returns the number of object post processors.
AbstractObjectFactory
 InheritedobjectDefinitionNames : Array
Returns an array containing all object definition names.
DefaultListableObjectFactory
 Inheritedparser : XMLObjectDefinitionsParser
Contains the parser of the XML definitions.
XMLObjectFactory
 InheritedtypeConverter : ITypeConverter
The current type converter implementation
AbstractObjectFactory
Protected Properties
 PropertyDefined by
 InheritedobjectDefinitions : Object
The registered object definitions
AbstractObjectFactory
Public Methods
 MethodDefined by
  
XMLApplicationContext(source:* = null)
Creates a new XMLApplicationContext
XMLApplicationContext
 Inherited
addConfig(config:XML):void
Use this method to add xml versions of configurations
XMLObjectFactory
 Inherited
addConfigLocation(configLocation:String):void
Use this method to add aditional configuration locations.
XMLObjectFactory
 Inherited
addEmbeddedConfig(config:Class):void
Adds an embedded config.
XMLObjectFactory
 Inherited
addObjectPostProcessor(objectPostProcessor:IObjectPostProcessor):void
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
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
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 all object definitions names that implement the given type.
DefaultListableObjectFactory
 Inherited
getObjectsOfType(type:Class):Dictionary
Returns all object definitions that implement 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
 Inherited
load():void
Instructs the object factory to start loading the available configuration(s)
XMLObjectFactory
 Inherited
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
Will register the given objectDefinition with the given name.
DefaultListableObjectFactory
 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
Protected Methods
 MethodDefined by
  
afterParse():void
Hook method defined in XmlObjectFactory overridden to invoke application context specific logic.
XMLApplicationContext
  
beforeParse():void
Hook method defined in XmlObjectFactory to add the ApplicationContextAwareProcessor.
XMLApplicationContext
  
Invokes all object factory post processors.
XMLApplicationContext
 Inherited
loadConfigLocation(configLocation:String):void
Will load a configLocation
XMLObjectFactory
  
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.
XMLApplicationContext
  
Will search all object definitions for implementations of IObjectPostProcessor.
XMLApplicationContext
Events
 EventSummaryDefined by
 Inherited Dispatched as a result of a call to the load method when all available configurations have been parsed.XMLObjectFactory
 Inherited Dispatched when an input or output error occurs that causes a load operation to fail.XMLObjectFactory
Constructor detail
XMLApplicationContext()constructor
public function XMLApplicationContext(source:* = null)

Creates a new XMLApplicationContext

Parameters
source:* (default = null)
Method detail
afterParse()method
protected override function afterParse():void

Hook method defined in XmlObjectFactory overridden to invoke application context specific logic.

beforeParse()method 
protected override function beforeParse():void

Hook method defined in XmlObjectFactory to add the ApplicationContextAwareProcessor.

See also

invokeObjectFactoryPostProcessors()method 
protected function invokeObjectFactoryPostProcessors():void

Invokes all object factory post processors.

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