1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package com.fatwire.gst.foundation.test.jndi;
18
19 import java.util.HashMap;
20 import java.util.Hashtable;
21 import java.util.Map;
22
23 import javax.naming.Binding;
24 import javax.naming.Context;
25 import javax.naming.Name;
26 import javax.naming.NameClassPair;
27 import javax.naming.NameParser;
28 import javax.naming.NamingEnumeration;
29 import javax.naming.NamingException;
30
31
32
33
34
35
36 public class VerySimpleInitialContextFactory implements javax.naming.spi.InitialContextFactory {
37 private static Context initial;
38
39 public VerySimpleInitialContextFactory() {
40 super();
41
42 }
43
44 @SuppressWarnings("unchecked")
45 public Context getInitialContext(final Hashtable<?, ?> environment) throws NamingException {
46
47 if (initial == null)
48 initial = new Context() {
49 @SuppressWarnings("rawtypes")
50 Hashtable env = new Hashtable(environment);
51 Map<String, Object> store = new HashMap<String, Object>();
52
53 public Object addToEnvironment(String propName, Object propVal) throws NamingException {
54 return env.put(propName, propVal);
55 }
56
57 public void bind(Name name, Object obj) throws NamingException {
58 store.put(name.toString(), obj);
59
60 }
61
62 public void bind(String name, Object obj) throws NamingException {
63 store.put(name.toString(), obj);
64
65 }
66
67 public void close() throws NamingException {
68 store.clear();
69
70 }
71
72 public Name composeName(Name name, Name prefix) throws NamingException {
73
74 return null;
75 }
76
77 public String composeName(String name, String prefix) throws NamingException {
78
79 return null;
80 }
81
82 public Context createSubcontext(Name name) throws NamingException {
83
84 return null;
85 }
86
87 public Context createSubcontext(String name) throws NamingException {
88
89 return null;
90 }
91
92 public void destroySubcontext(Name name) throws NamingException {
93
94 }
95
96 public void destroySubcontext(String name) throws NamingException {
97
98 }
99
100 public Hashtable<?, ?> getEnvironment() throws NamingException {
101 return env;
102 }
103
104 public String getNameInNamespace() throws NamingException {
105
106 return null;
107 }
108
109 public NameParser getNameParser(Name name) throws NamingException {
110
111 return null;
112 }
113
114 public NameParser getNameParser(String name) throws NamingException {
115
116 return null;
117 }
118
119 public NamingEnumeration<NameClassPair> list(Name name) throws NamingException {
120
121 return null;
122 }
123
124 public NamingEnumeration<NameClassPair> list(String name) throws NamingException {
125
126 return null;
127 }
128
129 public NamingEnumeration<Binding> listBindings(Name name) throws NamingException {
130
131 return null;
132 }
133
134 public NamingEnumeration<Binding> listBindings(String name) throws NamingException {
135
136 return null;
137 }
138
139 public Object lookup(Name name) throws NamingException {
140 return store.get(name.toString());
141 }
142
143 public Object lookup(String name) throws NamingException {
144 return store.get(name);
145 }
146
147 public Object lookupLink(Name name) throws NamingException {
148
149 return null;
150 }
151
152 public Object lookupLink(String name) throws NamingException {
153
154 return null;
155 }
156
157 public void rebind(Name name, Object obj) throws NamingException {
158 store.put(name.toString(), obj);
159
160 }
161
162 public void rebind(String name, Object obj) throws NamingException {
163 store.put(name, obj);
164
165 }
166
167 public Object removeFromEnvironment(String propName) throws NamingException {
168
169 return null;
170 }
171
172 public void rename(Name oldName, Name newName) throws NamingException {
173
174 }
175
176 public void rename(String oldName, String newName) throws NamingException {
177
178 }
179
180 public void unbind(Name name) throws NamingException {
181 store.remove(name.toString());
182
183 }
184
185 public void unbind(String name) throws NamingException {
186 store.remove(name);
187
188 }
189 };
190 return initial;
191 }
192 }