Over 10 years of community discussion and knowledge are maintained here as a read-only archive.
public interface IHandler{ function handle(notification:INotification); }public class NotificationHandler implements IHandler{ protected var viewComponent:Object; public function NotificationHandler(viewComponent:Object) { super(); this.viewComponent = viewComponent; } public function handle(notification:INotification):void { // Do nothing, just a base class for other handler classes }}public class BaseMediator extends Mediator{ protected var handler:IHandler; override public function handleNotification(notification:INotification):void { // If the control reaches here means that the implementing // class has not overidden the handleNotification funciton. // Try to handle the notification if the IHandler is set // otherwise just do a NO-OP if(handler) { handler.handle(notification); } }}public class MyModuleHandler extends NotificationHandler{ override public function handle(notification:INotification):void { // do something interesting here with the notifications } }public class MyMediator extends BaseMediator{ public static const FIRST_NOTIFICATION:String = 'FIRST_NOTIFICATION'; public static const SECOND_NOTIFICATION:String = 'SECOND_NOTIFICATION'; public function MyMediator(mediatorName:String=null, viewComponent:Object=null) { super(mediatorName, viewComponent); } override public function onRegister():void { handler = new MyModuleHandler(viewComponent); } override public function listNotificationInterests():Array { return [ FIRST_NOTIFICATION, SECOND_NOTIFICATION ]; }}
public class PrattlerJunctionMediator extends LoggingJunctionMediator { public static const NAME:String = 'PrattlerJunctionMediator'; /** * Constructor. * <P> * Creates and registers its own STDIN pipe * and adds this instance as a listener, * because the logger uses a TeeMerge and * new inputs are added to it rather than * as separate pipes registered with the * Junction.</P> */ public function PrattlerJunctionMediator( ) { super( NAME, new Junction() ); } /** * List Notification Interests. * <P> * Adds subclass interests to those of the JunctionMediator.</P> */ override public function listNotificationInterests():Array { var interests:Array = super.listNotificationInterests(); interests.push(ApplicationFacade.EXPORT_FEED_WINDOW); return interests; } /** * Handle Junction related Notifications for the PrattlerModule. * <P> * For the Prattler, this consists of exporting the * FeedWindow in a PipeMessage to STDSHELL, as well as the * ordinary JunctionMediator duties of accepting input * and output pipes from the Shell.</P> * <P> * Also send messages to the logger (via the direct superclass * LoggingJunctionMediator.</P> */ override public function handleNotification( note:INotification ):void { switch( note.getName() ) { // Send the FeedWindow Component case ApplicationFacade.EXPORT_FEED_WINDOW: var prattlerWindowMessage:UIQueryMessage = new UIQueryMessage( UIQueryMessage.SET, PrattlerModule.FEED_WINDOW_UI, UIComponent(note.getBody()) ); junction.sendMessage( PipeAwareModule.STDSHELL, prattlerWindowMessage ); break; // And let super handle the rest (ACCEPT_OUTPUT_PIPE, ACCEPT_INPUT_PIPE, SEND_TO_LOG) default: super.handleNotification(note); } } }}