1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.mortbay.naming.local;
17
18 import java.util.Hashtable;
19 import java.util.Properties;
20
21 import javax.naming.CompoundName;
22 import javax.naming.Context;
23 import javax.naming.Name;
24 import javax.naming.NameParser;
25 import javax.naming.NamingEnumeration;
26 import javax.naming.NamingException;
27
28 import org.mortbay.naming.NamingContext;
29
30
31
32
33
34
35
36
37
38 public class localContextRoot implements Context
39 {
40 private static final NamingContext _root;
41
42 private final Hashtable _env;
43
44
45 static
46 {
47 _root = new NamingContext();
48 _root.setNameParser(new LocalNameParser());
49 }
50
51 static class LocalNameParser implements NameParser
52 {
53 Properties syntax = new Properties();
54
55 LocalNameParser()
56 {
57 syntax.put("jndi.syntax.direction", "left_to_right");
58 syntax.put("jndi.syntax.separator", "/");
59 syntax.put("jndi.syntax.ignorecase", "false");
60 }
61
62 public Name parse(String name) throws NamingException
63 {
64 return new CompoundName(name, syntax);
65 }
66 }
67
68 public localContextRoot(Hashtable env)
69 {
70 _env = new Hashtable(env);
71 }
72
73
74
75
76
77
78 public void close() throws NamingException
79 {
80
81 }
82
83
84
85
86
87
88 public String getNameInNamespace() throws NamingException
89 {
90 return "";
91 }
92
93
94
95
96
97
98 public void destroySubcontext(String name) throws NamingException
99 {
100 synchronized (_root)
101 {
102 _root.destroySubcontext(getSuffix(name));
103 }
104 }
105
106
107
108
109
110
111 public void unbind(String name) throws NamingException
112 {
113 synchronized (_root)
114 {
115 _root.unbind(getSuffix(name));
116 }
117 }
118
119
120
121
122
123
124 public Hashtable getEnvironment() throws NamingException
125 {
126 return _env;
127 }
128
129
130
131
132
133
134 public void destroySubcontext(Name name) throws NamingException
135 {
136 synchronized (_root)
137 {
138 _root.destroySubcontext(getSuffix(name));
139 }
140 }
141
142
143
144
145
146
147 public void unbind(Name name) throws NamingException
148 {
149 synchronized (_root)
150 {
151 _root.unbind(getSuffix(name));
152 }
153 }
154
155
156
157
158
159
160 public Object lookup(String name) throws NamingException
161 {
162 synchronized (_root)
163 {
164 return _root.lookup(getSuffix(name));
165 }
166 }
167
168
169
170
171
172
173 public Object lookupLink(String name) throws NamingException
174 {
175 synchronized (_root)
176 {
177 return _root.lookupLink(getSuffix(name));
178 }
179 }
180
181
182
183
184
185
186 public Object removeFromEnvironment(String propName) throws NamingException
187 {
188 return _env.remove(propName);
189 }
190
191
192
193
194
195
196 public void bind(String name, Object obj) throws NamingException
197 {
198 synchronized (_root)
199 {
200 _root.bind(getSuffix(name), obj);
201 }
202 }
203
204
205
206
207
208
209 public void rebind(String name, Object obj) throws NamingException
210 {
211 synchronized (_root)
212 {
213 _root.rebind(getSuffix(name), obj);
214 }
215 }
216
217
218
219
220
221
222 public Object lookup(Name name) throws NamingException
223 {
224 synchronized (_root)
225 {
226 return _root.lookup(getSuffix(name));
227 }
228 }
229
230
231
232
233
234
235 public Object lookupLink(Name name) throws NamingException
236 {
237 synchronized (_root)
238 {
239 return _root.lookupLink(getSuffix(name));
240 }
241 }
242
243
244
245
246
247
248 public void bind(Name name, Object obj) throws NamingException
249 {
250 synchronized (_root)
251 {
252 _root.bind(getSuffix(name), obj);
253 }
254 }
255
256
257
258
259
260
261 public void rebind(Name name, Object obj) throws NamingException
262 {
263 synchronized (_root)
264 {
265 _root.rebind(getSuffix(name), obj);
266 }
267 }
268
269
270
271
272
273
274 public void rename(String oldName, String newName) throws NamingException
275 {
276 synchronized (_root)
277 {
278 _root.rename(getSuffix(oldName), getSuffix(newName));
279 }
280 }
281
282
283
284
285
286
287 public Context createSubcontext(String name) throws NamingException
288 {
289 synchronized (_root)
290 {
291 return _root.createSubcontext(getSuffix(name));
292 }
293 }
294
295
296
297
298
299
300 public Context createSubcontext(Name name) throws NamingException
301 {
302 synchronized (_root)
303 {
304 return _root.createSubcontext(getSuffix(name));
305 }
306 }
307
308
309
310
311
312
313 public void rename(Name oldName, Name newName) throws NamingException
314 {
315 synchronized (_root)
316 {
317 _root.rename(getSuffix(oldName), getSuffix(newName));
318 }
319 }
320
321
322
323
324
325
326 public NameParser getNameParser(String name) throws NamingException
327 {
328 return _root.getNameParser(name);
329 }
330
331
332
333
334
335
336 public NameParser getNameParser(Name name) throws NamingException
337 {
338 return _root.getNameParser(name);
339 }
340
341
342
343
344
345
346 public NamingEnumeration list(String name) throws NamingException
347 {
348 synchronized (_root)
349 {
350 return _root.list(getSuffix(name));
351 }
352 }
353
354
355
356
357
358
359 public NamingEnumeration listBindings(String name) throws NamingException
360 {
361 synchronized (_root)
362 {
363 return _root.listBindings(getSuffix(name));
364 }
365 }
366
367
368
369
370
371
372 public NamingEnumeration list(Name name) throws NamingException
373 {
374 synchronized (_root)
375 {
376 return _root.list(getSuffix(name));
377 }
378 }
379
380
381
382
383
384
385 public NamingEnumeration listBindings(Name name) throws NamingException
386 {
387 synchronized (_root)
388 {
389 return _root.listBindings(getSuffix(name));
390 }
391 }
392
393
394
395
396
397
398
399 public Object addToEnvironment(String propName, Object propVal)
400 throws NamingException
401 {
402 return _env.put(propName, propVal);
403 }
404
405
406
407
408
409
410 public String composeName(String name, String prefix)
411 throws NamingException
412 {
413 return _root.composeName(name, prefix);
414 }
415
416
417
418
419
420
421
422 public Name composeName(Name name, Name prefix) throws NamingException
423 {
424 return _root.composeName(name, prefix);
425 }
426
427 protected String getSuffix(String url) throws NamingException
428 {
429 return url;
430 }
431
432 protected Name getSuffix(Name name) throws NamingException
433 {
434 return name;
435 }
436
437 }