##### Coverage Report - com.ctrip.apollo.spi.DefaultConfigFactoryManager

Classes in this File | Line Coverage | Branch Coverage | Complexity
DefaultConfigFactoryManager |
100% | 15/15
100% | 6/6
| 7.0;7

1 |  |
     package com.ctrip.apollo.spi;
2 |  |
3 |  |
     import com.google.common.collect.Maps;
4 |  |
5 |  |
     import org.unidal.lookup.ContainerHolder;
6 |  |
     import org.unidal.lookup.LookupException;
7 |  |
     import org.unidal.lookup.annotation.Inject;
8 |  |
     import org.unidal.lookup.annotation.Named;
9 |  |
10 |  |
     import java.util.Map;
11 |  |
12 |  |
     /**
13 |  |
      * @author Jason Song(song_s@ctrip.com)
14 |  |
      */
15 |  |
     @Named(type = ConfigFactoryManager.class, value = "default")
16 | 15 |
     public class DefaultConfigFactoryManager extends ContainerHolder implements ConfigFactoryManager {
17 |  |
       @Inject
18 |  |
       private ConfigRegistry m_registry;
19 |  |
20 | 15 |
       private Map<String, ConfigFactory> m_factories = Maps.newConcurrentMap();
21 |  |
22 |  |
       @Override
23 |  |
       public ConfigFactory getFactory(String namespace) {
24 |  |
         // step 1: check hacked factory
25 | 16 |
         ConfigFactory factory = m_registry.getFactory(namespace);
26 |  |
27 | 16 |
         if (factory != null) {
28 | 3 |
           return factory;
29 |  |
         }
30 |  |
31 |  |
         // step 2: check cache
32 | 13 |
         factory = m_factories.get(namespace);
33 |  |
34 | 13 |
         if (factory != null) {
35 | 1 |
           return factory;
36 |  |
         }
37 |  |
38 |  |
         // step 3: check declared config factory
39 |  |
         try {
40 | 12 |
           factory = lookup(ConfigFactory.class, namespace);
41 | 9 |
         } catch (LookupException ex) {
42 |  |
           // ignore it
43 | 3 |
         }
44 |  |
45 |  |
         // step 4: check default config factory
46 | 12 |
         if (factory == null) {
47 | 9 |
           factory = lookup(ConfigFactory.class, "default");
48 |  |
         }
49 |  |
50 | 12 |
         m_factories.put(namespace, factory);
51 |  |
52 |  |
         // factory should not be null
53 | 12 |
         return factory;
54 |  |
       }
55 |  |
     }