Packagecom.bourre.commands
Classpublic class FrontController
InheritanceFrontController Inheritance AbstractLocator
ImplementsASyncCommandListener

Player version: Flash Player 9.0
Language version: ActionScript 3.0

A base class for an application specific front controller, that is able to dispatch control following particular events to appropriate command classes.

The Front Controller is the centralised request handling class in a LowRA plugin or application. It could be used with or without the plugin architecture or LowRA. By default all classes which will extend the AbstractPlugin will own an instance of the FrontController class.

The role of the Front Controller is to first register all the different events that it is capable of handling against worker classes, called command classes. On hearing an application event, the Front Controller will look up its table of registered events, find the appropriate command for handling of the event, before dispatching control to the command by calling its execute() method.

When used inside a plugin the Front Controller is automatically registered as a listener of a private event broadcaster created especially for this plugin. In that way it will receive all private events dispatched in all plugin's MVC components.

See the How to use the Command pattern implementations in LowRA document for more details on the commands package structure.



Protected Properties
 PropertyDefined by
 Inherited_m : HashMap
Map storing String keys associated with Object values.
AbstractLocator
  _owner : Plugin
A reference to the plugin owner of this front controller.
FrontController
Public Methods
 MethodDefined by
  
FrontController(owner:Plugin = null)
Creates a new Front Controller instance for the passed-in plugin.
FrontController
  
add(d:Dictionary):void
Adds all key/commands associations within the passed-in Dictionnary in the current front controller.
FrontController
 Inherited
addEventListener(type:String, listener:Object, ... rest):Boolean
Adds an event listener for the specified event type.
AbstractLocator
 Inherited
callMethodOnAllValues(methodName:String, ... args):void
Takes all values of a Locator and call on each value the method name passed as 1st argument.
AbstractLocator
 Inherited
getKeys():Array
Returns an Array view of the keys contained in this locator.
AbstractLocator
 Inherited
Returns the exclusive logger object owned by this locator.
AbstractLocator
  
Returns the owner plugin of this controller
FrontController
 Inherited
getType():Class
Return the class type of elements in this container.
AbstractLocator
 Inherited
getValues():Array
Returns an Array view of the values contained in this locator.
AbstractLocator
  
handleEvent(event:Event):void
Handles all events received by this object.
FrontController
 Inherited
isRegistered(name:String):Boolean
Returns true is there is a ressource associated with the passed-in key.
AbstractLocator
 Inherited
isTyped():Boolean
Returns true if this container perform a verification of the type of elements.
AbstractLocator
  
locate(key:String):Object
Returns the command located at the specified key index.
FrontController
 Inherited
matchType(o:*):Boolean
Verify that the passed-in object type match the current container element's type.
AbstractLocator
  
onCommandEnd(e:Event):void
Catch callback events from asynchronous commands thiggered by this front controller.
FrontController
 Inherited
processOnAllValues(f:Function, ... args):void
Takes all values of a Locator and pass them one by one as arguments to a method of an object.
AbstractLocator
  
pushCommandClass(eventName:String, commandClass:Class):Boolean
Registers the passed-in command class to be triggered at each time the controller will receive an event of type eventName.
FrontController
  
pushCommandInstance(eventName:String, command:Command):Boolean
Registers the passed-in command to be triggered at each time the controller will receive an event of type eventName.
FrontController
  
register(eventName:String, o:Object):Boolean
Registers passed-in object with identifier name to this locator.
FrontController
  
release():void
FrontController
  
remove(eventName:String):void
Removes the class or the command registered with the passed-in event name.
FrontController
 Inherited
removeEventListener(type:String, listener:Object):Boolean
Removes the passed-in listener for listening the specified event.
AbstractLocator
  
toString():String
Returns the string representation of this instance.
FrontController
 Inherited
unregister(name:String):Boolean
Unregisters object registered with identifier name.
AbstractLocator
Protected Methods
 MethodDefined by
 Inherited
broadcastEvent(e:Event):void
Broadcast the passed-in event object to listeners according to the event's type.
AbstractLocator
 Inherited
Returns event Broadcaster owned by this locator.
AbstractLocator
 Inherited
onRegister(name:String = null, o:Object = null):void
Call this method to do something when an object is registered in locator.
AbstractLocator
 Inherited
onUnregister(name:String = null):void
Call this method to do something when an object is unregistered from locator.
AbstractLocator
Property detail
_ownerproperty
protected var _owner:Plugin

Player version: Flash Player 9.0
Language version: ActionScript 3.0

A reference to the plugin owner of this front controller. When used outside of the plugin architecture, this property store a reference to the global instance of the NullPlugin class.

Constructor detail
FrontController()constructor
public function FrontController(owner:Plugin = null)

Player version: Flash Player 9.0
Language version: ActionScript 3.0

Creates a new Front Controller instance for the passed-in plugin. If the plugin argument is omitted, the Front Controller is owned by the global instance of the NullPluginParameters

owner:Plugin (default = null) — plugin object which own the controller
Method detail
add()method
public override function add(d:Dictionary):void

Player version: Flash Player 9.0
Language version: ActionScript 3.0

Adds all key/commands associations within the passed-in Dictionnary in the current front controller. The errors thrown by the pushCommandClass and pushCommandInstance are also thrown in the add method.

Parameters
d:Dictionary — a dictionary object used to fill ths controller

Throws
IllegalArgumentException — There is already a command or class registered with a key in the dictionary.
 
IllegalArgumentException — A command class in the dictionary doesn't inherit from Command interface.
 
NullPointerException — A command in the dictionary is null
getOwner()method 
public final function getOwner():Plugin

Player version: Flash Player 9.0
Language version: ActionScript 3.0

Returns the owner plugin of this controller

Returns
Plugin — the owner plugin of this controller
handleEvent()method 
public final function handleEvent(event:Event):void

Player version: Flash Player 9.0
Language version: ActionScript 3.0

Handles all events received by this object. For each received event the controller will look up its registered events table, if a command or a class is registered the controller proceed.

If the command object is an asynchronous command the instance is stored in a specific map in order to keep a reference to that command during all its execution, and prevent it to be collected by the garbage collector. The front controller will automatically remove the reference when it receive the onCommandEnd event from the command.

Parameters
event:Event — event object dispatched by the source object
locate()method 
public override function locate(key:String):Object

Player version: Flash Player 9.0
Language version: ActionScript 3.0

Returns the command located at the specified key index. If there's no command registered with the passed-in key the function fail and throw an error.

The locate method will always return a Command instance, even if it was a class which was registered with this key. The locate will instanciate the command and then return it.

Parameters
key:String

Returns
Object

Throws
NoSuchElementException — There is no command registered with the passed-in key
onCommandEnd()method 
public function onCommandEnd(e:Event):void

Player version: Flash Player 9.0
Language version: ActionScript 3.0

Catch callback events from asynchronous commands thiggered by this front controller. When the controller receive an event from the command, that command is removed from the controller storage.

Parameters
e:Event — event object propagated by the command
pushCommandClass()method 
public function pushCommandClass(eventName:String, commandClass:Class):Boolean

Player version: Flash Player 9.0
Language version: ActionScript 3.0

Registers the passed-in command class to be triggered at each time the controller will receive an event of type eventName.

The passed-in command class must at least implement the Command interface. If the class doesn't inherit from Command the association failed and an exception is throw.

If there is already a command or a class associated with the passed-in event, the association failed and an exception is throw.

Parameters
eventName:String — name of the event type with which the command will be registered
 
commandClass:Class — class to associate with the passed-in event type

Returns
Booleantrue if the command class have been succesfully registered with the passed-in event type

Throws
IllegalArgumentException — There is already a command or class registered with the specified key.
 
IllegalArgumentException — The passed-in command class doesn't inherit from Command interface.
pushCommandInstance()method 
public function pushCommandInstance(eventName:String, command:Command):Boolean

Player version: Flash Player 9.0
Language version: ActionScript 3.0

Registers the passed-in command to be triggered at each time the controller will receive an event of type eventName.

If there is already a class or a command associated with the passed-in event, the association failed and an exception is throw.

Parameters
eventName:String — name of the event type with which the command will be registered
 
command:Command — command to associate with the passed-in event type

Returns
Booleantrue if the command have been succesfully registered with the passed-in event type

Throws
IllegalArgumentException — There is already a command or class registered with the specified key.
 
NullPointerException — The passed-in command is null
register()method 
public override function register(eventName:String, o:Object):Boolean

Player version: Flash Player 9.0
Language version: ActionScript 3.0

Registers passed-in object with identifier name to this locator.

Parameters
eventName:String — Key identifier
 
o:Object — Object to store

Returns
Booleantrue if success
release()method 
public override function release():void

Player version: Flash Player 9.0
Language version: ActionScript 3.0

remove()method 
public function remove(eventName:String):void

Player version: Flash Player 9.0
Language version: ActionScript 3.0

Removes the class or the command registered with the passed-in event name.

Parameters
eventName:String — event name for which unregister associated command or class
toString()method 
public override function toString():String

Player version: Flash Player 9.0
Language version: ActionScript 3.0

Returns the string representation of this instance.

Returns
String — the string representation of this instance