Packageorg.spicefactory.parsley.context
Classpublic class ContextBuilder
InheritanceContextBuilder Inheritance Object

A ContextBuilder offers the option to create a new Context programmatically using the convenient configuration DSL.

A standard ContextBuilder can be created using the newBuilder method:

ContextBuilder.newBuilder()
     .config(XmlConfig.forFile("logging.xml"))
     .config(FlexConfig.forClass(MyConfig))
 	   .build();

If you need to specify more options than just the configuration artifacts, you must enter setup mode first:

var viewRoot:DisplayObject = ...;
 var parent:Context = ...;
 ContextBuilder.newSetup()
     .viewRoot(viewRoot)
     .parent(parent)
     .viewSettings().autoremoveComponents(false)
     .newBuilder()
         .config(XmlConfig.forFile("logging.xml"))
         .config(FlexConfig.forClass(MyConfig))
 	       .build();



Public Methods
 MethodDefined By
  
Builds and returns the final Context instance, applying all settings specified for this builder.
ContextBuilder
  
complete(handler:Function):ContextBuilder
Adds a callback to invoke when the Context created by this builder finishes initialization.
ContextBuilder
  
Adds a configuration processor to this builder.
ContextBuilder
  
error(handler:Function):ContextBuilder
Adds a callback to invoke when Context creation aborts with an error.
ContextBuilder
  
[static] Creates a new ContextBuilder instance applying default settings.
ContextBuilder
  
[static] Creates a new setup instance that allows to specify custom options for the ContextBuilder to be created.
ContextBuilder
  
object(instance:Object, id:String = null):ContextBuilder
Adds an existing instance to the Context created by this builder.
ContextBuilder
  
Returns the factory that can be used to programmatically create new object definitions using the framework's configuration DSL.
ContextBuilder
Method Detail
build()method
public function build():Context

Builds and returns the final Context instance, applying all settings specified for this builder.

Returns
Context — the final Context instance
complete()method 
public function complete(handler:Function):ContextBuilder

Adds a callback to invoke when the Context created by this builder finishes initialization. This may happen synchronously or asynchronously.

The handler function has to accept a parameter of type Context.

Parameters

handler:Function — a callback to invoke when the Context created by this builder finishes initialization

Returns
ContextBuilder — this builder instance for method chaining
config()method 
public function config(processor:ConfigurationProcessor):ContextBuilder

Adds a configuration processor to this builder.

The builtin configuration mechanisms offer convenient shortuts to create such a processor like FlexConfig.forClass(MyConfig) or XmlConfig.forFile("config.xml").

Parameters

processor:ConfigurationProcessor — the processor to add

Returns
ContextBuilder — this builder instance for method chaining
error()method 
public function error(handler:Function):ContextBuilder

Adds a callback to invoke when Context creation aborts with an error. This may happen synchronously or asynchronously.

The handler function has to accept a parameter of type Object for the cause of the failure. This is usually an instance of type Error or ErrorEvent.

Parameters

handler:Function — a callback to invoke when Context creation aborts with an error

Returns
ContextBuilder — this builder instance for method chaining
newBuilder()method 
public static function newBuilder():ContextBuilder

Creates a new ContextBuilder instance applying default settings. In case you want to specify options like view root, custom scopes or parent Contexts, use newSetup instead.

Returns
ContextBuilder — a new ContextBuilder instance applying default settings
newSetup()method 
public static function newSetup():ContextBuilderSetup

Creates a new setup instance that allows to specify custom options for the ContextBuilder to be created.

Returns
ContextBuilderSetup — a new setup instance that allows to specify custom options for the ContextBuilder to be created
object()method 
public function object(instance:Object, id:String = null):ContextBuilder

Adds an existing instance to the Context created by this builder. The only way to apply framework features to the target instance is metadata in this case. If you need other means of applying features to an object, consider using the objectDefinition method instead.

Parameters

instance:Object — the instance to add to the Context
 
id:String (default = null) — the optional id of the instance

Returns
ContextBuilder — this builder instance for method chaining
objectDefinition()method 
public function objectDefinition():ObjectDefinitionBuilderFactory

Returns the factory that can be used to programmatically create new object definitions using the framework's configuration DSL. This allows for more fine-grained control of the functionality that should be applied to the target instance than using the simple shortcut of the object method, where all object configuration would need to be done with metadata.

Returns
ObjectDefinitionBuilderFactory — the factory that can be used to programmatically create new object definitions