Packagecom.bourre.core
Classpublic class CoreFactory

Player version: Flash Player 9.0
Language version: ActionScript 3.0

A factory for object creation.

The CoreFactory can build any object of any type.
The CoreFactory is intensively used in the IoC assembler of LowRA.



Public Methods
 MethodDefined by
  
buildInstance(qualifiedClassName:String, args:Array = null, factoryMethod:String = null, singletonAccess:String = null):Object
[static] Builds an instance of the passed-in class with the specified arguments passed to the class constructor.
CoreFactory
Method detail
buildInstance()method
public static function buildInstance(qualifiedClassName:String, args:Array = null, factoryMethod:String = null, singletonAccess:String = null):Object

Player version: Flash Player 9.0
Language version: ActionScript 3.0

Builds an instance of the passed-in class with the specified arguments passed to the class constructor. The function can also work with singleton factory and factory methods.

When trying to create an object, the function will work as below :

  1. The function try to retreive a reference to te specified class, if the class cannot be found in the current application domain the function will fail with an exception.
  2. Then the function will look to a factory method, if one have been specified, if the singletonAccess is also specified, the function retreive a reference to the singleton instance and then call the factory method on it. If there is no singleton access, the function call the factory method directly on the class.
  3. If singletonAccess is specified and factoryMethod parameter is null, this method will try to return an instance using singleton access parameter as static method name of the class passed.
  4. If there is neither a factory method nor a singleton accessor, the function will instantiate the class using its constructor.

In AS3, the constructor property of a class is not a function but an object, resulting that it is not possible to use the apply or call method on the constructor of a class. The workaround we use is to create wrapping methods which correspond each to a specific call to a class constructor with a specific number of arguments, in that way, we can select the right method to use according to the number of arguments specified in the buildInstance call. However, there's a limitation, we decided to limit the number of arguments to 30 values.

Parameters
qualifiedClassName:String — the full classname of the class to create as returned by the getQualifiedClassName function
 
args:Array (default = null) — array of arguments to transmit into the constructor
 
factoryMethod:String (default = null) — the name of a factory method provided by the class to use in place of the constructor
 
singletonAccess:String (default = null) — the name of the singleton accessor method if the factory method is a member of the singleton instance

Returns
Object — an instance of the specified class, or null

Throws
ReferenceError — The specified classname cannot be found in the current application domain

Example
Creating a Point instance using the CoreFactory class :
CoreFactory.buildInstance( "flash.geom::Point", [ 50, 50 ] );
Using the factory method createObject of the class to create the instance :
CoreFactory.buildInstance( "com.package::SomeClass", ["someParam"], "createObject" );