Coverage Report - org.vostokframework.domain.loading.states.fileloader.algorithms.FileLoadingAlgorithmBehavior
 
Classes in this File Line Coverage Branch Coverage Complexity
FileLoadingAlgorithmBehavior
87%
34/39
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.domain.loading.states.fileloader.algorithms
 30  
 {
 31  
         import org.as3collections.IList;
 32  
         import org.as3coreaddendum.errors.ObjectDisposedError;
 33  
         import org.as3utils.ReflectionUtil;
 34  
         import org.vostokframework.domain.loading.states.fileloader.IFileLoadingAlgorithm;
 35  
 
 36  
         import flash.errors.IllegalOperationError;
 37  
         import flash.events.Event;
 38  
 
 39  
         /**
 40  
          * description
 41  
          * 
 42  
          * @author Flávio Silva
 43  
          */
 44  
         public class FileLoadingAlgorithmBehavior implements IFileLoadingAlgorithm
 45  
         {
 46  
                 /**
 47  
                  * @private
 48  
                   */
 49  
                 private var _disposed:Boolean;
 50  
                 private var _errors:IList;
 51  
                 private var _wrappedAlgorithm:IFileLoadingAlgorithm;
 52  
                 
 53  
                 protected function get errors():IList { return _errors; }
 54  
                 
 55  
                 protected function get wrappedAlgorithm():IFileLoadingAlgorithm { return _wrappedAlgorithm; }
 56  
                 
 57  
                 /**
 58  
                  * description
 59  
                  * 
 60  
                  * @param loader
 61  
                  * @param request
 62  
                  * @param context
 63  
                  */
 64  
                 public function FileLoadingAlgorithmBehavior(wrapAlgorithm:IFileLoadingAlgorithm)
 65  1
                 {
 66  1
                         if (ReflectionUtil.classPathEquals(this, FileLoadingAlgorithmBehavior))  throw new IllegalOperationError(ReflectionUtil.getClassName(this) + " is an abstract class and shouldn't be directly instantiated.");
 67  1
                         if (!wrapAlgorithm) throw new ArgumentError("Argument <wrapAlgorithm> must not be null.");
 68  
                         
 69  1
                         _wrappedAlgorithm = wrapAlgorithm;
 70  1
                 }
 71  
                 
 72  
                 public function addEventListener(type : String, listener : Function, useCapture : Boolean = false, priority : int = 0, useWeakReference : Boolean = false) : void
 73  
                 {
 74  1
                         validateDisposal();
 75  1
                         _wrappedAlgorithm.addEventListener(type, listener, useCapture, priority, useWeakReference);
 76  1
                 }
 77  
                 
 78  
                 public function addParsers(parsers:IList):void
 79  
                 {
 80  1
                         validateDisposal();
 81  1
                         _wrappedAlgorithm.addParsers(parsers);
 82  1
                 }
 83  
                 
 84  
                 /**
 85  
                  * description
 86  
                  * 
 87  
                  * @return
 88  
                   */
 89  
                 public function cancel(): void
 90  
                 {
 91  1
                         validateDisposal();
 92  1
                         _wrappedAlgorithm.cancel();
 93  1
                 }
 94  
                 
 95  
                 public function dispatchEvent(event: Event): Boolean
 96  
                 {
 97  1
                         validateDisposal();
 98  1
                         return _wrappedAlgorithm.dispatchEvent(event);
 99  
                 }
 100  
                 
 101  
                 public function dispose():void
 102  
                 {
 103  1
                         if (_disposed) return;
 104  
                         
 105  1
                         doDispose();
 106  
                         
 107  1
                         _wrappedAlgorithm.dispose();
 108  
                         
 109  1
                         _disposed = true;
 110  1
                         _wrappedAlgorithm = null;
 111  1
                 }
 112  
                 
 113  
                 public function hasEventListener(type : String) : Boolean
 114  
                 {
 115  0
                         validateDisposal();
 116  0
                         return _wrappedAlgorithm.hasEventListener(type);
 117  
                 }
 118  
                 
 119  
                 /**
 120  
                  * description
 121  
                  * 
 122  
                  * @return
 123  
                   */
 124  
                 public function load(): void
 125  
                 {
 126  1
                         validateDisposal();
 127  1
                         _wrappedAlgorithm.load();
 128  1
                 }
 129  
                 
 130  
                 public function removeEventListener(type : String, listener : Function, useCapture : Boolean = false) : void
 131  
                 {
 132  1
                         validateDisposal();
 133  1
                         _wrappedAlgorithm.removeEventListener(type, listener, useCapture);
 134  1
                 }
 135  
                 
 136  
                 /**
 137  
                  * description
 138  
                  */
 139  
                 public function stop(): void
 140  
                 {
 141  1
                         validateDisposal();
 142  1
                         _wrappedAlgorithm.stop();
 143  1
                 }
 144  
                 
 145  
                 public function willTrigger(type : String) : Boolean
 146  
                 {
 147  0
                         validateDisposal();
 148  0
                         return _wrappedAlgorithm.willTrigger(type);
 149  
                 }
 150  
                 
 151  
                 protected function doDispose():void
 152  
                 {
 153  
                         
 154  0
                 }
 155  
                 
 156  
                 /**
 157  
                  * @private
 158  
                  */
 159  
                 protected function validateDisposal():void
 160  
                 {
 161  1
                         if (_disposed) throw new ObjectDisposedError("This object was disposed, therefore no more operations can be performed.");
 162  1
                 }
 163  
                 
 164  
         }
 165  
 
 166  
 }