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.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 | |
|
41 | |
|
42 | |
|
43 | |
|
44 | |
public class FileLoadingAlgorithmBehavior implements IFileLoadingAlgorithm |
45 | |
{ |
46 | |
|
47 | |
|
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 | |
|
59 | |
|
60 | |
|
61 | |
|
62 | |
|
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 | |
|
86 | |
|
87 | |
|
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 | |
|
121 | |
|
122 | |
|
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 | |
|
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 | |
|
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 | |
} |