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