| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
|
| 17 | |
|
| 18 | |
|
| 19 | |
|
| 20 | |
|
| 21 | |
|
| 22 | |
|
| 23 | |
|
| 24 | |
|
| 25 | |
|
| 26 | |
|
| 27 | |
|
| 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 | |
|
| 45 | |
|
| 46 | |
|
| 47 | |
|
| 48 | |
public class FileLoaderState implements ILoaderState |
| 49 | |
{ |
| 50 | |
|
| 51 | |
|
| 52 | |
|
| 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 | |
|
| 77 | |
|
| 78 | |
|
| 79 | |
|
| 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 | |
|
| 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 | |
} |