org.puremvc.java.multicore.core.controller
Class Controller

java.lang.Object
  extended by org.puremvc.java.multicore.core.controller.Controller
All Implemented Interfaces:
IController

public class Controller
extends Object
implements IController

A Multiton IController implementation.

In PureMVC, the Controller class follows the 'Command and Controller' strategy, and assumes these responsibilities:

Your application must register ICommands with the Controller.

The simplest way is to subclass Facade, and use its initializeController method to add your registrations.

See Also:
View, Observer, Notification, SimpleCommand, MacroCommand

Field Summary
protected  Map<String,ICommand> commandMap
          Mapping of Notification names to Command Class references
protected static Map<String,Controller> instanceMap
           
protected  String multitonKey
          The Multiton Key for this Core
protected  View view
          Local reference to View
 
Constructor Summary
protected Controller(String key)
          Constructor.
 
Method Summary
 void executeCommand(INotification note)
          If an ICommand has previously been registered to handle a the given INotification, then it is executed.
static Controller getInstance(String key)
          Controller Multiton Factory method.
 boolean hasCommand(String notificationName)
          Check if a Command is registered for a given Notification
protected  void initializeController()
          Initialize the Multiton Controller instance.
 void registerCommand(String notificationName, ICommand command)
          Register a particular ICommand class as the handler for a particular INotification.
 void removeCommand(String notificationName)
          Remove a previously registered ICommand to INotification mapping.
static void removeController(String key)
          Remove an IController instance
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

commandMap

protected Map<String,ICommand> commandMap
Mapping of Notification names to Command Class references


view

protected View view
Local reference to View


multitonKey

protected String multitonKey
The Multiton Key for this Core


instanceMap

protected static Map<String,Controller> instanceMap
Constructor Detail

Controller

protected Controller(String key)
Constructor.

This IController implementation is a Multiton, so you should not call the constructor directly, but instead call the static Factory method, passing the unique key for this instance Controller.getInstance( multitonKey )

Throws:
Error - Error if instance for this Multiton key has already been constructed
Method Detail

initializeController

protected void initializeController()
Initialize the Multiton Controller instance.

Called automatically by the constructor.

Note that if you are using a subclass of View in your application, you should also subclass Controller and override the initializeController method in the following way:

// ensure that the Controller is talking to my IView implementation override public function initializeController( ) : void { view = MyView.getInstance(); }


getInstance

public static Controller getInstance(String key)
Controller Multiton Factory method.

Returns:
the Multiton instance of Controller

executeCommand

public void executeCommand(INotification note)
If an ICommand has previously been registered to handle a the given INotification, then it is executed.

Specified by:
executeCommand in interface IController
Parameters:
note - an INotification

registerCommand

public void registerCommand(String notificationName,
                            ICommand command)
Register a particular ICommand class as the handler for a particular INotification.

If an ICommand has already been registered to handle INotifications with this name, it is no longer used, the new ICommand is used instead.

The Observer for the new ICommand is only created if this the first time an ICommand has been regisered for this Notification name.

Specified by:
registerCommand in interface IController
Parameters:
notificationName - the name of the INotification
command - an instance of ICommand

removeCommand

public void removeCommand(String notificationName)
Remove a previously registered ICommand to INotification mapping.

Specified by:
removeCommand in interface IController
Parameters:
notificationName - the name of the INotification to remove the ICommand mapping for

removeController

public static void removeController(String key)
Remove an IController instance

Parameters:
multitonKey - of IController instance to remove

hasCommand

public boolean hasCommand(String notificationName)
Check if a Command is registered for a given Notification

Specified by:
hasCommand in interface IController
Parameters:
notificationName -
Returns:
whether a Command is currently registered for the given notificationName.


Copyright © 2010. All Rights Reserved.