KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > speedo > runtime > basic > SpeedoInitialNamingFactory


1 /**
2  * Speedo: an implementation of JDO compliant personality on top of JORM generic
3  * I/O sub-system.
4  * Copyright (C) 2001-2004 France Telecom R&D
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19  *
20  *
21  *
22  * Contact: speedo@objectweb.org
23  *
24  * Authors: S.Chassande-Barrioz.
25  *
26  */

27 package org.objectweb.speedo.runtime.basic;
28
29 import javax.naming.spi.InitialContextFactory JavaDoc;
30 import javax.naming.Context JavaDoc;
31 import javax.naming.NamingException JavaDoc;
32 import javax.naming.Name JavaDoc;
33 import javax.naming.NamingEnumeration JavaDoc;
34 import javax.naming.NameParser JavaDoc;
35 import java.util.Hashtable JavaDoc;
36 import java.util.Map JavaDoc;
37 import java.util.HashMap JavaDoc;
38
39 /**
40  * @author S.Chassande-Barrioz
41  */

42 public class SpeedoInitialNamingFactory implements InitialContextFactory JavaDoc {
43     static Context JavaDoc ctx = new SpeedoContext(new HashMap JavaDoc());
44
45     public Context JavaDoc getInitialContext(Hashtable JavaDoc environment)
46         throws NamingException JavaDoc {
47         return ctx;
48     }
49 }
50 class SpeedoContext implements Context JavaDoc {
51     Map JavaDoc ctx;
52
53     public SpeedoContext(Map JavaDoc ctx) {
54         this.ctx = ctx;
55     }
56
57     public Object JavaDoc lookup(Name JavaDoc name) throws NamingException JavaDoc {
58         Object JavaDoc o = ctx.get(name.get(0));
59         if (o instanceof Context JavaDoc) {
60             return ((Context JavaDoc) o).lookup(name.getSuffix(1));
61         } else {
62             return o;
63         }
64     }
65
66     public Object JavaDoc lookup(String JavaDoc name) throws NamingException JavaDoc {
67         return ctx.get(name);
68     }
69
70     public void bind(Name JavaDoc name, Object JavaDoc obj) throws NamingException JavaDoc {
71         if (name.size() > 1) {
72             ((Context JavaDoc)ctx.get(name.get(0))).rebind(name.getSuffix(1), obj);
73         } else {
74             bind(name.get(0), obj);
75         }
76     }
77
78     public void bind(String JavaDoc name, Object JavaDoc obj) throws NamingException JavaDoc {
79         if (ctx.containsKey(name)) {
80             throw new NamingException JavaDoc(name + " already bound");
81         }
82         ctx.put(name, obj);
83     }
84
85     public void rebind(Name JavaDoc name, Object JavaDoc obj) throws NamingException JavaDoc {
86         if (name.size() > 1) {
87             ((Context JavaDoc)ctx.get(name.get(0))).rebind(name.getSuffix(1), obj);
88         } else {
89             ctx.put(name.get(0), obj);
90         }
91     }
92
93     public void rebind(String JavaDoc name, Object JavaDoc obj) throws NamingException JavaDoc {
94         ctx.put(name, obj);
95     }
96
97     public void unbind(Name JavaDoc name) throws NamingException JavaDoc {
98         if (name.size() > 1) {
99             ((Context JavaDoc)ctx.get(name.get(0))).unbind(name.getSuffix(1));
100         } else {
101             unbind(name.get(0));
102         }
103     }
104
105     public void unbind(String JavaDoc name) throws NamingException JavaDoc {
106         ctx.remove(name);
107     }
108
109     public void rename(Name JavaDoc oldName, Name JavaDoc newName) throws NamingException JavaDoc {
110         throw new UnsupportedOperationException JavaDoc();
111     }
112
113     public void rename(String JavaDoc oldName, String JavaDoc newName) throws NamingException JavaDoc {
114         throw new UnsupportedOperationException JavaDoc();
115     }
116
117     public NamingEnumeration JavaDoc list(Name JavaDoc name) throws NamingException JavaDoc {
118         throw new UnsupportedOperationException JavaDoc();
119     }
120
121     public NamingEnumeration JavaDoc list(String JavaDoc name) throws NamingException JavaDoc {
122         throw new UnsupportedOperationException JavaDoc();
123     }
124
125     public NamingEnumeration JavaDoc listBindings(Name JavaDoc name) throws NamingException JavaDoc {
126         throw new UnsupportedOperationException JavaDoc();
127     }
128
129     public NamingEnumeration JavaDoc listBindings(String JavaDoc name) throws NamingException JavaDoc {
130         throw new UnsupportedOperationException JavaDoc();
131     }
132
133     public void destroySubcontext(Name JavaDoc name) throws NamingException JavaDoc {
134         throw new UnsupportedOperationException JavaDoc();
135     }
136
137     public void destroySubcontext(String JavaDoc name) throws NamingException JavaDoc {
138         throw new UnsupportedOperationException JavaDoc();
139     }
140
141     public Context JavaDoc createSubcontext(Name JavaDoc name) throws NamingException JavaDoc {
142         throw new UnsupportedOperationException JavaDoc();
143     }
144
145     public Context JavaDoc createSubcontext(String JavaDoc name) throws NamingException JavaDoc {
146         throw new UnsupportedOperationException JavaDoc();
147     }
148
149     public Object JavaDoc lookupLink(Name JavaDoc name) throws NamingException JavaDoc {
150         throw new UnsupportedOperationException JavaDoc();
151     }
152
153     public Object JavaDoc lookupLink(String JavaDoc name) throws NamingException JavaDoc {
154         throw new UnsupportedOperationException JavaDoc();
155     }
156
157     public NameParser JavaDoc getNameParser(Name JavaDoc name) throws NamingException JavaDoc {
158         throw new UnsupportedOperationException JavaDoc();
159     }
160
161     public NameParser JavaDoc getNameParser(String JavaDoc name) throws NamingException JavaDoc {
162         throw new UnsupportedOperationException JavaDoc();
163     }
164
165     public Name JavaDoc composeName(Name JavaDoc name, Name JavaDoc prefix) throws NamingException JavaDoc {
166         throw new UnsupportedOperationException JavaDoc();
167     }
168
169     public String JavaDoc composeName(String JavaDoc name, String JavaDoc prefix)
170         throws NamingException JavaDoc {
171         throw new UnsupportedOperationException JavaDoc();
172     }
173
174     public Object JavaDoc addToEnvironment(String JavaDoc propName, Object JavaDoc propVal)
175         throws NamingException JavaDoc {
176         throw new UnsupportedOperationException JavaDoc();
177     }
178
179     public Object JavaDoc removeFromEnvironment(String JavaDoc propName)
180         throws NamingException JavaDoc {
181         throw new UnsupportedOperationException JavaDoc();
182     }
183
184     public Hashtable JavaDoc getEnvironment() throws NamingException JavaDoc {
185         throw new UnsupportedOperationException JavaDoc();
186     }
187
188     public void close() throws NamingException JavaDoc {
189     }
190
191     public String JavaDoc getNameInNamespace() throws NamingException JavaDoc {
192         throw new UnsupportedOperationException JavaDoc();
193     }
194 }
195
196
Popular Tags