1:
37:
38:
39: package ;
40:
41: import ;
42: import ;
43: import ;
44: import ;
45:
46: import ;
47: import ;
48: import ;
49: import ;
50: import ;
51:
52:
56: public class gnuContext
57: extends Context
58: {
59:
62: Context parent;
63:
64:
67: Map properties = new Hashtable();
68:
69:
72: String name;
73:
74:
80: public gnuContext(String a_name, Context a_parent)
81: {
82: name = a_name;
83: parent = a_parent;
84: }
85:
86:
87: public String context_name()
88: {
89: return name;
90: }
91:
92:
93: public Context create_child(String child)
94: {
95: return new gnuContext(child, this);
96: }
97:
98:
99: public void delete_values(String property)
100: {
101: boolean starts = false;
102: if (property.endsWith("*"))
103: {
104: starts = true;
105: property = property.substring(0, property.length() - 1);
106: }
107:
108: Set keys = properties.keySet();
109:
110: Iterator iter = keys.iterator();
111: while (iter.hasNext())
112: {
113: String key = (String) iter.next();
114: if ((starts && key.startsWith(property)) ||
115: (!starts && key.equals(property))
116: )
117: iter.remove();
118: }
119: }
120:
121:
122: public NVList get_values(String start_scope, int flags, String pattern)
123: {
124: if (start_scope != null)
125: {
126: Context c = this;
127: while (c != null && !c.context_name().equals(start_scope))
128: c = c.parent();
129: if (c == null)
130: return new gnuNVList();
131: }
132:
133: try
134: {
135: gnuNVList rt = new gnuNVList();
136:
137: boolean starts = false;
138: if (pattern.endsWith("*"))
139: {
140: starts = true;
141: pattern = pattern.substring(0, pattern.length() - 1);
142: }
143:
144: Set keys = properties.keySet();
145:
146: Iterator iter = keys.iterator();
147: while (iter.hasNext())
148: {
149: String key = (String) iter.next();
150: if ((starts && key.startsWith(pattern)) ||
151: (!starts && key.equals(pattern))
152: )
153: {
154: rt.add_value(key, (Any) properties.get(key), 0);
155: }
156: }
157:
158: if ((flags & CTX_RESTRICT_SCOPE.value) == 0 && parent != null)
159: {
160: NVList par = parent.get_values(start_scope, flags, pattern);
161: for (int i = 0; i < par.count(); i++)
162: {
163: rt.list.add(par.item(i));
164: }
165: }
166:
167: return rt;
168: }
169: catch (Bounds ex)
170: {
171: throw new Error("Report this bug.");
172: }
173: }
174:
175:
176: public Context parent()
177: {
178: return parent;
179: }
180:
181:
182: public void set_one_value(String name, Any value)
183: {
184: properties.put(name, value);
185: }
186:
187:
188: public void set_values(NVList values)
189: {
190: try
191: {
192: for (int i = 0; i < values.count(); i++)
193: {
194: properties.put(values.item(i).name(), values.item(i).value());
195: }
196: }
197: catch (Bounds ex)
198: {
199: throw new Error("Please report this bug.");
200: }
201: }
202: }