001: //========================================================================
002: //$Id: localContextRoot.java 1327 2006-11-27 18:40:14Z janb $
003: //Copyright 2000-2006 Mort Bay Consulting Pty. Ltd.
004: //------------------------------------------------------------------------
005: //Licensed under the Apache License, Version 2.0 (the "License");
006: //you may not use this file except in compliance with the License.
007: //You may obtain a copy of the License at
008: //http://www.apache.org/licenses/LICENSE-2.0
009: //Unless required by applicable law or agreed to in writing, software
010: //distributed under the License is distributed on an "AS IS" BASIS,
011: //WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
012: //See the License for the specific language governing permissions and
013: //limitations under the License.
014: //========================================================================
015:
016: package org.mortbay.naming.local;
017:
018: import java.util.Hashtable;
019: import java.util.Properties;
020:
021: import javax.naming.CompoundName;
022: import javax.naming.Context;
023: import javax.naming.Name;
024: import javax.naming.NameParser;
025: import javax.naming.NamingEnumeration;
026: import javax.naming.NamingException;
027:
028: import org.mortbay.naming.NamingContext;
029:
030: /**
031: *
032: * localContext
033: *
034: * @author janb
035: * @version $Revision: 1327 $ $Date: 2006-11-27 19:40:14 +0100 (Mon, 27 Nov 2006) $
036: *
037: */
038: public class localContextRoot implements Context {
039: private static final NamingContext _root;
040:
041: private final Hashtable _env;
042:
043: // make a root for the static namespace local:
044: static {
045: _root = new NamingContext();
046: _root.setNameParser(new LocalNameParser());
047: }
048:
049: static class LocalNameParser implements NameParser {
050: Properties syntax = new Properties();
051:
052: LocalNameParser() {
053: syntax.put("jndi.syntax.direction", "left_to_right");
054: syntax.put("jndi.syntax.separator", "/");
055: syntax.put("jndi.syntax.ignorecase", "false");
056: }
057:
058: public Name parse(String name) throws NamingException {
059: return new CompoundName(name, syntax);
060: }
061: }
062:
063: public localContextRoot(Hashtable env) {
064: _env = new Hashtable(env);
065: }
066:
067: /**
068: *
069: *
070: * @see javax.naming.Context#close()
071: */
072: public void close() throws NamingException {
073:
074: }
075:
076: /**
077: *
078: *
079: * @see javax.naming.Context#getNameInNamespace()
080: */
081: public String getNameInNamespace() throws NamingException {
082: return "";
083: }
084:
085: /**
086: *
087: *
088: * @see javax.naming.Context#destroySubcontext(java.lang.String)
089: */
090: public void destroySubcontext(String name) throws NamingException {
091: synchronized (_root) {
092: _root.destroySubcontext(getSuffix(name));
093: }
094: }
095:
096: /**
097: *
098: *
099: * @see javax.naming.Context#unbind(java.lang.String)
100: */
101: public void unbind(String name) throws NamingException {
102: synchronized (_root) {
103: _root.unbind(getSuffix(name));
104: }
105: }
106:
107: /**
108: *
109: *
110: * @see javax.naming.Context#getEnvironment()
111: */
112: public Hashtable getEnvironment() throws NamingException {
113: return _env;
114: }
115:
116: /**
117: *
118: *
119: * @see javax.naming.Context#destroySubcontext(javax.naming.Name)
120: */
121: public void destroySubcontext(Name name) throws NamingException {
122: synchronized (_root) {
123: _root.destroySubcontext(getSuffix(name));
124: }
125: }
126:
127: /**
128: *
129: *
130: * @see javax.naming.Context#unbind(javax.naming.Name)
131: */
132: public void unbind(Name name) throws NamingException {
133: synchronized (_root) {
134: _root.unbind(getSuffix(name));
135: }
136: }
137:
138: /**
139: *
140: *
141: * @see javax.naming.Context#lookup(java.lang.String)
142: */
143: public Object lookup(String name) throws NamingException {
144: synchronized (_root) {
145: return _root.lookup(getSuffix(name));
146: }
147: }
148:
149: /**
150: *
151: *
152: * @see javax.naming.Context#lookupLink(java.lang.String)
153: */
154: public Object lookupLink(String name) throws NamingException {
155: synchronized (_root) {
156: return _root.lookupLink(getSuffix(name));
157: }
158: }
159:
160: /**
161: *
162: *
163: * @see javax.naming.Context#removeFromEnvironment(java.lang.String)
164: */
165: public Object removeFromEnvironment(String propName)
166: throws NamingException {
167: return _env.remove(propName);
168: }
169:
170: /**
171: *
172: *
173: * @see javax.naming.Context#bind(java.lang.String, java.lang.Object)
174: */
175: public void bind(String name, Object obj) throws NamingException {
176: synchronized (_root) {
177: _root.bind(getSuffix(name), obj);
178: }
179: }
180:
181: /**
182: *
183: *
184: * @see javax.naming.Context#rebind(java.lang.String, java.lang.Object)
185: */
186: public void rebind(String name, Object obj) throws NamingException {
187: synchronized (_root) {
188: _root.rebind(getSuffix(name), obj);
189: }
190: }
191:
192: /**
193: *
194: *
195: * @see javax.naming.Context#lookup(javax.naming.Name)
196: */
197: public Object lookup(Name name) throws NamingException {
198: synchronized (_root) {
199: return _root.lookup(getSuffix(name));
200: }
201: }
202:
203: /**
204: *
205: *
206: * @see javax.naming.Context#lookupLink(javax.naming.Name)
207: */
208: public Object lookupLink(Name name) throws NamingException {
209: synchronized (_root) {
210: return _root.lookupLink(getSuffix(name));
211: }
212: }
213:
214: /**
215: *
216: *
217: * @see javax.naming.Context#bind(javax.naming.Name, java.lang.Object)
218: */
219: public void bind(Name name, Object obj) throws NamingException {
220: synchronized (_root) {
221: _root.bind(getSuffix(name), obj);
222: }
223: }
224:
225: /**
226: *
227: *
228: * @see javax.naming.Context#rebind(javax.naming.Name, java.lang.Object)
229: */
230: public void rebind(Name name, Object obj) throws NamingException {
231: synchronized (_root) {
232: _root.rebind(getSuffix(name), obj);
233: }
234: }
235:
236: /**
237: *
238: *
239: * @see javax.naming.Context#rename(java.lang.String, java.lang.String)
240: */
241: public void rename(String oldName, String newName)
242: throws NamingException {
243: synchronized (_root) {
244: _root.rename(getSuffix(oldName), getSuffix(newName));
245: }
246: }
247:
248: /**
249: *
250: *
251: * @see javax.naming.Context#createSubcontext(java.lang.String)
252: */
253: public Context createSubcontext(String name) throws NamingException {
254: synchronized (_root) {
255: return _root.createSubcontext(getSuffix(name));
256: }
257: }
258:
259: /**
260: *
261: *
262: * @see javax.naming.Context#createSubcontext(javax.naming.Name)
263: */
264: public Context createSubcontext(Name name) throws NamingException {
265: synchronized (_root) {
266: return _root.createSubcontext(getSuffix(name));
267: }
268: }
269:
270: /**
271: *
272: *
273: * @see javax.naming.Context#rename(javax.naming.Name, javax.naming.Name)
274: */
275: public void rename(Name oldName, Name newName)
276: throws NamingException {
277: synchronized (_root) {
278: _root.rename(getSuffix(oldName), getSuffix(newName));
279: }
280: }
281:
282: /**
283: *
284: *
285: * @see javax.naming.Context#getNameParser(java.lang.String)
286: */
287: public NameParser getNameParser(String name) throws NamingException {
288: return _root.getNameParser(name);
289: }
290:
291: /**
292: *
293: *
294: * @see javax.naming.Context#getNameParser(javax.naming.Name)
295: */
296: public NameParser getNameParser(Name name) throws NamingException {
297: return _root.getNameParser(name);
298: }
299:
300: /**
301: *
302: *
303: * @see javax.naming.Context#list(java.lang.String)
304: */
305: public NamingEnumeration list(String name) throws NamingException {
306: synchronized (_root) {
307: return _root.list(getSuffix(name));
308: }
309: }
310:
311: /**
312: *
313: *
314: * @see javax.naming.Context#listBindings(java.lang.String)
315: */
316: public NamingEnumeration listBindings(String name)
317: throws NamingException {
318: synchronized (_root) {
319: return _root.listBindings(getSuffix(name));
320: }
321: }
322:
323: /**
324: *
325: *
326: * @see javax.naming.Context#list(javax.naming.Name)
327: */
328: public NamingEnumeration list(Name name) throws NamingException {
329: synchronized (_root) {
330: return _root.list(getSuffix(name));
331: }
332: }
333:
334: /**
335: *
336: *
337: * @see javax.naming.Context#listBindings(javax.naming.Name)
338: */
339: public NamingEnumeration listBindings(Name name)
340: throws NamingException {
341: synchronized (_root) {
342: return _root.listBindings(getSuffix(name));
343: }
344: }
345:
346: /**
347: *
348: *
349: * @see javax.naming.Context#addToEnvironment(java.lang.String,
350: * java.lang.Object)
351: */
352: public Object addToEnvironment(String propName, Object propVal)
353: throws NamingException {
354: return _env.put(propName, propVal);
355: }
356:
357: /**
358: *
359: *
360: * @see javax.naming.Context#composeName(java.lang.String, java.lang.String)
361: */
362: public String composeName(String name, String prefix)
363: throws NamingException {
364: return _root.composeName(name, prefix);
365: }
366:
367: /**
368: *
369: *
370: * @see javax.naming.Context#composeName(javax.naming.Name,
371: * javax.naming.Name)
372: */
373: public Name composeName(Name name, Name prefix)
374: throws NamingException {
375: return _root.composeName(name, prefix);
376: }
377:
378: protected String getSuffix(String url) throws NamingException {
379: return url;
380: }
381:
382: protected Name getSuffix(Name name) throws NamingException {
383: return name;
384: }
385:
386: }
|