KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > oracle > toplink > essentials > internal > ejb > cmp3 > naming > base > InitialContextImpl


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the "License"). You may not use this file except
5  * in compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * glassfish/bootstrap/legal/CDDLv1.0.txt or
9  * https://glassfish.dev.java.net/public/CDDLv1.0.html.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * HEADER in each file and include the License file at
15  * glassfish/bootstrap/legal/CDDLv1.0.txt. If applicable,
16  * add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your
18  * own identifying information: Portions Copyright [yyyy]
19  * [name of copyright owner]
20  */

21 // Copyright (c) 1998, 2005, Oracle. All rights reserved.
22
package oracle.toplink.essentials.internal.ejb.cmp3.naming.base;
23
24 import java.util.Hashtable JavaDoc;
25 import javax.naming.*;
26
27 public abstract class InitialContextImpl implements Context {
28     Hashtable JavaDoc env;
29
30     // Single global namespace
31
static Hashtable JavaDoc stringNamespace = new Hashtable JavaDoc();
32     static Hashtable JavaDoc namespace = new Hashtable JavaDoc();
33
34     /************************/
35     /***** Internal API *****/
36     /************************/
37     protected abstract Object JavaDoc handleEntityManagerFactory(Object JavaDoc obj);
38
39     protected void debug(String JavaDoc s) {
40         System.out.println(s);
41     }
42
43     public InitialContextImpl() {
44     }
45
46     public InitialContextImpl(Hashtable JavaDoc env) {
47         this.env = env;
48     }
49
50     public Object JavaDoc internalLookup(Object JavaDoc name) {
51         // Check the String namespace first
52
Object JavaDoc obj = stringNamespace.get(name);
53
54         // If not found then check the real namespace
55
if (obj == null) {
56             obj = namespace.get(name);
57         }
58
59         // If still not found then it just isn't there
60
if (obj == null) {
61             return null;
62         }
63         debug("Ctx - JNDI lookup, name=" + name + " value=" + obj);
64         // Temporary workaround to instantiate an EntityManager from the Factory
65

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