01: package net.sourceforge.orbroker;
02:
03: import java.util.HashMap;
04: import java.util.Map;
05: import net.kildenpedersen.reflect.Reflector;
06:
07: /*
08: * Created on Apr 22, 2004
09: *
10: */
11:
12: /**
13: * Holding class for parameter values. Based on a Map.
14: * @author Nils Kilden-Pedersen
15: */
16: final class Parameters {
17:
18: private final Map map;
19:
20: Parameters() {
21: this .map = new HashMap();
22: }
23:
24: Parameters(Parameters source) {
25: this .map = new HashMap(source.map);
26: }
27:
28: void addParameter(String name, Object value) {
29: if (name == null) {
30: String msg = "No parameter name given";
31: throw new NullPointerException(msg);
32: }
33: this .map.put(name, value);
34: }
35:
36: void addParameters(Parameters newParameters) {
37: if (!newParameters.map.isEmpty()) {
38: this .map.putAll(newParameters.map);
39: }
40: }
41:
42: /**
43: * Return the leaf value, i.e. the last value in a property tree. Ex.:
44: * <code>root.propertyBranch.propertyLeaf</code> will return the value of
45: * propertyLeaf after traversing the tree.
46: *
47: * @param parameterTree
48: * @return leaf value
49: */
50: Object getLeafValue(String parameterTree) {
51: Object value = this .map.get(parameterTree);
52: if (value != null) {
53: return value;
54: }
55: return Reflector.getLeafValue(this .map, parameterTree);
56: }
57:
58: void removeParameters(String path) {
59: this .map.remove(path);
60: }
61:
62: /**
63: * Return values as {@link Map}.
64: * @return parameter values in map.
65: */
66: Map toMap() {
67: return this .map;
68: }
69:
70: /**
71: * @inheritDoc
72: * @see java.lang.Object#toString()
73: */
74: public String toString() {
75: return this.map.toString();
76: }
77:
78: }
|