1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package org.xwiki.configuration.internal

File AbstractConfigurationSourceProvider.java

 

Coverage histogram

../../../../img/srcFileCovDistChart7.png
64% of files have more coverage

Code metrics

2
14
2
1
84
39
6
0.43
7
2
3

Classes

Class Line # Actions
AbstractConfigurationSourceProvider 35 14 0% 6 7
0.611111161.1%
 

Contributing tests

This file is covered by 180 tests. .

Source view

1    /*
2    * See the NOTICE file distributed with this work for additional
3    * information regarding copyright ownership.
4    *
5    * This is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU Lesser General Public License as
7    * published by the Free Software Foundation; either version 2.1 of
8    * the License, or (at your option) any later version.
9    *
10    * This software is distributed in the hope that it will be useful,
11    * but WITHOUT ANY WARRANTY; without even the implied warranty of
12    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13    * Lesser General Public License for more details.
14    *
15    * You should have received a copy of the GNU Lesser General Public
16    * License along with this software; if not, write to the Free
17    * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18    * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
19    */
20    package org.xwiki.configuration.internal;
21   
22    import javax.inject.Inject;
23    import javax.inject.Provider;
24   
25    import org.xwiki.component.manager.ComponentLookupException;
26    import org.xwiki.component.manager.ComponentManager;
27    import org.xwiki.configuration.ConfigurationSource;
28   
29    /**
30    * Common code for Configuration Source Provider implementations.
31    *
32    * @version $Id: 0f8ae46f56960c820eafec3b44dd9cba06ab95d9 $
33    * @since 4.1M2
34    */
 
35    public abstract class AbstractConfigurationSourceProvider implements Provider<ConfigurationSource>
36    {
37    /**
38    * Used to lookup existing {@link org.xwiki.configuration.ConfigurationSource} components.
39    */
40    @Inject
41    private ComponentManager componentManager;
42   
43    /**
44    * @param hint the hint of the Configuration Source to lookup
45    * @return the Configuration Source implementation with the passed hint or if not found a Memory Configuration
46    * Source and if not found a Void Configuration Source
47    */
 
48  135974 toggle protected ConfigurationSource get(String hint)
49    {
50  135960 ConfigurationSource configurationSource;
51   
52  135961 try {
53  135970 if (hint == null) {
54  135829 configurationSource = this.componentManager.getInstance(ConfigurationSource.class);
55    } else {
56  138 configurationSource = this.componentManager.getInstance(ConfigurationSource.class, hint);
57    }
58    } catch (ComponentLookupException e) {
59  30 try {
60  30 configurationSource = this.componentManager.getInstance(ConfigurationSource.class, "memory");
61    } catch (ComponentLookupException e1) {
62  0 configurationSource = getVoidConfigurationSource();
63    }
64    }
65   
66  136014 return configurationSource;
67    }
68   
69    /**
70    * @return an empty configuration source
71    */
 
72  0 toggle private ConfigurationSource getVoidConfigurationSource()
73    {
74  0 ConfigurationSource configurationSource;
75   
76  0 try {
77  0 configurationSource = this.componentManager.getInstance(ConfigurationSource.class, "void");
78    } catch (ComponentLookupException e) {
79  0 configurationSource = new VoidConfigurationSource();
80    }
81   
82  0 return configurationSource;
83    }
84    }