| Package | org.springextensions.actionscript.cairngorm.control |
| SVN browsing | CairngormFrontController.as |
| Fisheye | CairngormFrontController.as |
| Class | public class CairngormFrontController |
| Inheritance | CairngormFrontController com.adobe.cairngorm.control.FrontController |
| Implements | IApplicationContextAware, ICommandFactoryRegistryAware, IOwnerModuleAware |
CairngormFrontController extends Cairngorm's
FrontController and adds the ability to pass in a command map to
the constructor.
The object with the command definitions must have the following form:
var commands:Object = {
"myFirstEvent": "com.domain.command.MyFirstCommand",
"mySecondEvent": "com.domain.command.MySecondCommand"
};
// instantiate a front controller and pass in the commands objects
var controller:FrontController = new CairngormFrontController(commands);...where the key in the commands object is the name of the
event that the frontcontroller will listen to and the value is the
fully qualified class name of the command that will be executed.
Notice that the constructor takes a second optional argument specifying the package where the commands reside. By passing in this argument it is not needed to specify fully qualified classnames for the command classes. Only the classnames themselves need to be specified then.
var commands:Object = {
"myFirstEvent": "MyFirstCommand",
"mySecondEvent": "MySecondCommand"
};
var controller:FrontController = new CairngormFrontController(commands, "com.domain.command");The following is the xml definition of the controller instance:
<object id="controller" class="org.springextensions.actionscript.ioc.util.CairngormFrontController">
<constructor-arg>
<object>
<property name="myFirstEvent" value="MyFirstCommand"/>
<property name="mySecondEvent" value="MySecondCommand"/>
</object>
</constructor-arg>
<constructor-arg value="com.domain.command"/>
</object>
Batch commands are also supported, to let multiple commands execute after a single event has been dispatched simply add more than one command with the same event:
<object id="controller" class="org.springextensions.actionscript.ioc.util.CairngormFrontController">
<constructor-arg>
<object>
<property name="myFirstEvent" value="MyFirstCommand"/>
<property name="myFirstEvent" value="MySecondCommand"/>
</object>
</constructor-arg>
<constructor-arg value="com.domain.command"/>
</object>
To turn off this behavior set the allowCommandBatches property to false.
It is possible to use the CairngormFrontController in a multi-module environment without events and commands
getting mixed up between the different controllers.
use the register() method to associate a CairngormFrontController instance with a module and
make sure the CairngormEvents have their bubbling property set to true and that they
are dispatched by an IEventDispatcher instance that is part of the UI event bubbling hierarchy.
Documentation reference: the frontcontroller
| Property | Defined by | ||
|---|---|---|---|
| allowCommandBatches : Boolean
When set to true the CairngormFrontController will allow multiple commands to be associated with
a single event.
| CairngormFrontController | ||
| applicationContext : IApplicationContext
Sets the IApplicationContext that this object runs in.
| CairngormFrontController | ||
| commandFactoryRegistry : ICommandFactoryRegistry
[write-only]
| CairngormFrontController | ||
| commandMap : Object [write-only]
An object containing key/value pairs with the event names and the command classes
| CairngormFrontController | ||
| commandPackage : String
Specifies the package where the commands reside.
| CairngormFrontController | ||
| ownerModule : Module
The
Module that will act as the owner of the current IOwnerModuleAware instance. | CairngormFrontController | ||
| throwCairngormErrors : Boolean
If true the current
CairngormFrontController will re-throw Cairngorm errors. | CairngormFrontController | ||
| Property | Defined by | ||
|---|---|---|---|
| eventDispatcher : Object
The eventDispatcher instance that is used to listen for
CairngormEvents on. | CairngormFrontController | ||
| Method | Defined by | ||
|---|---|---|---|
|
CairngormFrontController(commandMap:Object, commandPackage:String = "", commandFactoryRegistry:ICommandFactoryRegistry = null)
Creates a new
CairngormFrontController instance. | CairngormFrontController | ||
|
addCommand(commandName:String, commandRef:Class, useWeakReference:Boolean = true):void
Adds an extra check to see if the command class implements the | CairngormFrontController | ||
|
addCommandFactory(factory:ICommandFactory):void
Adds a new The | CairngormFrontController | ||
|
addCommandIdentifier(commandName:String, commandRef:String, useWeakReference:Boolean = true):void
| CairngormFrontController | ||
|
addTrailingPeriod(input:String):String
[static]
Adds a trailing period character to the specified input string if it doesn't already have one. Input: "com.mypackages.classes.", output: "com.mypackages.classes." Input: "com.mypackages.classes", output: "com.mypackages.classes." | CairngormFrontController | ||
|
[static]
| CairngormFrontController | ||
|
removeCommand(commandName:String):void
Makes sure the right event listener is removed, depending on whether its a batch command or not. | CairngormFrontController | ||
| Method | Defined by | ||
|---|---|---|---|
|
addBatchCommand(commandName:String, commandRef:Object, useWeakReference:Boolean = true):void
Adds a batch command.
| CairngormFrontController | ||
|
addEventListeners():void
Adds all the event listeners to the current
eventDispatcher. | CairngormFrontController | ||
|
addSingleCommand(commandName:String, commandRef:Object, useWeakReference:Boolean = true):void
Adds a single command.
| CairngormFrontController | ||
|
createAndExecuteCommand(commandIdent:Object, event:CairngormEvent):void
Creates the | CairngormFrontController | ||
|
evaluateTarget(target:Object):Boolean
True if module is not null and equal to the specified Used by the | CairngormFrontController | ||
|
executeCommand(event:CairngormEvent):void
Retrieves the command name from the specified
CairngormEvent instance and
looks up the associated command class for it. | CairngormFrontController | ||
|
executeCommands(event:CairngormEvent):void
Retrieves the command name from the specified
CairngormEvent instance and
looks up the associated command list for it. | CairngormFrontController | ||
|
getCommandIndentifier(commandName:String):Object
| CairngormFrontController | ||
|
getCommands(commandName:String):Array
Retrieves the associated command list for the specified command name.
| CairngormFrontController | ||
|
init():void
Initializes the current
CairngormFrontController instance. | CairngormFrontController | ||
|
initCommandMap():void
Loops through the commandMap, validates the command class and adds the commands by invoking
addCommand for each item in the map. | CairngormFrontController | ||
|
registerModule(module:Module):void
When the module parameter is not null the eventDispatcher that the current
CairngormFrontController listens to
is switched to the current ISystemManager instance. | CairngormFrontController | ||
|
removeEventListeners():void
Removes all the event listeners from the current
eventDispatcher. | CairngormFrontController | ||
|
validateCommandClass(commandRef:Class):void
Checks if the specified Class implements the
ICommand interface, if not, an error is thrown. | CairngormFrontController | ||
| allowCommandBatches | property |
allowCommandBatches:Boolean [read-write]When set to true the CairngormFrontController will allow multiple commands to be associated with a single event. When set to false this will generate an error.
The default value is true.
public function get allowCommandBatches():Boolean
public function set allowCommandBatches(value:Boolean):void
| applicationContext | property |
applicationContext:IApplicationContext [read-write]Sets the IApplicationContext that this object runs in.
Implementation public function get applicationContext():IApplicationContext
public function set applicationContext(value:IApplicationContext):void
| commandFactoryRegistry | property |
commandFactoryRegistry:ICommandFactoryRegistry [write-only]Implementation
public function set commandFactoryRegistry(value:ICommandFactoryRegistry):void
| commandMap | property |
commandMap:Object [write-only]An object containing key/value pairs with the event names and the command classes
Implementation public function set commandMap(value:Object):void
| commandPackage | property |
commandPackage:String [read-write]Specifies the package where the commands reside. By setting this property it is not needed to specify fully qualified classnames for the command classes.
Implementation public function get commandPackage():String
public function set commandPackage(value:String):void
| eventDispatcher | property |
protected var eventDispatcher:Object
The eventDispatcher instance that is used to listen for CairngormEvents on. This can either be a CairngormEventDispatcher
or a ISystemManager instance, depending on whether the current CairngormFrontController is associated with a module
or not.
| ownerModule | property |
ownerModule:Module [read-write]
The Module that will act as the owner of the current IOwnerModuleAware instance.
public function get ownerModule():Module
public function set ownerModule(value:Module):void
| throwCairngormErrors | property |
throwCairngormErrors:Boolean [read-write]
If true the current CairngormFrontController will re-throw Cairngorm errors.
The default value is true.
public function get throwCairngormErrors():Boolean
public function set throwCairngormErrors(value:Boolean):void
| CairngormFrontController | () | constructor |
public function CairngormFrontController(commandMap:Object, commandPackage:String = "", commandFactoryRegistry:ICommandFactoryRegistry = null)
Creates a new CairngormFrontController instance.
commandMap:Object — an object containing key/value pairs with the event names and the command classes
|
|
commandPackage:String (default = "") — the package where the commands reside
|
|
commandFactoryRegistry:ICommandFactoryRegistry (default = null) — an ICommandFactoryRegistry that can take care of the creation of ICommands
|
| addBatchCommand | () | method |
protected function addBatchCommand(commandName:String, commandRef:Object, useWeakReference:Boolean = true):voidAdds a batch command.
ParameterscommandName:String |
|
commandRef:Object |
|
useWeakReference:Boolean (default = true) |
| addCommand | () | method |
public override function addCommand(commandName:String, commandRef:Class, useWeakReference:Boolean = true):void
Adds an extra check to see if the command class implements the ICommand interface.
commandName:String |
|
commandRef:Class |
|
useWeakReference:Boolean (default = true) |
| addCommandFactory | () | method |
public function addCommandFactory(factory:ICommandFactory):void
Adds a new ICommandFactory instance to the current CairngormFrontController instance.
The ICommandFactory gets added to the start of the list.
factory:ICommandFactory — the new ICommandFactory instance.
|
| addCommandIdentifier | () | method |
public function addCommandIdentifier(commandName:String, commandRef:String, useWeakReference:Boolean = true):voidParameters
commandName:String |
|
commandRef:String |
|
useWeakReference:Boolean (default = true) |
| addEventListeners | () | method |
protected function addEventListeners():void
Adds all the event listeners to the current eventDispatcher.
| addSingleCommand | () | method |
protected function addSingleCommand(commandName:String, commandRef:Object, useWeakReference:Boolean = true):voidAdds a single command.
ParameterscommandName:String |
|
commandRef:Object |
|
useWeakReference:Boolean (default = true) |
| addTrailingPeriod | () | method |
public static function addTrailingPeriod(input:String):String
Adds a trailing period character to the specified input string if it doesn't already have one.
Input: "com.mypackages.classes.", output: "com.mypackages.classes."
Input: "com.mypackages.classes", output: "com.mypackages.classes."
Parametersinput:String — the specified input string
|
String — the converted output
|
| createAndExecuteCommand | () | method |
protected function createAndExecuteCommand(commandIdent:Object, event:CairngormEvent):void
Creates the ICommand associated with the specified CairngormEvent instance and registers
the command with the current PendingCommandRegistry instance.
commandIdent:Object |
|
event:CairngormEvent |
| evaluateTarget | () | method |
protected function evaluateTarget(target:Object):Boolean
True if module is not null and equal to the specified target, or always true when no module is associated with the current CairngormFrontController.
Used by the executeCommand() method to determine whether a Command needs to be excecuted or not.
Parameters
target:Object |
Boolean |
| executeCommand | () | method |
protected override function executeCommand(event:CairngormEvent):void
Retrieves the command name from the specified CairngormEvent instance and
looks up the associated command class for it. With this class the createAndExecuteCommand() method
is the invoked.
event:CairngormEvent |
| executeCommands | () | method |
protected function executeCommands(event:CairngormEvent):void
Retrieves the command name from the specified CairngormEvent instance and
looks up the associated command list for it. With this list the createAndExecuteCommand() method
is the invoked for each command class in the list.
event:CairngormEvent |
| getCommandIndentifier | () | method |
protected function getCommandIndentifier(commandName:String):ObjectParameters
commandName:String |
Object |
| getCommands | () | method |
protected function getCommands(commandName:String):ArrayRetrieves the associated command list for the specified command name.
ParameterscommandName:String |
Array |
| getInstance | () | method |
public static function getInstance():CairngormFrontControllerReturns
CairngormFrontController —
The current CairngormFrontController instance.
|
| init | () | method |
protected function init():void
Initializes the current CairngormFrontController instance.
If the commandFactoryRegistry is null an instance of DefaultCommandFactoryRegistry is created.
| initCommandMap | () | method |
protected function initCommandMap():void
Loops through the commandMap, validates the command class and adds the commands by invoking addCommand for each item in the map.
| registerModule | () | method |
protected function registerModule(module:Module):void
When the module parameter is not null the eventDispatcher that the current CairngormFrontController listens to
is switched to the current ISystemManager instance. Otherwise CairngormEventDispatcher.getInstance()
is used. After the appropriate IEventDispatcher has been chosen the initCommandMap() is invoked.
module:Module — A Module instance or null
|
| removeCommand | () | method |
public override function removeCommand(commandName:String):void
Makes sure the right event listener is removed, depending on whether its a batch command or not.
ParameterscommandName:String |
| removeEventListeners | () | method |
protected function removeEventListeners():void
Removes all the event listeners from the current eventDispatcher.
| validateCommandClass | () | method |
protected function validateCommandClass(commandRef:Class):void
Checks if the specified Class implements the ICommand interface, if not, an error is thrown.
commandRef:Class |
— when specified Class does not implement the ICommand interface.
|