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