1 /*
2 * org.osjava.sj.memory.MemoryContext
3 * $Id: MemoryContext.java 1743 2005-06-24 23:56:40Z rzigweid $
4 * $Rev: 1743 $
5 * $Date: 2005-06-24 16:56:40 -0700 (Fri, 24 Jun 2005) $
6 * $Author: rzigweid $
7 * $URL: https://osjava.googlecode.com/svn/releases/simple-jndi-0.11.4.1/src/java/org/osjava/sj/memory/MemoryContext.java $
8 *
9 * Created on Dec 30, 2004
10 *
11 * Copyright (c) 2004, Robert M. Zigweid All rights reserved.
12 *
13 * Redistribution and use in source and binary forms, with or without
14 * modification, are permitted provided that the following conditions are met:
15 *
16 * + Redistributions of source code must retain the above copyright notice,
17 * this list of conditions and the following disclaimer.
18 *
19 * + Redistributions in binary form must reproduce the above copyright notice,
20 * this list of conditions and the following disclaimer in the documentation
21 * and/or other materials provided with the distribution.
22 *
23 * + Neither the name of the Simple-JNDI nor the names of its contributors may
24 * be used to endorse or promote products derived from this software without
25 * specific prior written permission.
26 *
27 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
28 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
29 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
30 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
31 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
32 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
33 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
34 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
35 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
36 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37 * POSSIBILITY OF SUCH DAMAGE.
38 */
39
40
41 package org.osjava.sj.memory;
42
43 import java.util.Hashtable;
44
45 import javax.naming.Context;
46 import javax.naming.Name;
47 import javax.naming.NameAlreadyBoundException;
48 import javax.naming.NameNotFoundException;
49 import javax.naming.NameParser;
50 import javax.naming.NamingException;
51
52 import org.osjava.sj.jndi.AbstractContext;
53
54 /***
55 * A generic context that requires no DataSource backend. It is designed to
56 * live exclusively in memory and not have its state saved.
57 *
58 * @author Robert M. Zigweid
59 * @since Simple-JNDI 0.11
60 * @version $Rev: 1743 $ $Date: 2005-06-24 16:56:40 -0700 (Fri, 24 Jun 2005) $
61 */
62 public class MemoryContext extends AbstractContext {
63
64 /***
65 *
66 */
67 public MemoryContext() {
68 super();
69 // TODO Auto-generated constructor stub
70 }
71
72 /***
73 * @param env
74 */
75 public MemoryContext(Hashtable env) {
76 super(env);
77 // TODO Auto-generated constructor stub
78 }
79
80 /***
81 * @param env
82 * @param systemOverride
83 */
84 public MemoryContext(Hashtable env, boolean systemOverride) {
85 super(env, systemOverride);
86 // TODO Auto-generated constructor stub
87 }
88
89 /***
90 * @param env
91 * @param parser
92 */
93 public MemoryContext(Hashtable env, NameParser parser) {
94 super(env, parser);
95 // TODO Auto-generated constructor stub
96 }
97
98 /***
99 * @param systemOverride
100 */
101 public MemoryContext(boolean systemOverride) {
102 super(systemOverride);
103 // TODO Auto-generated constructor stub
104 }
105
106 /***
107 * @param systemOverride
108 * @param parser
109 */
110 public MemoryContext(boolean systemOverride, NameParser parser) {
111 super(systemOverride, parser);
112 // TODO Auto-generated constructor stub
113 }
114
115 /***
116 * @param parser
117 */
118 public MemoryContext(NameParser parser) {
119 super(parser);
120 // TODO Auto-generated constructor stub
121 }
122
123 /***
124 * @param env
125 * @param systemOverride
126 * @param parser
127 */
128 public MemoryContext(Hashtable env, boolean systemOverride, NameParser parser) {
129 super(env, systemOverride, parser);
130 // TODO Auto-generated constructor stub
131 }
132
133 /***
134 * @param that
135 */
136 public MemoryContext(AbstractContext that) {
137 super(that);
138 // TODO Auto-generated constructor stub
139 }
140
141 /***
142 * @see javax.naming.Context#createSubcontext(javax.naming.Name)
143 */
144 public Context createSubcontext(Name name) throws NamingException {
145 Context newContext;
146 /* Get the subcontexts of /this/ subcontext. */
147 Hashtable subContexts = getSubContexts();
148
149 if(name.size() > 1) {
150 if(subContexts.containsKey(name.getPrefix(1))) {
151 Context subContext = (Context)subContexts.get(name.getPrefix(1));
152 newContext = subContext.createSubcontext(name.getSuffix(1));
153 return newContext;
154 }
155 throw new NameNotFoundException("The subcontext " + name.getPrefix(1) + " was not found.");
156 }
157
158 if(lookup(name) != null) {
159 throw new NameAlreadyBoundException();
160 }
161
162 Name contextName = getNameParser((Name)null).parse(getNameInNamespace());
163 contextName.addAll(name);
164 newContext = new MemoryContext(this);
165 ((AbstractContext)newContext).setNameInNamespace(contextName);
166 bind(name, newContext);
167 return newContext;
168 }
169 }