001: /**
002: * Speedo: an implementation of JDO compliant personality on top of JORM generic
003: * I/O sub-system.
004: * Copyright (C) 2001-2004 France Telecom R&D
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation; either
009: * version 2 of the License, or (at your option) any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: * You should have received a copy of the GNU Lesser General Public
017: * License along with this library; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
019: *
020: *
021: *
022: * Contact: speedo@objectweb.org
023: *
024: * Authors: S.Chassande-Barrioz.
025: *
026: */package org.objectweb.speedo.runtime.basic;
027:
028: import javax.naming.spi.InitialContextFactory;
029: import javax.naming.Context;
030: import javax.naming.NamingException;
031: import javax.naming.Name;
032: import javax.naming.NamingEnumeration;
033: import javax.naming.NameParser;
034: import java.util.Hashtable;
035: import java.util.Map;
036: import java.util.HashMap;
037:
038: /**
039: * @author S.Chassande-Barrioz
040: */
041: public class SpeedoInitialNamingFactory implements
042: InitialContextFactory {
043: static Context ctx = new SpeedoContext(new HashMap());
044:
045: public Context getInitialContext(Hashtable environment)
046: throws NamingException {
047: return ctx;
048: }
049: }
050:
051: class SpeedoContext implements Context {
052: Map ctx;
053:
054: public SpeedoContext(Map ctx) {
055: this .ctx = ctx;
056: }
057:
058: public Object lookup(Name name) throws NamingException {
059: Object o = ctx.get(name.get(0));
060: if (o instanceof Context) {
061: return ((Context) o).lookup(name.getSuffix(1));
062: } else {
063: return o;
064: }
065: }
066:
067: public Object lookup(String name) throws NamingException {
068: return ctx.get(name);
069: }
070:
071: public void bind(Name name, Object obj) throws NamingException {
072: if (name.size() > 1) {
073: ((Context) ctx.get(name.get(0))).rebind(name.getSuffix(1),
074: obj);
075: } else {
076: bind(name.get(0), obj);
077: }
078: }
079:
080: public void bind(String name, Object obj) throws NamingException {
081: if (ctx.containsKey(name)) {
082: throw new NamingException(name + " already bound");
083: }
084: ctx.put(name, obj);
085: }
086:
087: public void rebind(Name name, Object obj) throws NamingException {
088: if (name.size() > 1) {
089: ((Context) ctx.get(name.get(0))).rebind(name.getSuffix(1),
090: obj);
091: } else {
092: ctx.put(name.get(0), obj);
093: }
094: }
095:
096: public void rebind(String name, Object obj) throws NamingException {
097: ctx.put(name, obj);
098: }
099:
100: public void unbind(Name name) throws NamingException {
101: if (name.size() > 1) {
102: ((Context) ctx.get(name.get(0))).unbind(name.getSuffix(1));
103: } else {
104: unbind(name.get(0));
105: }
106: }
107:
108: public void unbind(String name) throws NamingException {
109: ctx.remove(name);
110: }
111:
112: public void rename(Name oldName, Name newName)
113: throws NamingException {
114: throw new UnsupportedOperationException();
115: }
116:
117: public void rename(String oldName, String newName)
118: throws NamingException {
119: throw new UnsupportedOperationException();
120: }
121:
122: public NamingEnumeration list(Name name) throws NamingException {
123: throw new UnsupportedOperationException();
124: }
125:
126: public NamingEnumeration list(String name) throws NamingException {
127: throw new UnsupportedOperationException();
128: }
129:
130: public NamingEnumeration listBindings(Name name)
131: throws NamingException {
132: throw new UnsupportedOperationException();
133: }
134:
135: public NamingEnumeration listBindings(String name)
136: throws NamingException {
137: throw new UnsupportedOperationException();
138: }
139:
140: public void destroySubcontext(Name name) throws NamingException {
141: throw new UnsupportedOperationException();
142: }
143:
144: public void destroySubcontext(String name) throws NamingException {
145: throw new UnsupportedOperationException();
146: }
147:
148: public Context createSubcontext(Name name) throws NamingException {
149: throw new UnsupportedOperationException();
150: }
151:
152: public Context createSubcontext(String name) throws NamingException {
153: throw new UnsupportedOperationException();
154: }
155:
156: public Object lookupLink(Name name) throws NamingException {
157: throw new UnsupportedOperationException();
158: }
159:
160: public Object lookupLink(String name) throws NamingException {
161: throw new UnsupportedOperationException();
162: }
163:
164: public NameParser getNameParser(Name name) throws NamingException {
165: throw new UnsupportedOperationException();
166: }
167:
168: public NameParser getNameParser(String name) throws NamingException {
169: throw new UnsupportedOperationException();
170: }
171:
172: public Name composeName(Name name, Name prefix)
173: throws NamingException {
174: throw new UnsupportedOperationException();
175: }
176:
177: public String composeName(String name, String prefix)
178: throws NamingException {
179: throw new UnsupportedOperationException();
180: }
181:
182: public Object addToEnvironment(String propName, Object propVal)
183: throws NamingException {
184: throw new UnsupportedOperationException();
185: }
186:
187: public Object removeFromEnvironment(String propName)
188: throws NamingException {
189: throw new UnsupportedOperationException();
190: }
191:
192: public Hashtable getEnvironment() throws NamingException {
193: throw new UnsupportedOperationException();
194: }
195:
196: public void close() throws NamingException {
197: }
198:
199: public String getNameInNamespace() throws NamingException {
200: throw new UnsupportedOperationException();
201: }
202: }
|