Coverage Report - org.vostokframework.application.monitoring.monitors.LoadingMonitorWrapper
 
Classes in this File Line Coverage Branch Coverage Complexity
LoadingMonitorWrapper
78%
37/47
N/A
0
 
 1  
 /*
 2  
  * Licensed under the MIT License
 3  
  * 
 4  
  * Copyright 2011 (c) Flávio Silva, flsilva.com
 5  
  *
 6  
  * Permission is hereby granted, free of charge, to any person
 7  
  * obtaining a copy of this software and associated documentation
 8  
  * files (the "Software"), to deal in the Software without
 9  
  * restriction, including without limitation the rights to use,
 10  
  * copy, modify, merge, publish, distribute, sublicense, and/or sell
 11  
  * copies of the Software, and to permit persons to whom the
 12  
  * Software is furnished to do so, subject to the following
 13  
  * conditions:
 14  
  *
 15  
  * The above copyright notice and this permission notice shall be
 16  
  * included in all copies or substantial portions of the Software.
 17  
  *
 18  
  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 19  
  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
 20  
  * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 21  
  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
 22  
  * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
 23  
  * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 24  
  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 25  
  * OTHER DEALINGS IN THE SOFTWARE.
 26  
  * 
 27  
  * http://www.opensource.org/licenses/mit-license.php
 28  
  */
 29  1
 package org.vostokframework.application.monitoring.monitors
 30  
 {
 31  
         import org.as3collections.IIterator;
 32  
         import org.as3collections.IList;
 33  
         import org.as3collections.lists.ArrayList;
 34  
         import org.as3collections.utils.ListUtil;
 35  
         import org.vostokframework.VostokIdentification;
 36  
         import org.vostokframework.application.monitoring.ILoadingMonitor;
 37  
         import org.vostokframework.application.monitoring.LoadingMonitoring;
 38  
         import org.vostokframework.domain.loading.ILoader;
 39  
 
 40  
         import flash.events.Event;
 41  
 
 42  
         /**
 43  
          * description
 44  
          * 
 45  
          * @author Flávio Silva
 46  
          */
 47  
         public class LoadingMonitorWrapper implements ILoadingMonitor
 48  
         {
 49  
                 
 50  
                 private var _listeners:IList;
 51  
                 private var _monitor:ILoadingMonitor;
 52  
                 
 53  
                 public function get id():String { return "test"; }
 54  
                 
 55  
                 public function get loader():ILoader { return _monitor.loader; }
 56  
                 
 57  
                 public function get monitoring():LoadingMonitoring { return _monitor.monitoring; }
 58  
                 
 59  
                 /**
 60  
                  * description
 61  
                  * 
 62  
                  * @param requestId
 63  
                  * @param loaders
 64  
                  */
 65  
                 public function LoadingMonitorWrapper(monitor:ILoadingMonitor = null)
 66  1
                 {
 67  1
                         _listeners = ListUtil.getUniqueTypedList(new ArrayList(), EventListener);
 68  1
                         if (monitor) changeMonitor(monitor);
 69  1
                 }
 70  
                 
 71  
                 public function addEventListener(type : String, listener : Function, useCapture : Boolean = false, priority : int = 0, useWeakReference : Boolean = false) : void
 72  
                 {
 73  1
                         var eventListener:EventListener = new EventListener(type, listener, useCapture, priority, useWeakReference);
 74  1
                         _listeners.add(eventListener);
 75  
                         
 76  1
                         _monitor.addEventListener(type, listener, useCapture, priority, useWeakReference);
 77  1
                 }
 78  
                 
 79  
                 public function addChild(child:ILoadingMonitor):void
 80  
                 {
 81  1
                         _monitor.addChild(child);
 82  1
                 }
 83  
                 
 84  
                 public function addChildren(children:IList):void
 85  
                 {
 86  0
                         _monitor.addChildren(children);
 87  0
                 }
 88  
                 
 89  
                 public function changeMonitor(monitor:ILoadingMonitor):void
 90  
                 {
 91  1
                         if (!monitor) throw new ArgumentError("Argument <monitor> must not be null.");
 92  
                         
 93  1
                         if (_monitor) removeListenersFromMonitor(_monitor);
 94  
                         
 95  1
                         _monitor = monitor;
 96  
                         
 97  1
                         addListenersOnMonitor();
 98  1
                 }
 99  
                 
 100  
                 public function containsChild(identification:VostokIdentification):Boolean
 101  
                 {
 102  1
                         return _monitor.containsChild(identification);
 103  
                 }
 104  
                 
 105  
                 public function dispatchEvent(event: Event) : Boolean
 106  
                 {
 107  0
                         return _monitor.dispatchEvent(event);
 108  
                 }
 109  
                 
 110  
                 public function dispose():void
 111  
                 {
 112  0
                         if (_monitor)
 113  
                         {
 114  0
                                 removeListenersFromMonitor(_monitor);
 115  0
                                 _monitor.dispose();
 116  
                         }
 117  
                         
 118  0
                         _listeners.clear();
 119  0
                         _listeners = null;
 120  0
                 }
 121  
                 
 122  
                 public function getChild(identification:VostokIdentification):ILoadingMonitor
 123  
                 {
 124  1
                         return _monitor.getChild(identification);
 125  
                 }
 126  
                 
 127  
                 public function hasEventListener(type : String) : Boolean
 128  
                 {
 129  1
                         return _monitor.hasEventListener(type);
 130  
                 }
 131  
                 
 132  
                 public function removeEventListener(type : String, listener : Function, useCapture : Boolean = false) : void
 133  
                 {
 134  1
                         _monitor.removeEventListener(type, listener, useCapture);
 135  
                         
 136  1
                         var eventListener:EventListener = new EventListener(type, listener, useCapture);
 137  1
                         _listeners.remove(eventListener);
 138  1
                 }
 139  
                 
 140  
                 public function removeChild(identification:VostokIdentification):void
 141  
                 {
 142  1
                         _monitor.removeChild(identification);
 143  1
                 }
 144  
                 
 145  
                 public function willTrigger(type : String) : Boolean
 146  
                 {
 147  0
                         return _monitor.willTrigger(type);
 148  
                 }
 149  
                 
 150  
                 private function addListenersOnMonitor():void
 151  
                 {
 152  1
                         if (_listeners.isEmpty()) return;
 153  
                         
 154  1
                         var it:IIterator = _listeners.iterator();
 155  
                         var eventListener:EventListener;
 156  
                         
 157  1
                         while (it.hasNext())
 158  
                         {
 159  1
                                 eventListener = it.next();
 160  1
                                 _monitor.addEventListener(eventListener.type, eventListener.listener, eventListener.useCapture, eventListener.priority, eventListener.useWeakReference);
 161  
                         }
 162  1
                 }
 163  
                 
 164  
                 private function removeListenersFromMonitor(monitor:ILoadingMonitor):void
 165  
                 {
 166  1
                         if (_listeners.isEmpty()) return;
 167  
                         
 168  1
                         var it:IIterator = _listeners.iterator();
 169  
                         var eventListener:EventListener;
 170  
                         
 171  1
                         while (it.hasNext())
 172  
                         {
 173  1
                                 eventListener = it.next();
 174  1
                                 monitor.removeEventListener(eventListener.type, eventListener.listener, eventListener.useCapture);
 175  
                         }
 176  1
                 }
 177  
         }
 178  
 
 179  
 }