Coverage Report - org.vostokframework.domain.loading.states.fileloader.algorithms.FileLoadingAlgorithmFactory
 
Classes in this File Line Coverage Branch Coverage Complexity
FileLoadingAlgorithmFactory
84%
21/25
N/A
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  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  
          * description
 45  
          * 
 46  
          * @author Flávio Silva
 47  
          */
 48  
         public class FileLoadingAlgorithmFactory implements IFileLoadingAlgorithmFactory
 49  
         {
 50  
                 /**
 51  
                  * @private
 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  
                  * description
 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  
                         //TODO:settings.extra.userDataContainer
 87  
                         //TODO:settings.extra.userTotalBytes
 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  
 }