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