##### Coverage Report - com.ctrip.framework.apollo.spi.DefaultConfigFactory

Classes in this File | Line Coverage | Branch Coverage | Complexity
DefaultConfigFactory |
92% | 13/14
100% | 2/2
| 2.0;2
DefaultConfigFactory$1 |
100% | 1/1
N/A | N/A
| 2.0;2

1 |  |
     package com.ctrip.framework.apollo.spi;
2 |  |
3 |  |
     import com.ctrip.framework.apollo.Config;
4 |  |
     import com.ctrip.framework.apollo.ConfigFile;
5 |  |
     import com.ctrip.framework.apollo.core.enums.ConfigFileFormat;
6 |  |
     import com.ctrip.framework.apollo.internals.ConfigRepository;
7 |  |
     import com.ctrip.framework.apollo.internals.DefaultConfig;
8 |  |
     import com.ctrip.framework.apollo.internals.LocalFileConfigRepository;
9 |  |
     import com.ctrip.framework.apollo.internals.PropertiesConfigFile;
10 |  |
     import com.ctrip.framework.apollo.internals.RemoteConfigRepository;
11 |  |
     import com.ctrip.framework.apollo.internals.XmlConfigFile;
12 |  |
13 |  |
     import org.slf4j.Logger;
14 |  |
     import org.slf4j.LoggerFactory;
15 |  |
     import org.unidal.lookup.annotation.Named;
16 |  |
17 |  |
     /**
18 |  |
      * @author Jason Song(song_s@ctrip.com)
19 |  |
      */
20 |  |
     @Named(type = ConfigFactory.class)
21 | 10 |
     public class DefaultConfigFactory implements ConfigFactory {
22 | 1 |
       private static final Logger logger = LoggerFactory.getLogger(DefaultConfigFactory.class);
23 |  |
24 |  |
       @Override
25 |  |
       public Config create(String namespace) {
26 | 9 |
         DefaultConfig defaultConfig =
27 | 9 |
             new DefaultConfig(namespace, createLocalConfigRepository(namespace));
28 | 9 |
         return defaultConfig;
29 |  |
       }
30 |  |
31 |  |
       @Override
32 |  |
       public ConfigFile createConfigFile(String namespace, ConfigFileFormat configFileFormat) {
33 | 2 |
         ConfigRepository configRepository = createLocalConfigRepository(namespace);
34 | 2 |
         switch (configFileFormat) {
35 |  |
           case Properties:
36 | 1 |
             return new PropertiesConfigFile(namespace, configRepository);
37 |  |
           case XML:
38 | 11 |
             return new XmlConfigFile(namespace, configRepository);
39 |  |
         }
40 |  |
41 | 0 |
         return null;
42 |  |
       }
43 |  |
44 |  |
       LocalFileConfigRepository createLocalConfigRepository(String namespace) {
45 | 8 |
         LocalFileConfigRepository localFileConfigRepository =
46 |  |
             new LocalFileConfigRepository(namespace);
47 | 8 |
         localFileConfigRepository.setUpstreamRepository(createRemoteConfigRepository(namespace));
48 | 8 |
         return localFileConfigRepository;
49 |  |
       }
50 |  |
51 |  |
       RemoteConfigRepository createRemoteConfigRepository(String namespace) {
52 | 8 |
         return new RemoteConfigRepository(namespace);
53 |  |
       }
54 |  |
     }