001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * // Copyright (c) 1998, 2007, Oracle. All rights reserved.
005: *
006: *
007: * The contents of this file are subject to the terms of either the GNU
008: * General Public License Version 2 only ("GPL") or the Common Development
009: * and Distribution License("CDDL") (collectively, the "License"). You
010: * may not use this file except in compliance with the License. You can obtain
011: * a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
012: * or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
013: * language governing permissions and limitations under the License.
014: *
015: * When distributing the software, include this License Header Notice in each
016: * file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
017: * Sun designates this particular file as subject to the "Classpath" exception
018: * as provided by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the License
020: * Header, with the fields enclosed by brackets [] replaced by your own
021: * identifying information: "Portions Copyrighted [year]
022: * [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * If you wish your version of this file to be governed by only the CDDL or
027: * only the GPL Version 2, indicate your decision by adding "[Contributor]
028: * elects to include this software in this distribution under the [CDDL or GPL
029: * Version 2] license." If you don't indicate a single choice of license, a
030: * recipient has the option to distribute your version of this file under
031: * either the CDDL, the GPL Version 2 or to extend the choice of license to
032: * its licensees as provided above. However, if you add GPL Version 2 code
033: * and therefore, elected the GPL Version 2 license, then the option applies
034: * only if the new code is made subject to such option by the copyright
035: * holder.
036: */
037: package oracle.toplink.essentials.internal.ejb.cmp3.naming.base;
038:
039: import java.util.Hashtable;
040: import javax.naming.*;
041:
042: public abstract class InitialContextImpl implements Context {
043: Hashtable env;
044:
045: // Single global namespace
046: static Hashtable stringNamespace = new Hashtable();
047: static Hashtable namespace = new Hashtable();
048:
049: /************************/
050: /***** Internal API *****/
051: /************************/
052: protected abstract Object handleEntityManagerFactory(Object obj);
053:
054: protected void debug(String s) {
055: System.out.println(s);
056: }
057:
058: public InitialContextImpl() {
059: }
060:
061: public InitialContextImpl(Hashtable env) {
062: this .env = env;
063: }
064:
065: public Object internalLookup(Object name) {
066: // Check the String namespace first
067: Object obj = stringNamespace.get(name);
068:
069: // If not found then check the real namespace
070: if (obj == null) {
071: obj = namespace.get(name);
072: }
073:
074: // If still not found then it just isn't there
075: if (obj == null) {
076: return null;
077: }
078: debug("Ctx - JNDI lookup, name=" + name + " value=" + obj);
079: // Temporary workaround to instantiate an EntityManager from the Factory
080:
081: return handleEntityManagerFactory(obj);
082: }
083:
084: /*************************************/
085: /***** Supported Context API *****/
086: /*************************************/
087: public Object lookup(String name) throws NamingException {
088: Object obj = internalLookup(name);
089: if (obj == null) {
090: throw new NameNotFoundException(name);
091: }
092: return obj;
093: }
094:
095: public Object lookup(Name name) throws NamingException {
096: Object obj = internalLookup(name);
097: if (obj == null) {
098: throw new NameNotFoundException(name.toString());
099: }
100: return obj;
101: }
102:
103: public void bind(String name, Object obj) throws NamingException {
104: if (internalLookup(name) != null) {
105: throw new NameAlreadyBoundException(name);
106: }
107: rebind(name, obj);
108: }
109:
110: public void bind(Name name, Object obj) throws NamingException {
111: if (internalLookup(name) != null) {
112: throw new NameAlreadyBoundException(name.toString());
113: }
114: rebind(name, obj);
115: }
116:
117: public void rebind(String name, Object obj) throws NamingException {
118: stringNamespace.put(name, obj);
119: // debug("Ctx - Namespace = " + stringNamespace + " class=" + this.getClass().getClassLoader());
120: // Bind as a Name as well
121: rebind(new CompositeName(name), obj);
122: }
123:
124: public void rebind(Name name, Object obj) throws NamingException {
125: namespace.put(name, obj);
126: }
127:
128: public Hashtable getEnvironment() throws NamingException {
129: return env;
130: }
131:
132: public void close() throws NamingException {
133: }
134:
135: /*************************************/
136: /***** Not supported Context API *****/
137: /*************************************/
138: public void unbind(Name name) throws NamingException {
139: }
140:
141: public void unbind(String name) throws NamingException {
142: }
143:
144: public void rename(Name oldName, Name newName)
145: throws NamingException {
146: }
147:
148: public void rename(String oldName, String newName)
149: throws NamingException {
150: }
151:
152: public NamingEnumeration list(Name name) throws NamingException {
153: return null;
154: }
155:
156: public NamingEnumeration list(String name) throws NamingException {
157: return null;
158: }
159:
160: public NamingEnumeration listBindings(Name name)
161: throws NamingException {
162: return null;
163: }
164:
165: public NamingEnumeration listBindings(String name)
166: throws NamingException {
167: return null;
168: }
169:
170: public void destroySubcontext(Name name) throws NamingException {
171: }
172:
173: public void destroySubcontext(String name) throws NamingException {
174: }
175:
176: public Context createSubcontext(Name name) throws NamingException {
177: return null;
178: }
179:
180: public Context createSubcontext(String name) throws NamingException {
181: return null;
182: }
183:
184: public Object lookupLink(Name name) throws NamingException {
185: return null;
186: }
187:
188: public Object lookupLink(String name) throws NamingException {
189: return null;
190: }
191:
192: public NameParser getNameParser(Name name) throws NamingException {
193: return null;
194: }
195:
196: public NameParser getNameParser(String name) throws NamingException {
197: return null;
198: }
199:
200: public Name composeName(Name name, Name prefix)
201: throws NamingException {
202: return null;
203: }
204:
205: public String composeName(String name, String prefix)
206: throws NamingException {
207: return null;
208: }
209:
210: public Object addToEnvironment(String propName, Object propVal)
211: throws NamingException {
212: return null;
213: }
214:
215: public Object removeFromEnvironment(String propName)
216: throws NamingException {
217: return null;
218: }
219:
220: public String getNameInNamespace() throws NamingException {
221: return null;
222: }
223: }
|