FrontController
| Kind of class: | public class |
|---|---|
| Package: | com.bourre.commands |
| Inherits from: | AbstractLocator |
| Implements: | |
| Author: | Francis Bourre |
| Classpath: | com.bourre.commands.FrontController |
| File last modified: | Tuesday, 15 April 2008, 09:25:44 |
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 theFrontController 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.
Summary
- pushCommandClass (eventName:String, commandClass:Class) : Boolean
- Creates a new Front Controller instance for the passed-in
- pushCommandInstance (eventName:String, command:Command) : Boolean
- Registers the passed-in command to be triggered at each time
- remove (eventName:String) : void
- Removes the class or the command registered with the
- handleEvent (event:Event) : void
- Handles all events received by this object.
- locate (key:String) : Object
- Returns the command located at the specified keyindex.
- add (d:Dictionary) : void
- Adds all key/commands associations within the passed-in
- release : void
- toString : String
- Returns the string representation of this instance.
- onCommandEnd (e:Event) : void
- Catch callback events from asynchronous commands thiggered
Instance methods
add
Dictionnary in the current front controller.The errors thrown by the
pushCommandClass andpushCommandInstance are also thrown in theadd method. - {VISDOC_LINK_0}
IllegalArgumentException— There is already
a command or class registered with a key in the dictionary. - {VISDOC_LINK_1}
IllegalArgumentException— A command class
in the dictionary doesn't inherit from Command interface. - {VISDOC_LINK_2}
NullPointerException— A command in the
dictionary is null
handleEvent
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.
source object
locate
keyindex. If there's no command registered with the passed-in keythe function fail and throw an error.
The locate method will always return a Commandinstance, even if it was a class which was registered with this key.
The locate will instanciate the command and then return it.
- {VISDOC_LINK_0}
NoSuchElementException— There is no command
registered with the passed-in key
pushCommandClass
plugin. If the plugin argument is omitted, the Front Controller
is owned by the global instance of the
NullPlugin</code.
class.
@param owner plugin object which own the controller
/ public function FrontController( owner : Plugin = null ) { _owner = ( owner == null ) ? NullPlugin.getInstance() : owner; if ( owner == null ) EventBroadcaster.getInstance().addListener( this ); super( Command, null, PluginDebug.getInstance( getOwner() ) ); _oASyncCommands = new Dictionary(); } /**
Returns the owner plugin of this controller
@return the owner plugin of this controller
/ final public function getOwner() : Plugin { return _owner; } /**
@inheritDoc
/ override public function register( eventName : String, o : Object ) : Boolean { try { if ( o is Class ) { return pushCommandClass( eventName, o as Class ); } else { return pushCommandInstance( eventName, o as Command ); } } catch( e : Error ) { getLogger().fatal( e.message ); throw e; } return false; } /**
Registers the passed-in command class to be triggered at each time
the controller will receive an event of type <code>eventName
The passed-in command class must at least implement the Commandinterface. 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.
will be registered
-
trueif the command class have been succesfully
registered with the passed-in event type
- {VISDOC_LINK_0}
IllegalArgumentException— There is already
a command or class registered with the specified key. - {VISDOC_LINK_1}
IllegalArgumentException— The passed-in command
class doesn't inherit from Command interface.
pushCommandInstance
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.
will be registered
-
trueif the command have been succesfully
registered with the passed-in event type
- {VISDOC_LINK_0}
IllegalArgumentException— There is already
a command or class registered with the specified key. - {VISDOC_LINK_1}
NullPointerException— The passed-in command
is null
remove
passed-in event name.
associated command or class
toString
- the string representation of this instance
Event handlers
onCommandEnd
by this front controller. When the controller receive an event
from the command, that command is removed from the controller
storage.