1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
|
22 |
|
|
23 |
|
|
24 |
|
package net.smartlab.web; |
25 |
|
|
26 |
|
import java.lang.reflect.Constructor; |
27 |
|
import java.net.URL; |
28 |
|
import java.util.Iterator; |
29 |
|
import java.util.Map; |
30 |
|
import java.util.Properties; |
31 |
|
import java.util.TreeMap; |
32 |
|
|
33 |
|
import org.apache.commons.logging.Log; |
34 |
|
import org.apache.commons.logging.LogFactory; |
35 |
|
|
36 |
|
|
37 |
|
|
38 |
|
@author |
39 |
|
|
40 |
|
|
|
|
| 0% |
Uncovered Elements: 29 (29) |
Complexity: 7 |
Complexity Density: 0,37 |
|
41 |
|
public abstract class PropertiesEnumeration extends StringEnumeration { |
42 |
|
|
43 |
|
private static final long serialVersionUID = 228095287903246251L; |
44 |
|
|
45 |
|
private static final Class[] TYPES = new Class[] { |
46 |
|
String.class, String.class |
47 |
|
}; |
48 |
|
|
49 |
|
private static Map enumerations = new TreeMap(); |
50 |
|
|
51 |
|
private Map values; |
52 |
|
|
53 |
|
|
54 |
|
|
55 |
|
|
56 |
|
protected final static Log logger = LogFactory.getLog(PropertiesEnumeration.class); |
57 |
|
|
58 |
|
|
59 |
|
|
60 |
|
|
61 |
|
|
|
|
| 0% |
Uncovered Elements: 26 (26) |
Complexity: 6 |
Complexity Density: 0,33 |
|
62 |
0
|
public PropertiesEnumeration() {... |
63 |
0
|
if (logger.isDebugEnabled()) { |
64 |
0
|
logger.debug("PropertiesEnumeration() - start"); |
65 |
|
} |
66 |
0
|
synchronized (this.getClass()) { |
67 |
0
|
values = (Map)enumerations.get(this.getClass()); |
68 |
0
|
if (values == null) { |
69 |
0
|
try { |
70 |
0
|
String classname = this.getClass().getName(); |
71 |
0
|
URL url = this.getClass().getResource(classname.substring(classname.lastIndexOf('.') + 1) + ".properties"); |
72 |
0
|
Properties properties = new Properties(); |
73 |
0
|
properties.load(url.openStream()); |
74 |
0
|
Iterator entries = properties.entrySet().iterator(); |
75 |
0
|
Constructor instantiator = this.getClass().getConstructor(TYPES); |
76 |
0
|
values = new TreeMap(); |
77 |
0
|
while (entries.hasNext()) { |
78 |
0
|
Map.Entry entry = (Map.Entry)entries.next(); |
79 |
0
|
if (logger.isTraceEnabled()) { |
80 |
0
|
logger.trace(" adding (" + entry.getKey() + ", " + entry.getValue() + ")"); |
81 |
|
} |
82 |
0
|
values.put(entry.getKey(), instantiator.newInstance(new Object[] { |
83 |
|
entry.getKey(), entry.getValue() |
84 |
|
})); |
85 |
|
} |
86 |
|
} catch (Exception e) { |
87 |
|
logger.error("PropertiesEnumeration() - failed", e); |
88 |
|
} |
89 |
|
} |
90 |
|
} |
91 |
|
} |
92 |
|
|
93 |
|
|
94 |
|
@see |
95 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
96 |
0
|
public StringEnumeration decode(String code) {... |
97 |
0
|
return (StringEnumeration)values.get(code); |
98 |
|
} |
99 |
|
} |