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.vostokframework.domain.assets.AssetType; |
33 | |
import org.vostokframework.domain.loading.DataParserRepository; |
34 | |
import org.vostokframework.domain.loading.settings.LoadingSettings; |
35 | |
import org.vostokframework.domain.loading.states.fileloader.IDataLoader; |
36 | |
import org.vostokframework.domain.loading.states.fileloader.IDataLoaderFactory; |
37 | |
import org.vostokframework.domain.loading.states.fileloader.IFileLoadingAlgorithm; |
38 | |
import org.vostokframework.domain.loading.states.fileloader.IFileLoadingAlgorithmFactory; |
39 | |
import org.vostokframework.domain.loading.states.fileloader.adapters.DataLoaderFactory; |
40 | |
import org.vostokframework.domain.loading.states.fileloader.dataparsers.CSSDataParser; |
41 | |
import org.vostokframework.domain.loading.states.fileloader.dataparsers.XMLDataParser; |
42 | |
|
43 | |
|
44 | |
|
45 | |
|
46 | |
|
47 | |
|
48 | |
public class FileLoadingAlgorithmFactory implements IFileLoadingAlgorithmFactory |
49 | |
{ |
50 | |
|
51 | |
|
52 | |
|
53 | |
private var _dataLoaderFactory:IDataLoaderFactory; |
54 | |
private var _dataParserRepository:DataParserRepository; |
55 | |
|
56 | |
public function get dataLoaderFactory(): IDataLoaderFactory { return _dataLoaderFactory; } |
57 | |
|
58 | |
public function get dataParserRepository(): DataParserRepository { return _dataParserRepository; } |
59 | |
|
60 | |
|
61 | |
|
62 | |
|
63 | |
|
64 | |
public function FileLoadingAlgorithmFactory() |
65 | 1 | { |
66 | 1 | _dataLoaderFactory = new DataLoaderFactory(); |
67 | |
|
68 | 1 | initDataParserRepository(); |
69 | 1 | } |
70 | |
|
71 | |
public function create(type:AssetType, url:String, settings:LoadingSettings):IFileLoadingAlgorithm |
72 | |
{ |
73 | 1 | var dataLoader:IDataLoader = _dataLoaderFactory.create(type, url, settings); |
74 | |
|
75 | 1 | var algorithm:IFileLoadingAlgorithm = new FileLoadingAlgorithm(dataLoader); |
76 | 1 | algorithm = new LatencyTimeoutFileLoadingAlgorithm(algorithm, settings.policy.latencyTimeout); |
77 | 1 | algorithm = new DelayableFileLoadingAlgorithm(algorithm); |
78 | 1 | algorithm = new MaxAttemptsFileLoadingAlgorithm(algorithm, settings.policy.maxAttempts); |
79 | |
|
80 | 1 | if (_dataParserRepository) |
81 | |
{ |
82 | 1 | var parsers:IList = _dataParserRepository.find(type); |
83 | 1 | algorithm.addParsers(parsers); |
84 | |
} |
85 | |
|
86 | |
|
87 | |
|
88 | |
|
89 | 1 | return algorithm; |
90 | |
} |
91 | |
|
92 | |
public function setDataLoaderFactory(factory:IDataLoaderFactory): void |
93 | |
{ |
94 | 1 | if (!factory) throw new ArgumentError("Argument <factory> must not be null."); |
95 | 1 | _dataLoaderFactory = factory; |
96 | 1 | } |
97 | |
|
98 | |
public function setDataParserRepository(repository:DataParserRepository): void |
99 | |
{ |
100 | 0 | if (!repository) throw new ArgumentError("Argument <repository> must not be null."); |
101 | |
|
102 | 0 | if (_dataParserRepository) _dataParserRepository.clear(); |
103 | 0 | _dataParserRepository = repository; |
104 | 0 | } |
105 | |
|
106 | |
protected function initDataParserRepository():void |
107 | |
{ |
108 | 1 | _dataParserRepository = new DataParserRepository(); |
109 | |
|
110 | 1 | _dataParserRepository.add(AssetType.CSS, new CSSDataParser()); |
111 | 1 | _dataParserRepository.add(AssetType.XML, new XMLDataParser()); |
112 | 1 | } |
113 | |
|
114 | |
} |
115 | |
|
116 | |
} |