KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > speedo > runtime > jca > SimpleNamingManager


1 /**
2  * Copyright (C) 2001-2004 France Telecom R&D
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  */

18 package org.objectweb.speedo.runtime.jca;
19
20 import javax.naming.spi.InitialContextFactory JavaDoc;
21 import javax.naming.Context JavaDoc;
22 import javax.naming.NamingException JavaDoc;
23 import javax.naming.Name JavaDoc;
24 import javax.naming.NamingEnumeration JavaDoc;
25 import javax.naming.NameParser JavaDoc;
26 import java.util.Hashtable JavaDoc;
27
28 /**
29  *
30  * @author S.Chassande-Barrioz
31  */

32 public class SimpleNamingManager implements InitialContextFactory JavaDoc {
33
34     private static SimpleContext ictx;
35
36     public SimpleNamingManager() {
37     }
38
39     public Context JavaDoc getInitialContext(Hashtable JavaDoc environment)
40             throws NamingException JavaDoc {
41         if (ictx == null) {
42             ictx = new SimpleContext(environment);
43         } else {
44             ictx.context.putAll(environment);
45         }
46         return ictx;
47     }
48
49     class SimpleContext implements Context JavaDoc {
50
51         public Hashtable JavaDoc context;
52
53         public SimpleContext(Hashtable JavaDoc context) {
54             this.context = context;
55         }
56
57         private String JavaDoc name2String(Name JavaDoc n) {
58             StringBuffer JavaDoc sb = new StringBuffer JavaDoc("");
59             String JavaDoc sep = "";
60             for(int i=0; i<n.size(); i++) {
61                 sb.append(sep);
62                 sep = ".";
63                 sb.append(n.get(i));
64             }
65             return sb.toString();
66         }
67
68         // IMPLEMENTATION OF THE Context INTERFACE //
69
//-----------------------------------------//
70

71         public Object JavaDoc lookup(Name JavaDoc name) throws NamingException JavaDoc {
72             return context.get(name2String(name));
73         }
74
75         public Object JavaDoc lookup(String JavaDoc name) throws NamingException JavaDoc {
76             return context.get(name);
77         }
78
79         public void bind(Name JavaDoc name, Object JavaDoc obj) throws NamingException JavaDoc {
80             String JavaDoc n = name2String(name);
81             if (context.containsKey(n)) {
82                 throw new NamingException JavaDoc(n + " already bound: " + context.get(n));
83             } else {
84                 context.put(n, obj);
85             }
86         }
87
88         public void bind(String JavaDoc n, Object JavaDoc obj) throws NamingException JavaDoc {
89             if (context.containsKey(n)) {
90                 throw new NamingException JavaDoc(n + " already bound: " + context.get(n));
91             } else {
92                 context.put(n, obj);
93             }
94         }
95
96         public void rebind(Name JavaDoc name, Object JavaDoc obj) throws NamingException JavaDoc {
97             context.put(name2String(name), obj);
98         }
99
100         public void rebind(String JavaDoc n, Object JavaDoc obj) throws NamingException JavaDoc {
101             context.put(n, obj);
102         }
103
104         public void unbind(Name JavaDoc name) throws NamingException JavaDoc {
105             context.remove(name2String(name));
106         }
107
108         public void unbind(String JavaDoc name) throws NamingException JavaDoc {
109             context.remove(name);
110         }
111
112         public void rename(Name JavaDoc oldName, Name JavaDoc newName) throws NamingException JavaDoc {
113             bind(newName, lookup(oldName));
114             unbind(oldName);
115         }
116
117         public void rename(String JavaDoc oldName, String JavaDoc newName) throws NamingException JavaDoc {
118             bind(newName, lookup(oldName));
119             unbind(oldName);
120         }
121
122         public NamingEnumeration JavaDoc list(Name JavaDoc name) throws NamingException JavaDoc {
123             return null;
124         }
125
126         public NamingEnumeration JavaDoc list(String JavaDoc name) throws NamingException JavaDoc {
127             return null;
128         }
129
130         public NamingEnumeration JavaDoc listBindings(Name JavaDoc name) throws NamingException JavaDoc {
131             return null;
132         }
133
134         public NamingEnumeration JavaDoc listBindings(String JavaDoc name) throws NamingException JavaDoc {
135             return null;
136         }
137
138         public void destroySubcontext(Name JavaDoc name) throws NamingException JavaDoc {
139         }
140
141         public void destroySubcontext(String JavaDoc name) throws NamingException JavaDoc {
142         }
143
144         public Context JavaDoc createSubcontext(Name JavaDoc name) throws NamingException JavaDoc {
145             return null;
146         }
147
148         public Context JavaDoc createSubcontext(String JavaDoc name) throws NamingException JavaDoc {
149             return null;
150         }
151
152         public Object JavaDoc lookupLink(Name JavaDoc name) throws NamingException JavaDoc {
153             return null;
154         }
155
156         public Object JavaDoc lookupLink(String JavaDoc name) throws NamingException JavaDoc {
157             return null;
158         }
159
160         public NameParser JavaDoc getNameParser(Name JavaDoc name) throws NamingException JavaDoc {
161             return null;
162         }
163
164         public NameParser JavaDoc getNameParser(String JavaDoc name) throws NamingException JavaDoc {
165             return null;
166         }
167
168         public Name JavaDoc composeName(Name JavaDoc name, Name JavaDoc prefix) throws NamingException JavaDoc {
169             return null;
170         }
171
172         public String JavaDoc composeName(String JavaDoc name, String JavaDoc prefix)
173                 throws NamingException JavaDoc {
174             return null;
175         }
176
177         public Object JavaDoc addToEnvironment(String JavaDoc propName, Object JavaDoc propVal)
178                 throws NamingException JavaDoc {
179             return null;
180         }
181
182         public Object JavaDoc removeFromEnvironment(String JavaDoc propName)
183                 throws NamingException JavaDoc {
184             return null;
185         }
186
187         public Hashtable JavaDoc getEnvironment() throws NamingException JavaDoc {
188             return context;
189         }
190
191         public void close() throws NamingException JavaDoc {
192         }
193
194         public String JavaDoc getNameInNamespace() throws NamingException JavaDoc {
195             return null;
196         }
197     }
198 }
199
Popular Tags