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