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