new ObjectFactory( [config] [, objects])
The basic Inversion of Control container or factory.
Parameters:
Name | Type | Argument | Default | Description |
---|---|---|---|---|
config |
system.ioc.ObjectConfig |
<optional> |
null | The configuration object of the factory. |
objects |
array |
<optional> |
null | The object definitions collection to initialize the factory. |
Example
var Point = function( x , y ) { this.x = x ; this.y = y ; console.log("constructor:" + this.toString() ) ; }; Point.prototype.test = function( message = null ) { console.log( 'test:' + this.toString() + " message:" + message ) ; } Point.prototype.toString = function() { return "[Point x:" + this.x + " y:" + this.y + "]" ; } ; var ObjectFactory = system.ioc.ObjectFactory ; var factory = new ObjectFactory(); var config = factory.config ; config.setConfigTarget ({ origin : { x : 10 , y : 20 } }) config.setLocaleTarget ({ messages : { test : 'test' } }) var objects = [ { id : "position" , type : "Point" , args : [ { value : 2 } , { ref : 'origin.y' }], properties : [ { name : "x" , ref :'origin.x' } , { name : "y" , value : 100 } ] }, { id : "origin" , type : "Point" , singleton : true , args : [ { config : 'origin.x' } , { value : 20 }] , properties : [ { name : 'test' , args : [ { locale : 'messages.test' } ] } ] } ]; factory.run( objects ); trace( factory.getObject('position') ) ;
Extends
Members
-
<constant> changeIt :system.signals.Signal
-
The signal emit when the task is changed.
Type:
- Inherited From:
-
<constant> clearIt :system.signals.Signal
-
The signal emit when the task is cleared.
Type:
- Inherited From:
-
config :system.ioc.ObjectConfig
-
Determinates the configuration object of the object factory.
Type:
-
<constant> finishIt :system.signals.Signal
-
This signal emit when the action is finished.
Type:
- Inherited From:
-
<constant> infoIt :system.signals.Signal
-
The signal emit when the task emit a message.
Type:
- Inherited From:
-
looping :boolean
-
The flag to determinate if the task must be looped.
Type:
- boolean
- Inherited From:
- Default Value:
-
- false
-
<constant> loopIt :system.signals.Signal
-
The signal emit when the task is looped.
Type:
- Inherited From:
-
<readonly> numObjectDefinition
-
Indicates the numbers of object definitions registered in the container.
- Inherited From:
-
objects :Array
-
This array contains objects to fill this factory with the run or create method.
Type:
-
<constant> pauseIt :system.signals.Signal
-
The signal emit when the task is paused.
Type:
- Inherited From:
-
<readonly> phase :string
-
Indicates the current phase.
Type:
- string
- Inherited From:
- See:
-
<constant> progressIt :system.signals.Signal
-
The signal emit when the task is in progress.
Type:
- Inherited From:
-
<constant> resumeIt :system.signals.Signal
-
The signal emit when the task is resumed.
Type:
- Inherited From:
-
<readonly> running :boolean
-
Indicates action is running.
Type:
- boolean
- Inherited From:
-
<readonly> singletons :system.data.maps.ArrayMap
-
The
system.data.maps.ArrayMap
representation of allsingletons
registered in this factory.Type:
-
<constant> startIt :system.signals.Signal
-
This signal emit when the action is started.
Type:
- Inherited From:
-
<constant> stopIt :system.signals.Signal
-
This signal emit when the task is stopped.
Type:
- Inherited From:
-
<constant> timeoutIt :system.signals.Signal
-
The signal emit when the task is out of time.
Type:
- Inherited From:
Methods
-
addObjectDefinition(definition)
-
Registers a new object definition in the container.
Parameters:
Name Type Description definition
The Identifiable ObjectDefinition reference to register in the container.
- Inherited From:
Throws:
ArgumentError If the specified object definition is null or if this id attribut is null.
-
clearObjectDefinition()
-
Removes all the object definitions register in the container.
- Inherited From:
-
clone()
-
Returns a shallow copy of this object.
- Overrides:
Returns:
a shallow copy of this object.
-
getObject(id)
-
This method returns an object with the specified
id
in argument.Parameters:
Name Type Description id
string The index expression of the object to returns.
Returns:
The instance of the object with the id passed in argument.
-
getObjectDefinition(id)
-
Returns the ObjectDefinition object register in the container with the specified id.
Parameters:
Name Type Description id
string The id name of the ObjectDefinition to return.
- Inherited From:
Throws:
ArgumentError If the specified object definition don't exist in the container.
Returns:
the ObjectDefinition object register in the container with the specified id.
-
hasObjectDefinition(id)
-
Returns
true
if the object defines with the specified id is register in the container.Parameters:
Name Type Description id
string The id of the ObjectDefinition to search.
- Inherited From:
Returns:
true
if the object defines with the specified id is register in the container. -
hasSingleton(id)
-
Indicates if a singleton reference is register in the factory with the specified id.
Parameters:
Name Type Description id
string The index expression of the singleton.
Returns:
true
if the singleton reference is register in the factory. -
isDirty()
-
Indicates if the
ObjectFactory
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:
true
if the factory is dirty. -
isLazyInit(id)
-
Indicates whether an object definition is to be lazily initialized.
Note: The default behavior for
ObjectFactory
implementations is to eagerly pre-instantiate all singleton object definitions at startup. If the object definitionlazyInit
attribute is set to true, the singleton will not be initialized until referenced by another object definition or explicitly retrieved from the enclosing ObjectFactory. If present and set to false, the object definition will be instantiated on startup by factories that perform eager initialization of singletons.Parameters:
Name Type Description id
string The index expression of the object to check.
Returns:
true
if the specified object definition is lazyly initialized. -
isLocked()
-
Returns
true
if the object is locked.- Inherited From:
- Implements:
Returns:
true
if the object is locked. -
isSingleton(id)
-
This method defined if the scope of the specified object definition is
singleton
.Parameters:
Name Type Description id
string The index expression of the object to check.
Returns:
true
if the object is a singleton. -
lock()
-
Locks the object.
- Inherited From:
- Implements:
-
notifyChanged()
-
Notify when the process is changed.
- Inherited From:
-
notifyCleared()
-
Notify when the process is cleared.
- Inherited From:
-
notifyFinished()
-
Notify when the process is finished.
- Inherited From:
-
notifyInfo()
-
Notify a specific information when the process is changed.
- Inherited From:
-
notifyLooped()
-
Notify when the process is looped.
- Inherited From:
-
notifyPaused()
-
Notify when the process is paused.
- Inherited From:
-
notifyProgress()
-
Notify when the process is progress.
- Inherited From:
-
notifyResumed()
-
Notify when the process is resumed.
- Inherited From:
-
notifyStarted()
-
Notify when the process is started.
- Inherited From:
-
notifyStopped()
-
Notify when the process is stopped.
- Inherited From:
-
notifyTimeout()
-
Notify when the process is out of time.
- Inherited From:
-
removeObjectDefinition(id)
-
Unregisters an object definition in the container.
Parameters:
Name Type Description id
The id of the object definition to remove.
- Inherited From:
Throws:
ArgumentError If the specified object definition don't exist in the container.
-
removeSingleton(id)
-
Removes and destroy a singleton in the factory.
Invoke the
destroy
method of this object is it's define in theObjectDefinition
of this singleton.Parameters:
Name Type Description id
string The index expression of the object to remove.
-
reset()
-
Resets the task.
- Inherited From:
- Implements:
-
resume()
-
Resumes the task.
- Inherited From:
-
run()
-
Run the initialization of the factory with new object definitions and create the not lazy-init singleton objects.
- Overrides:
Example
var Point = function( x , y ) { this.x = x ; this.y = y ; }; Point.prototype.test = function( message = null ) { console.log( 'test:' + this.toString() + " message:" + message ) ; } Point.prototype.toString = function() { return "[Point x:" + this.x + " y:" + this.y + "]" ; } ; var ObjectFactory = system.ioc.ObjectFactory ; var factory = new ObjectFactory(); var config = factory.config ; config.setConfigTarget ({ origin : { x : 10 , y : 20 } }) config.setLocaleTarget ({ messages : { test : 'test' } }) var objects = [ { id : "position" , type : Point , args : [ { value : 2 } , { ref : 'origin.y' }], properties : [ { name : "x" , ref :'origin.x' } , { name : "y" , value : 100 } ] }, { id : "origin" , type : Point , singleton : true , args : [ { config : 'origin.x' } , { value : 20 }] , properties : [ { name : 'test' , args : [ { locale : 'messages.test' } ] } ] } ]; factory.run( objects ); trace( factory.getObject('position') ) ;
-
start()
-
Starts the task.
- Inherited From:
- Implements:
-
stop()
-
Starts the process.
- Inherited From:
- Implements:
-
unlock()
-
Unlocks the object.
- Inherited From:
- Implements:
-
warn()
-
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.