|
1 /* |
|
2 * Copyright 1999-2004 Sun Microsystems, Inc. All Rights Reserved. |
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
|
4 * |
|
5 * This code is free software; you can redistribute it and/or modify it |
|
6 * under the terms of the GNU General Public License version 2 only, as |
|
7 * published by the Free Software Foundation. Sun designates this |
|
8 * particular file as subject to the "Classpath" exception as provided |
|
9 * by Sun in the LICENSE file that accompanied this code. |
|
10 * |
|
11 * This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 * version 2 for more details (a copy is included in the LICENSE file that |
|
15 * accompanied this code). |
|
16 * |
|
17 * You should have received a copy of the GNU General Public License version |
|
18 * 2 along with this work; if not, write to the Free Software Foundation, |
|
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 * |
|
21 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
|
22 * CA 95054 USA or visit www.sun.com if you need additional information or |
|
23 * have any questions. |
|
24 */ |
|
25 |
|
26 |
|
27 package javax.naming.directory; |
|
28 |
|
29 import java.util.Hashtable; |
|
30 import javax.naming.spi.NamingManager; |
|
31 import javax.naming.*; |
|
32 |
|
33 /** |
|
34 * This class is the starting context for performing |
|
35 * directory operations. The documentation in the class description |
|
36 * of InitialContext (including those for synchronization) apply here. |
|
37 * |
|
38 * |
|
39 * @author Rosanna Lee |
|
40 * @author Scott Seligman |
|
41 * |
|
42 * @see javax.naming.InitialContext |
|
43 * @since 1.3 |
|
44 */ |
|
45 |
|
46 public class InitialDirContext extends InitialContext implements DirContext { |
|
47 |
|
48 /** |
|
49 * Constructs an initial DirContext with the option of not |
|
50 * initializing it. This may be used by a constructor in |
|
51 * a subclass when the value of the environment parameter |
|
52 * is not yet known at the time the <tt>InitialDirContext</tt> |
|
53 * constructor is called. The subclass's constructor will |
|
54 * call this constructor, compute the value of the environment, |
|
55 * and then call <tt>init()</tt> before returning. |
|
56 * |
|
57 * @param lazy |
|
58 * true means do not initialize the initial DirContext; false |
|
59 * is equivalent to calling <tt>new InitialDirContext()</tt> |
|
60 * @throws NamingException if a naming exception is encountered |
|
61 * |
|
62 * @see InitialContext#init(Hashtable) |
|
63 * @since 1.3 |
|
64 */ |
|
65 protected InitialDirContext(boolean lazy) throws NamingException { |
|
66 super(lazy); |
|
67 } |
|
68 |
|
69 /** |
|
70 * Constructs an initial DirContext. |
|
71 * No environment properties are supplied. |
|
72 * Equivalent to <tt>new InitialDirContext(null)</tt>. |
|
73 * |
|
74 * @throws NamingException if a naming exception is encountered |
|
75 * |
|
76 * @see #InitialDirContext(Hashtable) |
|
77 */ |
|
78 public InitialDirContext() throws NamingException { |
|
79 super(); |
|
80 } |
|
81 |
|
82 /** |
|
83 * Constructs an initial DirContext using the supplied environment. |
|
84 * Environment properties are discussed in the |
|
85 * <tt>javax.naming.InitialContext</tt> class description. |
|
86 * |
|
87 * <p> This constructor will not modify <tt>environment</tt> |
|
88 * or save a reference to it, but may save a clone. |
|
89 * |
|
90 * @param environment |
|
91 * environment used to create the initial DirContext. |
|
92 * Null indicates an empty environment. |
|
93 * |
|
94 * @throws NamingException if a naming exception is encountered |
|
95 */ |
|
96 public InitialDirContext(Hashtable<?,?> environment) |
|
97 throws NamingException |
|
98 { |
|
99 super(environment); |
|
100 } |
|
101 |
|
102 private DirContext getURLOrDefaultInitDirCtx(String name) |
|
103 throws NamingException { |
|
104 Context answer = getURLOrDefaultInitCtx(name); |
|
105 if (!(answer instanceof DirContext)) { |
|
106 if (answer == null) { |
|
107 throw new NoInitialContextException(); |
|
108 } else { |
|
109 throw new NotContextException( |
|
110 "Not an instance of DirContext"); |
|
111 } |
|
112 } |
|
113 return (DirContext)answer; |
|
114 } |
|
115 |
|
116 private DirContext getURLOrDefaultInitDirCtx(Name name) |
|
117 throws NamingException { |
|
118 Context answer = getURLOrDefaultInitCtx(name); |
|
119 if (!(answer instanceof DirContext)) { |
|
120 if (answer == null) { |
|
121 throw new NoInitialContextException(); |
|
122 } else { |
|
123 throw new NotContextException( |
|
124 "Not an instance of DirContext"); |
|
125 } |
|
126 } |
|
127 return (DirContext)answer; |
|
128 } |
|
129 |
|
130 // DirContext methods |
|
131 // Most Javadoc is deferred to the DirContext interface. |
|
132 |
|
133 public Attributes getAttributes(String name) |
|
134 throws NamingException { |
|
135 return getAttributes(name, null); |
|
136 } |
|
137 |
|
138 public Attributes getAttributes(String name, String[] attrIds) |
|
139 throws NamingException { |
|
140 return getURLOrDefaultInitDirCtx(name).getAttributes(name, attrIds); |
|
141 } |
|
142 |
|
143 public Attributes getAttributes(Name name) |
|
144 throws NamingException { |
|
145 return getAttributes(name, null); |
|
146 } |
|
147 |
|
148 public Attributes getAttributes(Name name, String[] attrIds) |
|
149 throws NamingException { |
|
150 return getURLOrDefaultInitDirCtx(name).getAttributes(name, attrIds); |
|
151 } |
|
152 |
|
153 public void modifyAttributes(String name, int mod_op, Attributes attrs) |
|
154 throws NamingException { |
|
155 getURLOrDefaultInitDirCtx(name).modifyAttributes(name, mod_op, attrs); |
|
156 } |
|
157 |
|
158 public void modifyAttributes(Name name, int mod_op, Attributes attrs) |
|
159 throws NamingException { |
|
160 getURLOrDefaultInitDirCtx(name).modifyAttributes(name, mod_op, attrs); |
|
161 } |
|
162 |
|
163 public void modifyAttributes(String name, ModificationItem[] mods) |
|
164 throws NamingException { |
|
165 getURLOrDefaultInitDirCtx(name).modifyAttributes(name, mods); |
|
166 } |
|
167 |
|
168 public void modifyAttributes(Name name, ModificationItem[] mods) |
|
169 throws NamingException { |
|
170 getURLOrDefaultInitDirCtx(name).modifyAttributes(name, mods); |
|
171 } |
|
172 |
|
173 public void bind(String name, Object obj, Attributes attrs) |
|
174 throws NamingException { |
|
175 getURLOrDefaultInitDirCtx(name).bind(name, obj, attrs); |
|
176 } |
|
177 |
|
178 public void bind(Name name, Object obj, Attributes attrs) |
|
179 throws NamingException { |
|
180 getURLOrDefaultInitDirCtx(name).bind(name, obj, attrs); |
|
181 } |
|
182 |
|
183 public void rebind(String name, Object obj, Attributes attrs) |
|
184 throws NamingException { |
|
185 getURLOrDefaultInitDirCtx(name).rebind(name, obj, attrs); |
|
186 } |
|
187 |
|
188 public void rebind(Name name, Object obj, Attributes attrs) |
|
189 throws NamingException { |
|
190 getURLOrDefaultInitDirCtx(name).rebind(name, obj, attrs); |
|
191 } |
|
192 |
|
193 public DirContext createSubcontext(String name, Attributes attrs) |
|
194 throws NamingException { |
|
195 return getURLOrDefaultInitDirCtx(name).createSubcontext(name, attrs); |
|
196 } |
|
197 |
|
198 public DirContext createSubcontext(Name name, Attributes attrs) |
|
199 throws NamingException { |
|
200 return getURLOrDefaultInitDirCtx(name).createSubcontext(name, attrs); |
|
201 } |
|
202 |
|
203 public DirContext getSchema(String name) throws NamingException { |
|
204 return getURLOrDefaultInitDirCtx(name).getSchema(name); |
|
205 } |
|
206 |
|
207 public DirContext getSchema(Name name) throws NamingException { |
|
208 return getURLOrDefaultInitDirCtx(name).getSchema(name); |
|
209 } |
|
210 |
|
211 public DirContext getSchemaClassDefinition(String name) |
|
212 throws NamingException { |
|
213 return getURLOrDefaultInitDirCtx(name).getSchemaClassDefinition(name); |
|
214 } |
|
215 |
|
216 public DirContext getSchemaClassDefinition(Name name) |
|
217 throws NamingException { |
|
218 return getURLOrDefaultInitDirCtx(name).getSchemaClassDefinition(name); |
|
219 } |
|
220 |
|
221 // -------------------- search operations |
|
222 |
|
223 public NamingEnumeration<SearchResult> |
|
224 search(String name, Attributes matchingAttributes) |
|
225 throws NamingException |
|
226 { |
|
227 return getURLOrDefaultInitDirCtx(name).search(name, matchingAttributes); |
|
228 } |
|
229 |
|
230 public NamingEnumeration<SearchResult> |
|
231 search(Name name, Attributes matchingAttributes) |
|
232 throws NamingException |
|
233 { |
|
234 return getURLOrDefaultInitDirCtx(name).search(name, matchingAttributes); |
|
235 } |
|
236 |
|
237 public NamingEnumeration<SearchResult> |
|
238 search(String name, |
|
239 Attributes matchingAttributes, |
|
240 String[] attributesToReturn) |
|
241 throws NamingException |
|
242 { |
|
243 return getURLOrDefaultInitDirCtx(name).search(name, |
|
244 matchingAttributes, |
|
245 attributesToReturn); |
|
246 } |
|
247 |
|
248 public NamingEnumeration<SearchResult> |
|
249 search(Name name, |
|
250 Attributes matchingAttributes, |
|
251 String[] attributesToReturn) |
|
252 throws NamingException |
|
253 { |
|
254 return getURLOrDefaultInitDirCtx(name).search(name, |
|
255 matchingAttributes, |
|
256 attributesToReturn); |
|
257 } |
|
258 |
|
259 public NamingEnumeration<SearchResult> |
|
260 search(String name, |
|
261 String filter, |
|
262 SearchControls cons) |
|
263 throws NamingException |
|
264 { |
|
265 return getURLOrDefaultInitDirCtx(name).search(name, filter, cons); |
|
266 } |
|
267 |
|
268 public NamingEnumeration<SearchResult> |
|
269 search(Name name, |
|
270 String filter, |
|
271 SearchControls cons) |
|
272 throws NamingException |
|
273 { |
|
274 return getURLOrDefaultInitDirCtx(name).search(name, filter, cons); |
|
275 } |
|
276 |
|
277 public NamingEnumeration<SearchResult> |
|
278 search(String name, |
|
279 String filterExpr, |
|
280 Object[] filterArgs, |
|
281 SearchControls cons) |
|
282 throws NamingException |
|
283 { |
|
284 return getURLOrDefaultInitDirCtx(name).search(name, filterExpr, |
|
285 filterArgs, cons); |
|
286 } |
|
287 |
|
288 public NamingEnumeration<SearchResult> |
|
289 search(Name name, |
|
290 String filterExpr, |
|
291 Object[] filterArgs, |
|
292 SearchControls cons) |
|
293 throws NamingException |
|
294 { |
|
295 return getURLOrDefaultInitDirCtx(name).search(name, filterExpr, |
|
296 filterArgs, cons); |
|
297 } |
|
298 } |