home *** CD-ROM | disk | FTP | other *** search
- package org.puremvc.as3.patterns.facade
- {
- import org.puremvc.as3.core.controller.Controller;
- import org.puremvc.as3.core.model.Model;
- import org.puremvc.as3.core.view.View;
- import org.puremvc.as3.interfaces.IController;
- import org.puremvc.as3.interfaces.IFacade;
- import org.puremvc.as3.interfaces.IMediator;
- import org.puremvc.as3.interfaces.IModel;
- import org.puremvc.as3.interfaces.INotification;
- import org.puremvc.as3.interfaces.IProxy;
- import org.puremvc.as3.interfaces.IView;
- import org.puremvc.as3.patterns.observer.Notification;
-
- public class Facade implements IFacade
- {
-
- protected static var instance:IFacade;
-
-
- protected const SINGLETON_MSG:String = "Facade Singleton already constructed!";
-
- protected var controller:IController;
-
- protected var view:IView;
-
- protected var model:IModel;
-
- public function Facade()
- {
- super();
- if(instance != null)
- {
- throw Error(SINGLETON_MSG);
- }
- instance = this;
- initializeFacade();
- }
-
- public static function getInstance() : IFacade
- {
- if(instance == null)
- {
- instance = new Facade();
- }
- return instance;
- }
-
- public function removeProxy(proxyName:String) : IProxy
- {
- var proxy:IProxy = null;
- if(model != null)
- {
- proxy = model.removeProxy(proxyName);
- }
- return proxy;
- }
-
- public function registerProxy(proxy:IProxy) : void
- {
- model.registerProxy(proxy);
- }
-
- protected function initializeController() : void
- {
- if(controller != null)
- {
- return;
- }
- controller = Controller.getInstance();
- }
-
- protected function initializeFacade() : void
- {
- initializeModel();
- initializeController();
- initializeView();
- }
-
- public function retrieveProxy(proxyName:String) : IProxy
- {
- return model.retrieveProxy(proxyName);
- }
-
- public function sendNotification(notificationName:String, body:Object = null, type:String = null) : void
- {
- notifyObservers(new Notification(notificationName,body,type));
- }
-
- public function notifyObservers(notification:INotification) : void
- {
- if(view != null)
- {
- view.notifyObservers(notification);
- }
- }
-
- protected function initializeView() : void
- {
- if(view != null)
- {
- return;
- }
- view = View.getInstance();
- }
-
- public function retrieveMediator(mediatorName:String) : IMediator
- {
- return view.retrieveMediator(mediatorName) as IMediator;
- }
-
- public function removeMediator(mediatorName:String) : IMediator
- {
- var mediator:IMediator = null;
- if(view != null)
- {
- mediator = view.removeMediator(mediatorName);
- }
- return mediator;
- }
-
- public function hasCommand(notificationName:String) : Boolean
- {
- return controller.hasCommand(notificationName);
- }
-
- public function removeCommand(notificationName:String) : void
- {
- controller.removeCommand(notificationName);
- }
-
- public function registerCommand(notificationName:String, commandClassRef:Class) : void
- {
- controller.registerCommand(notificationName,commandClassRef);
- }
-
- public function hasMediator(mediatorName:String) : Boolean
- {
- return view.hasMediator(mediatorName);
- }
-
- public function registerMediator(mediator:IMediator) : void
- {
- if(view != null)
- {
- view.registerMediator(mediator);
- }
- }
-
- protected function initializeModel() : void
- {
- if(model != null)
- {
- return;
- }
- model = Model.getInstance();
- }
-
- public function hasProxy(proxyName:String) : Boolean
- {
- return model.hasProxy(proxyName);
- }
- }
- }
-