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

Classes in this File | Line Coverage | Branch Coverage | Complexity
DefaultConfigRegistry |
81% | 9/11
50% | 1/2
| 1.3333333333333333;1.333

1 |  |
     package com.ctrip.apollo.spi;
2 |  |
3 |  |
     import com.google.common.collect.Maps;
4 |  |
5 |  |
     import org.codehaus.plexus.logging.LogEnabled;
6 |  |
     import org.codehaus.plexus.logging.Logger;
7 |  |
     import org.unidal.lookup.annotation.Named;
8 |  |
9 |  |
     import java.util.Map;
10 |  |
11 |  |
     /**
12 |  |
      * @author Jason Song(song_s@ctrip.com)
13 |  |
      */
14 |  |
     @Named(type = ConfigRegistry.class, value = "default")
15 | 13 |
     public class DefaultConfigRegistry implements ConfigRegistry, LogEnabled {
16 | 13 |
       private Map<String, ConfigFactory> m_instances = Maps.newConcurrentMap();
17 |  |
18 |  |
       private Logger m_logger;
19 |  |
20 |  |
       @Override
21 |  |
       public void register(String namespace, ConfigFactory factory) {
22 | 3 |
         if (m_instances.containsKey(namespace)) {
23 | 0 |
           m_logger.warn(
24 | 0 |
               String.format("ConfigFactory(%s) is overridden by %s!", namespace, factory.getClass()));
25 |  |
         }
26 |  |
27 | 3 |
         m_instances.put(namespace, factory);
28 | 3 |
       }
29 |  |
30 |  |
       @Override
31 |  |
       public ConfigFactory getFactory(String namespace) {
32 | 13 |
         ConfigFactory config = m_instances.get(namespace);
33 |  |
34 | 13 |
         return config;
35 |  |
       }
36 |  |
37 |  |
       @Override
38 |  |
       public void enableLogging(Logger logger) {
39 | 13 |
         m_logger = logger;
40 | 13 |
       }
41 |  |
     }