01: /*
02: * Created on Oct 20, 2004
03: */
04: package net.sourceforge.orbroker;
05:
06: import java.util.HashMap;
07: import java.util.Map;
08: import java.util.Properties;
09:
10: /**
11: * The ConnectionContext class is a container for both text replacements and SQL parameters.
12: * @author Nils Kilden-Pedersen
13: */
14: final class ConnectionContext {
15: private Parameters parameters = new Parameters();
16:
17: private final TextReplacements textReplacements = new TextReplacements();
18:
19: void addContext(ConnectionContext context) {
20: this .textReplacements.setAll(context.textReplacements);
21: this .parameters.addParameters(context.parameters);
22: }
23:
24: Map copyParameters() {
25: return new HashMap(this .parameters.toMap());
26: }
27:
28: Map getParametersAsMap() {
29: return this .parameters.toMap();
30: }
31:
32: Object getParameterValue(String path) {
33: return this .parameters.getLeafValue(path);
34: }
35:
36: TextReplacements getTextReplacements() {
37: return this .textReplacements;
38: }
39:
40: /**
41: * Remove parameter.
42: * @param name parameter to remove
43: */
44: void removeParameter(String name) {
45: this .parameters.removeParameters(name);
46: }
47:
48: /**
49: * @param name
50: * @param value
51: */
52: void setParameter(String name, Object value) {
53: this .parameters.addParameter(name, value);
54: }
55:
56: void setParameters(Parameters newParms) {
57: this .parameters = newParms;
58: }
59:
60: /**
61: * @param name
62: * @param text
63: */
64: void setTextReplacement(String name, String text) {
65: this .textReplacements.setProperty(name, text);
66: }
67:
68: void setTextReplacements(Properties textReplacements) {
69: this .textReplacements.setAll(textReplacements);
70: }
71:
72: /**
73: * @param textReplacements
74: */
75: void setTextReplacements(TextReplacements textReplacements) {
76: this .textReplacements.setAll(textReplacements);
77: }
78:
79: /**
80: * @inheritDoc
81: * @see java.lang.Object#toString()
82: */
83: public String toString() {
84: return "Replacements: " + this .textReplacements.toString()
85: + "\nParameters: " + this.parameters.toString();
86: }
87: }
|