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.application.monitoring.monitors |
30 | |
{ |
31 | |
import org.as3collections.IIterator; |
32 | |
import org.as3collections.IList; |
33 | |
import org.as3collections.lists.ArrayList; |
34 | |
import org.as3collections.utils.ListUtil; |
35 | |
import org.vostokframework.VostokIdentification; |
36 | |
import org.vostokframework.application.monitoring.ILoadingMonitor; |
37 | |
import org.vostokframework.application.monitoring.LoadingMonitoring; |
38 | |
import org.vostokframework.domain.loading.ILoader; |
39 | |
|
40 | |
import flash.events.Event; |
41 | |
|
42 | |
|
43 | |
|
44 | |
|
45 | |
|
46 | |
|
47 | |
public class LoadingMonitorWrapper implements ILoadingMonitor |
48 | |
{ |
49 | |
|
50 | |
private var _listeners:IList; |
51 | |
private var _monitor:ILoadingMonitor; |
52 | |
|
53 | |
public function get id():String { return "test"; } |
54 | |
|
55 | |
public function get loader():ILoader { return _monitor.loader; } |
56 | |
|
57 | |
public function get monitoring():LoadingMonitoring { return _monitor.monitoring; } |
58 | |
|
59 | |
|
60 | |
|
61 | |
|
62 | |
|
63 | |
|
64 | |
|
65 | |
public function LoadingMonitorWrapper(monitor:ILoadingMonitor = null) |
66 | 1 | { |
67 | 1 | _listeners = ListUtil.getUniqueTypedList(new ArrayList(), EventListener); |
68 | 1 | if (monitor) changeMonitor(monitor); |
69 | 1 | } |
70 | |
|
71 | |
public function addEventListener(type : String, listener : Function, useCapture : Boolean = false, priority : int = 0, useWeakReference : Boolean = false) : void |
72 | |
{ |
73 | 1 | var eventListener:EventListener = new EventListener(type, listener, useCapture, priority, useWeakReference); |
74 | 1 | _listeners.add(eventListener); |
75 | |
|
76 | 1 | _monitor.addEventListener(type, listener, useCapture, priority, useWeakReference); |
77 | 1 | } |
78 | |
|
79 | |
public function addChild(child:ILoadingMonitor):void |
80 | |
{ |
81 | 1 | _monitor.addChild(child); |
82 | 1 | } |
83 | |
|
84 | |
public function addChildren(children:IList):void |
85 | |
{ |
86 | 0 | _monitor.addChildren(children); |
87 | 0 | } |
88 | |
|
89 | |
public function changeMonitor(monitor:ILoadingMonitor):void |
90 | |
{ |
91 | 1 | if (!monitor) throw new ArgumentError("Argument <monitor> must not be null."); |
92 | |
|
93 | 1 | if (_monitor) removeListenersFromMonitor(_monitor); |
94 | |
|
95 | 1 | _monitor = monitor; |
96 | |
|
97 | 1 | addListenersOnMonitor(); |
98 | 1 | } |
99 | |
|
100 | |
public function containsChild(identification:VostokIdentification):Boolean |
101 | |
{ |
102 | 1 | return _monitor.containsChild(identification); |
103 | |
} |
104 | |
|
105 | |
public function dispatchEvent(event: Event) : Boolean |
106 | |
{ |
107 | 0 | return _monitor.dispatchEvent(event); |
108 | |
} |
109 | |
|
110 | |
public function dispose():void |
111 | |
{ |
112 | 0 | if (_monitor) |
113 | |
{ |
114 | 0 | removeListenersFromMonitor(_monitor); |
115 | 0 | _monitor.dispose(); |
116 | |
} |
117 | |
|
118 | 0 | _listeners.clear(); |
119 | 0 | _listeners = null; |
120 | 0 | } |
121 | |
|
122 | |
public function getChild(identification:VostokIdentification):ILoadingMonitor |
123 | |
{ |
124 | 1 | return _monitor.getChild(identification); |
125 | |
} |
126 | |
|
127 | |
public function hasEventListener(type : String) : Boolean |
128 | |
{ |
129 | 1 | return _monitor.hasEventListener(type); |
130 | |
} |
131 | |
|
132 | |
public function removeEventListener(type : String, listener : Function, useCapture : Boolean = false) : void |
133 | |
{ |
134 | 1 | _monitor.removeEventListener(type, listener, useCapture); |
135 | |
|
136 | 1 | var eventListener:EventListener = new EventListener(type, listener, useCapture); |
137 | 1 | _listeners.remove(eventListener); |
138 | 1 | } |
139 | |
|
140 | |
public function removeChild(identification:VostokIdentification):void |
141 | |
{ |
142 | 1 | _monitor.removeChild(identification); |
143 | 1 | } |
144 | |
|
145 | |
public function willTrigger(type : String) : Boolean |
146 | |
{ |
147 | 0 | return _monitor.willTrigger(type); |
148 | |
} |
149 | |
|
150 | |
private function addListenersOnMonitor():void |
151 | |
{ |
152 | 1 | if (_listeners.isEmpty()) return; |
153 | |
|
154 | 1 | var it:IIterator = _listeners.iterator(); |
155 | |
var eventListener:EventListener; |
156 | |
|
157 | 1 | while (it.hasNext()) |
158 | |
{ |
159 | 1 | eventListener = it.next(); |
160 | 1 | _monitor.addEventListener(eventListener.type, eventListener.listener, eventListener.useCapture, eventListener.priority, eventListener.useWeakReference); |
161 | |
} |
162 | 1 | } |
163 | |
|
164 | |
private function removeListenersFromMonitor(monitor:ILoadingMonitor):void |
165 | |
{ |
166 | 1 | if (_listeners.isEmpty()) return; |
167 | |
|
168 | 1 | var it:IIterator = _listeners.iterator(); |
169 | |
var eventListener:EventListener; |
170 | |
|
171 | 1 | while (it.hasNext()) |
172 | |
{ |
173 | 1 | eventListener = it.next(); |
174 | 1 | monitor.removeEventListener(eventListener.type, eventListener.listener, eventListener.useCapture); |
175 | |
} |
176 | 1 | } |
177 | |
} |
178 | |
|
179 | |
} |