Packagesystem.ioc
Classpublic class ObjectFactory
InheritanceObjectFactory Inheritance ObjectDefinitionContainer Inheritance CoreAction Inheritance Task Inheritance Object
Implements IObjectFactory

The basic Inversion of Control container/factory class.

Example :

     import flash.text.TextField ;
     import flash.text.TextFormat ;
     
     import system.ioc.ObjectFactory ;
     
     var factory:ObjectFactory = new ObjectFactory();
     
     var objects:Array =
     [
         {
             id         : "my_field" ,
             type       : "flash.text.TextField" ,
             properties :
             [
                 { name:"defaultTextFormat" , value:new TextFormat("Verdana", 11) } ,
                 { name:"selectable"        , value:false                         } ,
                 { name:"text"              , value:"hello world"                 } ,
                 { name:"textColor"         , value:0xF7F744                      } ,
                 { name:"x"                 , value:100                           } ,
                 { name:"y"                 , value:100                           }
             ]
         }
     ];
     
     factory.create( objects );
     
     var field:TextField = factory.getObject("my_field") as TextField ;
     
     addChild(field) ;
     



Public Properties
 PropertyDefined By
 InheritedchangeIt : Signaler
This signal emit when the notifyChanged method is invoked.
CoreAction
 InheritedclearIt : Signaler
This signal emit when the notifyCleared method is invoked.
CoreAction
  config : ObjectConfig
Determinates the configuration object of the object factory.
ObjectFactory
 InheritedfinishIt : Signaler
This signal emit when the notifyFinished method is invoked.
Task
 InheritedinfoIt : Signaler
This signal emit when the notifyInfo method is invoked.
CoreAction
 Inheritedlogger : Logger
Determinates the internal Logger reference of this Loggable object.
Task
 Inheritedlooping : Boolean
The flag to determinate if the Action object is looped.
CoreAction
 InheritedloopIt : Signaler
This signal emit when the notifyLooped method is invoked.
CoreAction
 InheritednumObjectDefinitions : uint
[read-only] Indicates the numbers of object definitions registered in the container.
ObjectDefinitionContainer
  objects : Array
This array contains objects to fill this factory with the run or create method.
ObjectFactory
 InheritedpauseIt : Signaler
This signal emit when the notifyPause method is invoked.
CoreAction
 Inheritedphase : String
[read-only] The current phase of the action.
Task
 InheritedprogressIt : Signaler
This signal emit when the notifyProgress method is invoked.
CoreAction
 InheritedresumeIt : Signaler
This signal emit when the notifyResumed method is invoked.
CoreAction
 Inheritedrunning : Boolean
[read-only] Indicates true if the process is in progress.
Task
  singletons : HashMap
[read-only] Returns the Map representation of all singletons register in this factory.
ObjectFactory
 InheritedstartIt : Signaler
This signal emit when the notifyStarted method is invoked.
Task
 InheritedstopIt : Signaler
This signal emit when the notifyStopped method is invoked.
CoreAction
 InheritedtimeoutIt : Signaler
This signal emit when the notifyTimeOut method is invoked.
CoreAction
Protected Properties
 PropertyDefined By
  bufferSingletons : Array
The internal buffer of no lazyInit singletons (id) to create it in the run method if the config.lazyInit property is false.
ObjectFactory
Public Methods
 MethodDefined By
  
ObjectFactory(config:ObjectConfig = null, objects:Array = null)
Creates a new ObjectFactory instance.
ObjectFactory
 Inherited
Registers a new object definition in the container.
ObjectDefinitionContainer
 Inherited
Removes all the object definitions register in the container.
ObjectDefinitionContainer
  
clone():*
[override] Returns a shallow copy of this object.
ObjectFactory
 Inherited
containsObjectDefinition(id:String):Boolean
Returns true if the object defines with the specified id is register in the container.
ObjectDefinitionContainer
  
containsSingleton(id:String):Boolean
Indicates if a singleton reference is register in the factory with the specified id.
ObjectFactory
  
getObject(id:String):*
This method returns an object with the specified id in argument.
ObjectFactory
 Inherited
Returns the IObjectDefinition object register in the container with the specified id.
ObjectDefinitionContainer
  
isDirty():Boolean
Indicates if the factory is dirty, must flush this buffer of not lazy-init singleton object definitions.
ObjectFactory
  
isLazyInit(id:String):Boolean
This method indicates if the specified object definition is lazy init.
ObjectFactory
 Inherited
isLocked():Boolean
Returns true if the object is locked.
Task
  
isSingleton(id:String):Boolean
This method defined if the scope of the specified object definition is "singleton".
ObjectFactory
 Inherited
lock():void
Locks the object.
Task
 Inherited
Notify when the process is changed.
CoreAction
 Inherited
Notify when the process is cleared.
CoreAction
 Inherited
Notify an ActionEvent when the process is finished.
Task
 Inherited
notifyInfo(info:*):void
Notify a specific information when the process is changed.
CoreAction
 Inherited
Notify when the process is looped.
CoreAction
 Inherited
Notify when the process is paused.
CoreAction
 Inherited
Notify when the process is in progress.
CoreAction
 Inherited
Notify when the process is resumed.
CoreAction
 Inherited
Notify an ActionEvent when the process is started.
Task
 Inherited
Notify when the process is stopped.
CoreAction
 Inherited
Notify when the process is out of time.
CoreAction
 Inherited
removeObjectDefinition(id:String):void
Unregisters an object definition in the container.
ObjectDefinitionContainer
  
removeSingleton(id:String):void
Removes and destroy a singleton in the container.
ObjectFactory
  
run(... arguments):void
[override] Run the initialization of the factory with new object definitions and create the not lazy-init singleton objects.
ObjectFactory
 Inherited
unlock():void
Unlocks the display.
Task
  
warn(... args):void
The custom warn method of this factory to log a warning message in the application.
ObjectFactory
Protected Methods
 MethodDefined By
  
createArguments(args:Array = null):Array
Creates the arguments Array representation of the specified definition.
ObjectFactory
  
Creates a new Object with a specified IObjectFactoryStrategy instance.
ObjectFactory
  
dependsOn(definition:IObjectDefinition):void
Invoked to creates all object in the factory register in the dependsOn collection.
ObjectFactory
  
eval(value:*, evaluators:Array):*
Evaluates a value with an Array of evaluators or Evaluable references in the factory.
ObjectFactory
  
generates(definition:IObjectDefinition):void
Invoked to creates all object in the factory register in the generates collection.
ObjectFactory
  
Invokes the destroy method of the specified object, if the init method is define in the IDefinition object.
ObjectFactory
  
invokeInitMethod(o:*, definition:IObjectDefinition = null):void
Invokes the init method of the specified object, if the init method is define in the IDefinition object.
ObjectFactory
  
isLockable(o:*, definition:IObjectDefinition):Boolean
Indicates if the specified object is Lockable and must be locked during the initialization of the properties and methods when is created.
ObjectFactory
  
Populates the Identifiable singleton object, if the 'identify' flag is true the config of this factory and if specified the IObjectDefinition object scope is singleton.
ObjectFactory
  
Populates all properties in the Map passed in argument.
ObjectFactory
  
populateProperty(o:*, prop:ObjectProperty, id:*):void
Populates a property in the specified object with the passed-in ObjectProperty object.
ObjectFactory
  
registerListeners(o:*, listeners:Array):void
Initialize the listener callback of the specified object.
ObjectFactory
  
registerReceivers(o:*, receivers:Array):void
Initialize the receiver callback of the specified object.
ObjectFactory
 Inherited
setRunning(b:Boolean):void
Changes the running property value.
Task
Property Detail
bufferSingletonsproperty
protected var bufferSingletons:Array

The internal buffer of no lazyInit singletons (id) to create it in the run method if the config.lazyInit property is false.

configproperty 
config:ObjectConfig

Determinates the configuration object of the object factory.


Implementation
    public function get config():ObjectConfig
    public function set config(value:ObjectConfig):void
objectsproperty 
public var objects:Array

This array contains objects to fill this factory with the run or create method.

singletonsproperty 
singletons:HashMap  [read-only]

Returns the Map representation of all singletons register in this factory.


Implementation
    public function get singletons():HashMap
Constructor Detail
ObjectFactory()Constructor
public function ObjectFactory(config:ObjectConfig = null, objects:Array = null)

Creates a new ObjectFactory instance.

Parameters
config:ObjectConfig (default = null) — The optional configuration object of the factory.
 
objects:Array (default = null) — The optional Array contains generic objects to fill and initialize this factory.
Method Detail
clone()method
override public function clone():*

Returns a shallow copy of this object.

Returns
* — a shallow copy of this object.
containsSingleton()method 
public function containsSingleton(id:String):Boolean

Indicates if a singleton reference is register in the factory with the specified id.

Parameters

id:String — 'id' of the singleton.

Returns
Booleantrue if the singleton reference exist in the factory.
createArguments()method 
protected function createArguments(args:Array = null):Array

Creates the arguments Array representation of the specified definition.

Parameters

args:Array (default = null)

Returns
Array — the arguments Array representation of the specified definition.
createObjectWithStrategy()method 
protected function createObjectWithStrategy(strategy:IObjectFactoryStrategy):*

Creates a new Object with a specified IObjectFactoryStrategy instance.

Parameters

strategy:IObjectFactoryStrategy

Returns
* — A new Object with a specified IObjectFactoryStrategy instance.
dependsOn()method 
protected function dependsOn(definition:IObjectDefinition):void

Invoked to creates all object in the factory register in the dependsOn collection.

All objects in the dependsOn collection are initialized before the initialization of the current object build in the factory.

Parameters

definition:IObjectDefinition

eval()method 
protected function eval(value:*, evaluators:Array):*

Evaluates a value with an Array of evaluators or Evaluable references in the factory.

Parameters

value:* — The value to evaluate.
 
evaluators:Array — The Array who contains IEvaluator objects or String ids who representing a IEvaluator in the factory.

Returns
* — The new value after evaluation.
generates()method 
protected function generates(definition:IObjectDefinition):void

Invoked to creates all object in the factory register in the generates collection.

All objects in the generates collection are initialized after the initialization of the current object build in the factory.

Parameters

definition:IObjectDefinition

getObject()method 
public function getObject(id:String):*

This method returns an object with the specified id in argument.

Parameters

id:String — The 'id' of the object to return.

Returns
* — the instance of the object with the id passed in argument.
invokeDestroyMethod()method 
protected function invokeDestroyMethod(o:*, definition:IObjectDefinition):void

Invokes the destroy method of the specified object, if the init method is define in the IDefinition object.

Parameters

o:*
 
definition:IObjectDefinition

invokeInitMethod()method 
protected function invokeInitMethod(o:*, definition:IObjectDefinition = null):void

Invokes the init method of the specified object, if the init method is define in the IDefinition object.

Parameters

o:*
 
definition:IObjectDefinition (default = null)

isDirty()method 
public function isDirty():Boolean

Indicates if the factory is dirty, must flush this buffer of not lazy-init singleton object definitions. The user must execute the run or create methods to flush this buffer.

Returns
Boolean
isLazyInit()method 
public function isLazyInit(id:String):Boolean

This method indicates if the specified object definition is lazy init.

Parameters

id:String — The 'id' of the object definition to check..

Returns
Booleantrue if the specified object definition is lazy init.
isLockable()method 
protected function isLockable(o:*, definition:IObjectDefinition):Boolean

Indicates if the specified object is Lockable and must be locked during the initialization of the properties and methods when is created.

Parameters

o:*
 
definition:IObjectDefinition

Returns
Boolean
isSingleton()method 
public function isSingleton(id:String):Boolean

This method defined if the scope of the specified object definition is "singleton".

Parameters

id:String — 'id' of the object.

Returns
Booleantrue if the object is a singleton.
populateIdentifiable()method 
protected function populateIdentifiable(o:*, definition:IObjectDefinition):void

Populates the Identifiable singleton object, if the 'identify' flag is true the config of this factory and if specified the IObjectDefinition object scope is singleton.

Parameters

o:*
 
definition:IObjectDefinition

populateProperties()method 
protected function populateProperties(o:*, definition:IObjectDefinition):void

Populates all properties in the Map passed in argument.

Parameters

o:*
 
definition:IObjectDefinition

populateProperty()method 
protected function populateProperty(o:*, prop:ObjectProperty, id:*):void

Populates a property in the specified object with the passed-in ObjectProperty object.

Parameters

o:* — The object to populate.
 
prop:ObjectProperty — The ObjectProperty used to populate the object.
 
id:* — The id of the current IObjectDefinition.

registerListeners()method 
protected function registerListeners(o:*, listeners:Array):void

Initialize the listener callback of the specified object.

Parameters

o:*
 
listeners:Array

registerReceivers()method 
protected function registerReceivers(o:*, receivers:Array):void

Initialize the receiver callback of the specified object.

Parameters

o:*
 
receivers:Array

removeSingleton()method 
public function removeSingleton(id:String):void

Removes and destroy a singleton in the container. Invoke the 'destroy' method of this object is it's define in the IObjectDefinition of this singleton.

Parameters

id:String — The id of the singleton to remove.

run()method 
override public function run(... arguments):void

Run the initialization of the factory with new object definitions and create the not lazy-init singleton objects.

Example :

         import flash.text.TextField ;
         import flash.text.TextFormat ;
         
         import system.ioc.ObjectFactory ;
         
         var factory:ObjectFactory = new ObjectFactory();
         
         factory.objects =
         [
             {
                 id         : "my_field" ,
                 type       : "flash.text.TextField" ,
                 properties :
                 [
                     { name:"defaultTextFormat" , value:new TextFormat("Verdana", 11) } ,
                     { name:"selectable"        , value:false                         } ,
                     { name:"text"              , value:"hello world"                 } ,
                     { name:"textColor"         , value:0xF7F744                      } ,
                     { name:"x"                 , value:100                           } ,
                     { name:"y"                 , value:100                           }
                 ]
             }
         ];
         
         factory.run();
         
         var field:TextField = factory.getObject("my_field") as TextField ;
         
         addChild(field) ;
         

Parameters

... arguments

warn()method 
public function warn(... args):void

The custom warn method of this factory to log a warning message in the application. You can overrides this method, the prototype object is dynamic.

Parameters

... args