org.puremvc.java.multicore.patterns.facade
Class Facade

java.lang.Object
  extended by org.puremvc.java.multicore.patterns.facade.Facade
All Implemented Interfaces:
IFacade, INotifier

public class Facade
extends Object
implements IFacade

A base Multiton IFacade implementation.

See Also:
Model, View, Controller

Field Summary
protected  Controller controller
          Reference to the Controller
protected static Map<String,Facade> instanceMap
           
protected  Model model
          Reference to the Model
protected  String multitonKey
          The Multiton Key for this Core
protected  View view
          Reference to the View
 
Constructor Summary
protected Facade()
          Default Constructor.
protected Facade(String key)
          Constructor.
 
Method Summary
static Facade getInstance(String key)
          Facade Multiton Factory method.
 boolean hasCommand(String notificationName)
          Check if a Command is registered for a given Notification
static boolean hasCore(String key)
          Check if a Core is registered or not.
 boolean hasMediator(String mediatorName)
          Check if a Mediator is registered or not.
 boolean hasProxy(String proxyName)
          Check if a Proxy is registered.
protected  void init(String key)
           
protected  void initializeController()
          Initialize the Controller.
protected  void initializeFacade()
          Initialize the Multiton Facade instance.
protected  void initializeModel()
          Initialize the Model.
 void initializeNotifier(String key)
          Initialize this INotifier instance.
protected  void initializeView()
          Initialize the View.
 void registerCommand(String noteName, ICommand command)
          Register an ICommand with the Controller by Notification name.
 void registerMediator(IMediator mediator)
          Register a IMediator with the View.
 void registerProxy(IProxy proxy)
          Register an IProxy with the Model by name.
 void removeCommand(String notificationName)
          Remove a previously registered ICommand to INotification mapping from the Controller.
static void removeCore(String key)
          Remove a Core.
 IMediator removeMediator(String mediatorName)
          Remove an IMediator from the View.
 IProxy removeProxy(String proxyName)
          Remove an IProxy from the Model by name.
 IMediator retrieveMediator(String mediatorName)
          Retrieve an IMediator from the View.
 IProxy retrieveProxy(String proxyName)
          Retrieve an IProxy from the Model by name.
 void sendNotification(String notificationName)
          Create and send an INotification.
 void sendNotification(String notificationName, Object body)
          Create and send an INotification.
 void sendNotification(String notificationName, Object body, String type)
          Create and send an INotification.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

controller

protected Controller controller
Reference to the Controller


model

protected Model model
Reference to the Model


view

protected View view
Reference to the View


multitonKey

protected String multitonKey
The Multiton Key for this Core


instanceMap

protected static Map<String,Facade> instanceMap
Constructor Detail

Facade

protected Facade()
Default Constructor. JavaFX class only extends Java class with default constructor.


Facade

protected Facade(String key)
Constructor.

This IFacade 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 Facade.getInstance( multitonKey )

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

init

protected void init(String key)

initializeFacade

protected void initializeFacade()
Initialize the Multiton Facade instance.

Called automatically by the constructor. Override in your subclass to do any subclass specific initializations. Be sure to call super.initializeFacade(), though.


getInstance

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

Returns:
the Multiton instance of the Facade

initializeController

protected void initializeController()
Initialize the Controller.

Called by the initializeFacade method. Override this method in your subclass of Facade if one or both of the following are true:

If you don't want to initialize a different IController, call super.initializeController() at the beginning of your method, then register Commands.


initializeModel

protected void initializeModel()
Initialize the Model.

Called by the initializeFacade method. Override this method in your subclass of Facade if one or both of the following are true:

If you don't want to initialize a different IModel, call super.initializeModel() at the beginning of your method, then register Proxys.

Note: This method is rarely overridden; in practice you are more likely to use a Command to create and register Proxys with the Model, since Proxys with mutable data will likely need to send INotifications and thus will likely want to fetch a reference to the Facade during their construction.


initializeView

protected void initializeView()
Initialize the View.

Called by the initializeFacade method. Override this method in your subclass of Facade if one or both of the following are true:

If you don't want to initialize a different IView, call super.initializeView() at the beginning of your method, then register IMediator instances.

Note: This method is rarely overridden; in practice you are more likely to use a Command to create and register Mediators with the View, since IMediator instances will need to send INotifications and thus will likely want to fetch a reference to the Facade during their construction.


registerCommand

public void registerCommand(String noteName,
                            ICommand command)
Register an ICommand with the Controller by Notification name.

Specified by:
registerCommand in interface IFacade
Parameters:
noteName - the name of the INotification to associate the ICommand with
command - an instance of the ICommand

removeCommand

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

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

hasCommand

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

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

registerMediator

public void registerMediator(IMediator mediator)
Register a IMediator with the View.

Specified by:
registerMediator in interface IFacade
Parameters:
mediator - the name to associate with this IMediator

registerProxy

public void registerProxy(IProxy proxy)
Register an IProxy with the Model by name.

Specified by:
registerProxy in interface IFacade
Parameters:
proxy - the name of the IProxy instance to be registered with the Model.

removeMediator

public IMediator removeMediator(String mediatorName)
Remove an IMediator from the View.

Specified by:
removeMediator in interface IFacade
Parameters:
mediatorName - name of the IMediator to be removed.
Returns:
the IMediator that was removed from the View

removeProxy

public IProxy removeProxy(String proxyName)
Remove an IProxy from the Model by name.

Specified by:
removeProxy in interface IFacade
Parameters:
proxyName - the IProxy to remove from the Model.
Returns:
the IProxy that was removed from the Model

hasProxy

public boolean hasProxy(String proxyName)
Check if a Proxy is registered.

Specified by:
hasProxy in interface IFacade
Parameters:
proxyName -
Returns:
whether a Proxy is currently registered with the given proxyName.

hasMediator

public boolean hasMediator(String mediatorName)
Check if a Mediator is registered or not.

Specified by:
hasMediator in interface IFacade
Parameters:
mediatorName -
Returns:
whether a Mediator is registered with the given mediatorName.

retrieveMediator

public IMediator retrieveMediator(String mediatorName)
Retrieve an IMediator from the View.

Specified by:
retrieveMediator in interface IFacade
Parameters:
mediatorName -
Returns:
the IMediator previously registered with the given mediatorName.

retrieveProxy

public IProxy retrieveProxy(String proxyName)
Retrieve an IProxy from the Model by name.

Specified by:
retrieveProxy in interface IFacade
Parameters:
proxyName - the name of the proxy to be retrieved.
Returns:
the IProxy instance previously registered with the given proxyName.

sendNotification

public void sendNotification(String notificationName,
                             Object body,
                             String type)
Create and send an INotification.

Keeps us from having to construct new notification instances in our implementation code.

Specified by:
sendNotification in interface INotifier
Parameters:
notificationName - the name of the notification to send
body - the body of the notification (optional)
type - the type of the notification (optional)

sendNotification

public void sendNotification(String notificationName,
                             Object body)
Create and send an INotification.

Keeps us from having to construct new notification instances in our implementation code.

Specified by:
sendNotification in interface INotifier
Parameters:
notificationName - the name of the notification to send
body - the body of the notification (optional)

sendNotification

public void sendNotification(String notificationName)
Create and send an INotification.

Keeps us from having to construct new notification instances in our implementation code.

Specified by:
sendNotification in interface INotifier
Parameters:
notificationName - the name of the notification to send

initializeNotifier

public void initializeNotifier(String key)
Description copied from interface: INotifier
Initialize this INotifier instance.

This is how a Notifier gets its multitonKey. Calls to sendNotification or to access the facade will fail until after this method has been called.

Specified by:
initializeNotifier in interface INotifier
Parameters:
key - the multitonKey for this INotifier to use

hasCore

public static boolean hasCore(String key)
Check if a Core is registered or not.

Parameters:
key - the multiton key for the Core in question
Returns:
whether a Core is registered with the given key.

removeCore

public static void removeCore(String key)
Remove a Core.

Parameters:
multitonKey - of the Core to remove


Copyright © 2010. All Rights Reserved.