Coverage Report - org.vostokframework.application.monitoring.monitors.dispatchers.AssetLoadingMonitorDispatcher
 
Classes in this File Line Coverage Branch Coverage Complexity
AssetLoadingMonitorDispatcher
66%
20/30
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.dispatchers
 30  
 {
 31  
         import org.as3collections.IList;
 32  
         import org.as3utils.StringUtil;
 33  
         import org.vostokframework.application.events.AssetLoadingErrorEvent;
 34  
         import org.vostokframework.application.events.AssetLoadingEvent;
 35  
         import org.vostokframework.application.monitoring.LoadingMonitoring;
 36  
         import org.vostokframework.application.monitoring.monitors.LoadingMonitorDispatcher;
 37  
         import org.vostokframework.domain.assets.AssetType;
 38  
 
 39  
         /**
 40  
          * @author Flavio
 41  
          * @version 1.0
 42  
          * @created 14-mai-2011 12:02:52
 43  
          */
 44  
         public class AssetLoadingMonitorDispatcher extends LoadingMonitorDispatcher
 45  
         {
 46  
                 /**
 47  
                  * @private
 48  
                  */
 49  
                 private var _assetId:String;
 50  
                 private var _assetLocale:String;
 51  
                 private var _assetType:AssetType;
 52  
                 
 53  
                 /**
 54  
                  * 
 55  
                  */
 56  
                 public function AssetLoadingMonitorDispatcher(assetId:String, assetLocale:String, assetType:AssetType)
 57  1
                 {
 58  1
                         if (StringUtil.isBlank(assetId)) throw new ArgumentError("Argument <assetId> must not be null nor an empty String.");
 59  1
                         if (StringUtil.isBlank(assetLocale)) throw new ArgumentError("Argument <assetLocale> must not be null nor an empty String.");
 60  1
                         if (!assetType) throw new ArgumentError("Argument <assetType> must not be null.");
 61  
                         
 62  1
                         _assetId = assetId;
 63  1
                         _assetLocale = assetLocale;
 64  1
                         _assetType = assetType;
 65  1
                 }
 66  
                 
 67  
                 override public function dispatchCanceledEvent(monitoring:LoadingMonitoring):void
 68  
                 {
 69  1
                         dispatchEvent(createEvent(AssetLoadingEvent.CANCELED, monitoring));
 70  1
                 }
 71  
                 
 72  
                 override public function dispatchCompleteEvent(monitoring:LoadingMonitoring, data:* = null):void
 73  
                 {
 74  1
                         dispatchEvent(createEvent(AssetLoadingEvent.COMPLETE, monitoring, data));
 75  1
                 }
 76  
                 
 77  
                 override public function dispatchFailedEvent(monitoring:LoadingMonitoring, errors:IList):void
 78  
                 {
 79  0
                         dispatchEvent(createErrorEvent(AssetLoadingErrorEvent.FAILED, monitoring, errors));
 80  0
                 }
 81  
                 
 82  
                 override public function dispatchHttpStatusEvent(monitoring:LoadingMonitoring, status:int):void
 83  
                 {
 84  0
                         var event:AssetLoadingEvent = createEvent(AssetLoadingEvent.HTTP_STATUS, monitoring);
 85  0
                         event.httpStatus = status;
 86  0
                         dispatchEvent(event);
 87  0
                 }
 88  
                 
 89  
                 override public function dispatchInitEvent(monitoring:LoadingMonitoring, data:* = null):void
 90  
                 {
 91  0
                         dispatchEvent(createEvent(AssetLoadingEvent.INIT, monitoring, data));
 92  0
                 }
 93  
                 
 94  
                 override public function dispatchOpenEvent(monitoring:LoadingMonitoring, data:* = null):void
 95  
                 {
 96  1
                         dispatchEvent(createEvent(AssetLoadingEvent.OPEN, monitoring, data));
 97  1
                 }
 98  
                 
 99  
                 override public function dispatchProgressEvent(monitoring:LoadingMonitoring):void
 100  
                 {
 101  1
                         dispatchEvent(createEvent(AssetLoadingEvent.PROGRESS, monitoring));
 102  1
                 }
 103  
                 
 104  
                 override public function dispatchStoppedEvent(monitoring:LoadingMonitoring):void
 105  
                 {
 106  1
                         dispatchEvent(createEvent(AssetLoadingEvent.STOPPED, monitoring));
 107  1
                 }
 108  
                 
 109  
                 override public function typeBelongs(type:String):Boolean
 110  
                 {
 111  0
                         return AssetLoadingEvent.typeBelongs(type);
 112  
                 }
 113  
                 
 114  
                 private function createEvent(type:String, monitoring:LoadingMonitoring, data:* = null):AssetLoadingEvent
 115  
                 {
 116  1
                         return new AssetLoadingEvent(type, _assetId, _assetLocale, _assetType, monitoring, data);
 117  
                 }
 118  
                 
 119  
                 private function createErrorEvent(type:String, monitoring:LoadingMonitoring, errors:IList):AssetLoadingErrorEvent
 120  
                 {
 121  0
                         return new AssetLoadingErrorEvent(type, _assetId, _assetLocale, _assetType, errors, monitoring);
 122  
                 }
 123  
                 
 124  
         }
 125  
 
 126  
 }