1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.configuration.internal; |
21 |
|
|
22 |
|
import java.util.ArrayList; |
23 |
|
import java.util.Iterator; |
24 |
|
import java.util.List; |
25 |
|
import java.util.Properties; |
26 |
|
|
27 |
|
import javax.inject.Inject; |
28 |
|
|
29 |
|
import org.apache.commons.configuration.Configuration; |
30 |
|
import org.xwiki.configuration.ConfigurationSource; |
31 |
|
import org.xwiki.properties.ConverterManager; |
32 |
|
|
33 |
|
|
34 |
|
@link |
35 |
|
|
36 |
|
|
37 |
|
|
38 |
|
@version |
39 |
|
@since |
40 |
|
|
|
|
| 96.2% |
Uncovered Elements: 2 (52) |
Complexity: 17 |
Complexity Density: 0.57 |
|
41 |
|
public class CommonsConfigurationSource implements ConfigurationSource |
42 |
|
{ |
43 |
|
private Configuration configuration; |
44 |
|
|
45 |
|
|
46 |
|
|
47 |
|
|
48 |
|
@Inject |
49 |
|
private ConverterManager converterManager; |
50 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
51 |
1688840 |
protected Configuration getConfiguration()... |
52 |
|
{ |
53 |
1688830 |
return this.configuration; |
54 |
|
} |
55 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
56 |
87 |
protected void setConfiguration(Configuration configuration)... |
57 |
|
{ |
58 |
87 |
this.configuration = configuration; |
59 |
|
} |
60 |
|
|
|
|
| 81.8% |
Uncovered Elements: 2 (11) |
Complexity: 3 |
Complexity Density: 0.43 |
|
61 |
1477009 |
@Override... |
62 |
|
@SuppressWarnings("unchecked") |
63 |
|
public <T> T getProperty(String key, T defaultValue) |
64 |
|
{ |
65 |
1477024 |
T result; |
66 |
1477175 |
if (containsKey(key)) { |
67 |
97 |
if (defaultValue != null) { |
68 |
97 |
return getProperty(key, (Class<T>) defaultValue.getClass()); |
69 |
|
} else { |
70 |
0 |
return getProperty(key); |
71 |
|
} |
72 |
|
} else { |
73 |
1477064 |
result = defaultValue; |
74 |
|
} |
75 |
|
|
76 |
1477061 |
return result; |
77 |
|
} |
78 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
79 |
221 |
@Override... |
80 |
|
@SuppressWarnings("unchecked") |
81 |
|
public <T> T getProperty(String key) |
82 |
|
{ |
83 |
221 |
return (T) getConfiguration().getProperty(key); |
84 |
|
} |
85 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (21) |
Complexity: 7 |
Complexity Density: 0.54 |
|
86 |
828 |
@Override... |
87 |
|
@SuppressWarnings("unchecked") |
88 |
|
public <T> T getProperty(String key, Class<T> valueClass) |
89 |
|
{ |
90 |
828 |
T result = null; |
91 |
|
|
92 |
828 |
try { |
93 |
828 |
if (String.class.getName().equals(valueClass.getName())) { |
94 |
626 |
result = (T) getConfiguration().getString(key); |
95 |
202 |
} else if (List.class.isAssignableFrom(valueClass)) { |
96 |
27 |
result = (T) getConfiguration().getList(key); |
97 |
175 |
} else if (Properties.class.isAssignableFrom(valueClass)) { |
98 |
40 |
result = (T) getConfiguration().getProperties(key); |
99 |
135 |
} else if (null != getProperty(key)) { |
100 |
77 |
result = (T) this.converterManager.convert(valueClass, getProperty(key)); |
101 |
|
} |
102 |
|
} catch (org.apache.commons.configuration.ConversionException e) { |
103 |
1 |
throw new org.xwiki.configuration.ConversionException("Key [" + key + "] is not of type [" |
104 |
|
+ valueClass.getName() + "]", e); |
105 |
|
} catch (org.xwiki.properties.converter.ConversionException e) { |
106 |
1 |
throw new org.xwiki.configuration.ConversionException("Key [" + key + "] is not of type [" |
107 |
|
+ valueClass.getName() + "]", e); |
108 |
|
} |
109 |
|
|
110 |
826 |
return result; |
111 |
|
} |
112 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 2 |
Complexity Density: 0.4 |
|
113 |
14 |
@Override... |
114 |
|
public List<String> getKeys() |
115 |
|
{ |
116 |
14 |
List<String> keysList = new ArrayList<String>(); |
117 |
14 |
Iterator<String> keys = getConfiguration().getKeys(); |
118 |
38 |
while (keys.hasNext()) { |
119 |
24 |
keysList.add(keys.next()); |
120 |
|
} |
121 |
|
|
122 |
14 |
return keysList; |
123 |
|
} |
124 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
125 |
1687911 |
@Override... |
126 |
|
public boolean containsKey(String key) |
127 |
|
{ |
128 |
1687923 |
return getConfiguration().containsKey(key); |
129 |
|
} |
130 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
131 |
4 |
@Override... |
132 |
|
public boolean isEmpty() |
133 |
|
{ |
134 |
4 |
return getConfiguration().isEmpty(); |
135 |
|
} |
136 |
|
} |