Coverage Report - org.vostokframework.domain.loading.states.fileloader.FileLoaderState
 
Classes in this File Line Coverage Branch Coverage Complexity
FileLoaderState
95%
43/45
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
 30  
 {
 31  
         import org.as3collections.IList;
 32  
         import org.as3coreaddendum.errors.ObjectDisposedError;
 33  
         import org.as3coreaddendum.errors.UnsupportedOperationError;
 34  
         import org.as3utils.ReflectionUtil;
 35  
         import org.vostokframework.VostokIdentification;
 36  
         import org.vostokframework.domain.loading.ILoader;
 37  
         import org.vostokframework.domain.loading.ILoaderState;
 38  
         import org.vostokframework.domain.loading.ILoaderStateTransition;
 39  
         import org.vostokframework.domain.loading.events.LoaderEvent;
 40  
 
 41  
         import flash.errors.IllegalOperationError;
 42  
 
 43  
         /**
 44  
          * description
 45  
          * 
 46  
          * @author Flávio Silva
 47  
          */
 48  
         public class FileLoaderState implements ILoaderState
 49  
         {
 50  
                 
 51  
                 /**
 52  
                  * @private
 53  
                  */
 54  
                 private var _algorithm:IFileLoadingAlgorithm;
 55  
                 private var _disposed:Boolean;
 56  
                 private var _loader:ILoaderStateTransition;
 57  
                 
 58  
                 protected function get algorithm():IFileLoadingAlgorithm { return _algorithm; }
 59  
                 
 60  
                 protected function get loader():ILoaderStateTransition { return _loader; }
 61  
                 
 62  
                 public function get isLoading():Boolean { return false; }
 63  
                 
 64  
                 public function get isQueued():Boolean { return false; }
 65  
                 
 66  
                 public function get isStopped():Boolean { return false; }
 67  
                 
 68  
                 public function get maxConcurrentConnections():int
 69  
                 {
 70  0
                         throw new UnsupportedOperationError("This is a Leaf implementation of the ILoaderState interface and does not support this operation. " + ReflectionUtil.getClassPath(this));
 71  
                 }
 72  
                 
 73  
                 public function get openedConnections():int { return 0; }
 74  
                 
 75  
                 /**
 76  
                  * description
 77  
                  * 
 78  
                  * @param name
 79  
                  * @param ordinal
 80  
                  */
 81  
                 public function FileLoaderState(algorithm:IFileLoadingAlgorithm)
 82  1
                 {
 83  1
                         if (ReflectionUtil.classPathEquals(this, FileLoaderState))  throw new IllegalOperationError(ReflectionUtil.getClassName(this) + " is an abstract class and shouldn't be directly instantiated.");
 84  1
                         if (!algorithm) throw new ArgumentError("Argument <algorithm> must not be null.");
 85  
                         
 86  1
                         _algorithm = algorithm;
 87  1
                 }
 88  
                 
 89  
                 public function addChild(child:ILoader): void
 90  
                 {
 91  1
                         throw new UnsupportedOperationError("This is a Leaf implementation of the ILoaderState interface and does not support this operation. " + ReflectionUtil.getClassPath(this));
 92  
                 }
 93  
                 
 94  
                 public function addChildren(children:IList): void
 95  
                 {
 96  1
                         throw new UnsupportedOperationError("This is a Leaf implementation of the ILoaderState interface and does not support this operation. " + ReflectionUtil.getClassPath(this));
 97  
                 }
 98  
                 
 99  
                 public function cancel():void
 100  
                 {
 101  1
                         validateDisposal();
 102  1
                         algorithm.cancel();
 103  
                         
 104  1
                         loader.setState(new CanceledFileLoader(loader, algorithm));
 105  1
                         loader.dispatchEvent(new LoaderEvent(LoaderEvent.CANCELED));
 106  1
                         dispose();
 107  1
                 }
 108  
                 
 109  
                 public function cancelChild(identification:VostokIdentification): void
 110  
                 {
 111  1
                         throw new UnsupportedOperationError("This is a Leaf implementation of the ILoaderState interface and does not support this operation. " + ReflectionUtil.getClassPath(this));
 112  
                 }
 113  
                 
 114  
                 public function containsChild(identification:VostokIdentification): Boolean
 115  
                 {
 116  1
                         return false;
 117  
                 }
 118  
                 
 119  
                 public function dispose():void
 120  
                 {
 121  1
                         if (_disposed) return;
 122  
                         
 123  1
                         doDispose();
 124  
                         
 125  1
                         _disposed = true;
 126  1
                         _algorithm = null;
 127  1
                         _loader = null;
 128  1
                 }
 129  
                 
 130  
                 public function getChild(identification:VostokIdentification): ILoader
 131  
                 {
 132  1
                         throw new UnsupportedOperationError("This is a Leaf implementation of the ILoaderState interface and does not support this operation. " + ReflectionUtil.getClassPath(this));
 133  
                 }
 134  
                 
 135  
                 public function getParent(identification:VostokIdentification): ILoader
 136  
                 {
 137  1
                         throw new UnsupportedOperationError("This is a Leaf implementation of the ILoaderState interface and does not support this operation. " + ReflectionUtil.getClassPath(this));
 138  
                 }
 139  
                 
 140  
                 public function load():void
 141  
                 {
 142  1
                         validateDisposal();
 143  
                         
 144  1
                         loader.setState(new LoadingFileLoader(loader, algorithm));
 145  1
                         loader.dispatchEvent(new LoaderEvent(LoaderEvent.CONNECTING));
 146  1
                         dispose();
 147  1
                 }
 148  
                 
 149  
                 public function removeChild(identification:VostokIdentification): void
 150  
                 {
 151  1
                         throw new UnsupportedOperationError("This is a Leaf implementation of the ILoaderState interface and does not support this operation. " + ReflectionUtil.getClassPath(this));
 152  
                 }
 153  
                 
 154  
                 public function resumeChild(identification:VostokIdentification): void
 155  
                 {
 156  1
                         throw new UnsupportedOperationError("This is a Leaf implementation of the ILoaderState interface and does not support this operation. " + ReflectionUtil.getClassPath(this));
 157  
                 }
 158  
                 
 159  
                 public function setLoader(loader:ILoaderStateTransition):void
 160  
                 {
 161  1
                         _loader = loader;
 162  1
                 }
 163  
                 
 164  
                 public function setMaxConcurrentConnections(value:int):void
 165  
                 {
 166  0
                         throw new UnsupportedOperationError("This is a Leaf implementation of the ILoaderState interface and does not support this operation. " + ReflectionUtil.getClassPath(this));
 167  
                 }
 168  
                 
 169  
                 public function stop():void
 170  
                 {
 171  1
                         validateDisposal();
 172  1
                         algorithm.stop();
 173  
                         
 174  1
                         loader.setState(new StoppedFileLoader(loader, algorithm));
 175  1
                         loader.dispatchEvent(new LoaderEvent(LoaderEvent.STOPPED));
 176  1
                         dispose();
 177  1
                 }
 178  
                 
 179  
                 public function stopChild(identification:VostokIdentification): void
 180  
                 {
 181  1
                         throw new UnsupportedOperationError("This is a Leaf implementation of the ILoaderState interface and does not support this operation. " + ReflectionUtil.getClassPath(this));
 182  
                 }
 183  
                 
 184  
                 protected function doDispose():void
 185  
                 {
 186  
                         
 187  1
                 }
 188  
                 
 189  
                 /**
 190  
                  * @private
 191  
                  */
 192  
                 protected function validateDisposal():void
 193  
                 {
 194  1
                         if (_disposed) throw new ObjectDisposedError("This object was disposed, therefore no more operations can be performed.");
 195  1
                 }
 196  
                 
 197  
         }
 198  
 
 199  
 }