|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.puremvc.java.core.Controller
public class Controller
A Singleton IController
implementation.
In PureMVC, the Controller
class follows the
'Command and Controller' strategy, and assumes these
responsibilities:
ICommand
s
are intended to handle which INotifications
.IObserver
with
the View
for each INotification
that it has an ICommand
mapping for.ICommand
to handle a given INotification
when notified by the View
.ICommand
's execute
method, passing in the INotification
.
Your application must register ICommands
with the
Controller.
The simplest way is to subclass Facade,
and use its initializeController
method to add your
registrations.
View
,
Observer
,
Notification
,
SimpleCommand
,
MacroCommand
Field Summary | |
---|---|
protected java.util.Map<java.lang.String,ICommand> |
commandMap
Mapping of Notification names to Command Class references |
protected static Controller |
instance
Reference to the singleton instance |
protected View |
view
Local reference to View |
Constructor Summary | |
---|---|
protected |
Controller()
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()
Controller Singleton Factory method. |
boolean |
hasCommand(java.lang.String notificationName)
Check if a Command is registered for a given Notification |
protected void |
initializeController()
Initialize the Singleton Controller instance. |
void |
registerCommand(java.lang.String notificationName,
ICommand command)
Register a particular ICommand class as the handler for a
particular INotification . |
void |
removeCommand(java.lang.String notificationName)
Remove a previously registered ICommand to
INotification mapping. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected static Controller instance
protected java.util.Map<java.lang.String,ICommand> commandMap
protected View view
Constructor Detail |
---|
protected Controller()
This IController
implementation is a Singleton, so you
should not call the constructor directly, but instead call the static
Singleton Factory method Controller.getInstance()
Method Detail |
---|
protected void initializeController()
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:
public static Controller getInstance()
Controller
Singleton Factory method.
Controller
public void executeCommand(INotification note)
ICommand
has previously been registered to handle a
the given INotification
, then it is executed.
executeCommand
in interface IController
note
- The notification to send associated with the command to call.public void registerCommand(java.lang.String notificationName, ICommand command)
ICommand
class as the handler for a
particular INotification
.
If an ICommand
has already been registered to handle
INotification
s with this name, it is no longer used, the
new ICommand
is used instead.
registerCommand
in interface IController
notificationName
- the name of the INotification
command
- an instance of ICommand
public void removeCommand(java.lang.String notificationName)
ICommand
to
INotification
mapping.
removeCommand
in interface IController
notificationName
- the name of the INotification
to remove the
ICommand
mapping forpublic boolean hasCommand(java.lang.String notificationName)
hasCommand
in interface IController
notificationName
- The name of the command to check for existance.
notificationName
.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |