Class View
- All Implemented Interfaces:
 IView
public class View extends java.lang.Object implements IView
A Singleton IView implementation.
In PureMVC, the View class assumes these responsibilities:
- Maintain a cache of 
IMediatorinstances. - Provide methods for registering, retrieving, and removing 
IMediators. - Notifiying 
IMediatorswhen they are registered or removed. - Managing the observer lists for each 
INotificationin the application. - Providing a method for attaching 
IObserversto anINotification's observer list. - Providing a method for broadcasting an 
INotification. - Notifying the 
IObserversof a givenINotificationwhen it broadcast. 
- See Also:
 Mediator,Observer,Notification
- 
Field Summary
Fields Modifier and Type Field Description protected static IViewinstanceprotected java.util.concurrent.ConcurrentMap<java.lang.String,IMediator>mediatorMapprotected java.util.concurrent.ConcurrentMap<java.lang.String,java.util.List<IObserver>>observerMapprotected java.lang.StringSINGLETON_MSG - 
Constructor Summary
Constructors Constructor Description View()Constructor. - 
Method Summary
Modifier and Type Method Description static IViewgetInstance(java.util.function.Supplier<IView> factory)View Singleton Factory method.booleanhasMediator(java.lang.String mediatorName)Check if a Mediator is registered or notprotected voidinitializeView()Initialize the Singleton View instance.voidnotifyObservers(INotification notification)Notify theIObserversfor a particularINotification.voidregisterMediator(IMediator mediator)Register anIMediatorinstance with theView.voidregisterObserver(java.lang.String notificationName, IObserver observer)Register anIObserverto be notified ofINotificationswith a given name.IMediatorremoveMediator(java.lang.String mediatorName)Remove anIMediatorfrom theView.voidremoveObserver(java.lang.String notificationName, java.lang.Object notifyContext)Remove the observer for a given notifyContext from an observer list for a given Notification name.IMediatorretrieveMediator(java.lang.String mediatorName)Retrieve anIMediatorfrom theView. 
- 
Field Details
- 
mediatorMap
 - 
observerMap
protected java.util.concurrent.ConcurrentMap<java.lang.String,java.util.List<IObserver>> observerMap - 
instance
 - 
SINGLETON_MSG
protected final java.lang.String SINGLETON_MSG- See Also:
 - Constant Field Values
 
 
 - 
 - 
Constructor Details
- 
View
public View()Constructor.
This
IViewimplementation is a Singleton, so you should not call the constructor directly, but instead call the static Singleton Factory methodView.getInstance()- Throws:
 java.lang.Error- Error if Singleton instance has already been constructed
 
 - 
 - 
Method Details
- 
getInstance
View Singleton Factory method.
- Parameters:
 factory- view supplier function- Returns:
 - the Singleton instance of 
View 
 - 
initializeView
protected void initializeView()Initialize the Singleton View instance.
Called automatically by the constructor, this is your opportunity to initialize the Singleton instance in your subclass without overriding the constructor.
 - 
registerObserver
Register an
IObserverto be notified ofINotificationswith a given name.- Specified by:
 registerObserverin interfaceIView- Parameters:
 notificationName- the name of theINotificationsto notify thisIObserverofobserver- theIObserverto register
 - 
notifyObservers
Notify the
IObserversfor a particularINotification.All previously attached
IObserversfor thisINotification's list are notified and are passed a reference to theINotificationin the order in which they were registered.- Specified by:
 notifyObserversin interfaceIView- Parameters:
 notification- theINotificationto notifyIObserversof.
 - 
removeObserver
public void removeObserver(java.lang.String notificationName, java.lang.Object notifyContext)Remove the observer for a given notifyContext from an observer list for a given Notification name.
- Specified by:
 removeObserverin interfaceIView- Parameters:
 notificationName- which observer list to remove fromnotifyContext- remove the observer with this object as its notifyContext
 - 
registerMediator
Register an
IMediatorinstance with theView.Registers the
IMediatorso that it can be retrieved by name, and further interrogates theIMediatorfor itsINotificationinterests.If the
IMediatorreturns anyINotificationnames to be notified about, anObserveris created encapsulating theIMediatorinstance'shandleNotificationmethod and registering it as anObserverfor allINotificationstheIMediatoris interested in.- Specified by:
 registerMediatorin interfaceIView- Parameters:
 mediator- a reference to theIMediatorinstance
 - 
retrieveMediator
Retrieve an
IMediatorfrom theView.- Specified by:
 retrieveMediatorin interfaceIView- Parameters:
 mediatorName- the name of theIMediatorinstance to retrieve.- Returns:
 - the 
IMediatorinstance previously registered with the givenmediatorName. 
 - 
removeMediator
Remove an
IMediatorfrom theView.- Specified by:
 removeMediatorin interfaceIView- Parameters:
 mediatorName- name of theIMediatorinstance to be removed.- Returns:
 - the 
IMediatorthat was removed from theView 
 - 
hasMediator
public boolean hasMediator(java.lang.String mediatorName)Check if a Mediator is registered or not
- Specified by:
 hasMediatorin interfaceIView- Parameters:
 mediatorName- mediator name- Returns:
 - whether a Mediator is registered with the given 
mediatorName. 
 
 -