1 package org.fax4j.common;
2
3 import java.text.MessageFormat;
4 import java.util.Collections;
5 import java.util.HashMap;
6 import java.util.Map;
7
8
9
10
11
12
13
14
15 public final class ConfigurationHolderImpl implements ConfigurationHolder {
16
17 private final String PROPERTY_PART;
18
19 private final Map<String, String> CONFIGURATION;
20
21 private final Logger LOGGER;
22
23
24
25
26
27
28
29 public ConfigurationHolderImpl(Map<String, String> map) {
30 this(map, null);
31 }
32
33
34
35
36
37
38
39
40
41 public ConfigurationHolderImpl(Map<String, String> map, String propertyPart) {
42 super();
43
44
45 LoggerManager loggerManager = LoggerManager.getInstance();
46 this.LOGGER = loggerManager.getLogger();
47
48
49 Map<String, String> configuration = new HashMap<String, String>(map);
50 this.CONFIGURATION = Collections.unmodifiableMap(configuration);
51
52
53 this.PROPERTY_PART = propertyPart;
54 }
55
56
57
58
59
60
61
62
63
64
65
66
67 public String getPropertyPart() {
68 return this.PROPERTY_PART;
69 }
70
71
72
73
74
75
76 public Map<String, String> getConfiguration() {
77 return this.CONFIGURATION;
78 }
79
80
81
82
83
84
85
86
87
88
89 public String getConfigurationValue(String key) {
90
91 String propertyKey = key;
92 if (this.PROPERTY_PART != null) {
93 propertyKey = MessageFormat.format(key, new Object[] { this.PROPERTY_PART });
94 }
95
96
97 String value = this.CONFIGURATION.get(propertyKey);
98
99
100 if (value != null) {
101 value = value.trim();
102
103
104 if (value.length() == 0) {
105 value = null;
106 }
107 }
108
109 this.LOGGER.logDebug(new Object[] { "Extracted configuration for key: ", propertyKey, " value: ", value },
110 null);
111
112 return value;
113 }
114
115
116
117
118
119
120
121
122
123
124 public String getConfigurationValue(Enum<?> key) {
125
126 String keyStr = key.toString();
127
128
129 String value = this.getConfigurationValue(keyStr);
130
131 return value;
132 }
133 }