01: /*
02: * Created on Dec 1, 2004
03: */
04: package net.sourceforge.orbroker;
05:
06: import java.util.HashMap;
07: import java.util.Iterator;
08: import java.util.Map;
09: import java.util.Properties;
10:
11: /**
12: * @author Nils Kilden-Pedersen
13: */
14: final class TextReplacements {
15:
16: private static void checkValue(String value) {
17: if (value.indexOf('?') > -1) {
18: throw new ConfigurationException(
19: "Invalid text replacement. Cannot contain '?'.");
20: }
21: }
22:
23: private final HashMap map = new HashMap(5);
24:
25: private void setAll(Map stringMap) {
26: if (stringMap.isEmpty()) {
27: return;
28: }
29: Iterator iter = stringMap.entrySet().iterator();
30: while (iter.hasNext()) {
31: Map.Entry entry = (Map.Entry) iter.next();
32: String key = (String) entry.getKey();
33: String value = (String) entry.getValue();
34: setProperty(key, value);
35: }
36: }
37:
38: String getProperty(String key) {
39: return (String) this .map.get(key);
40: }
41:
42: void setAll(Properties props) {
43: setAll((Map) props);
44: }
45:
46: void setAll(TextReplacements props) {
47: setAll(props.map);
48: }
49:
50: void setProperty(String key, String value) {
51: checkValue(value);
52: this .map.put(key, value);
53: }
54:
55: /**
56: * @inheritDoc
57: * @see java.lang.Object#toString()
58: */
59: public String toString() {
60: return this.map.toString();
61: }
62: }
|