blob: a5bd91c85fc9c8a72be2f37788edb64b1e97016f [file] [log] [blame]
J. Duke319a3b92007-12-01 00:00:00 +00001/*
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
26package com.sun.jndi.toolkit.ctx;
27
28import java.util.Hashtable;
29
30import javax.naming.*;
31import javax.naming.directory.*;
32import javax.naming.spi.NamingManager;
33import javax.naming.spi.DirectoryManager;
34
35/*
36 * Inherit from AtomicContext so that subclasses of PartialCompositeDirContext
37 * can get the ns methods defined in subclasses of PartialCompositeContext.
38 *
39 * Direct subclasses of DirContext should provide implementations for
40 * the p_ abstract DirContext methods and override the p_ Context methods
41 * (not abstract anymore because they are overridden by ComponentContext
42 * (the superclass of AtomicContext)).
43 *
44 * @author Rosanna Lee
45 */
46
47public abstract class PartialCompositeDirContext
48 extends AtomicContext implements DirContext {
49
50 protected PartialCompositeDirContext() {
51 _contextType = _PARTIAL;
52 }
53
54// ------ Abstract methods whose implementation come from subclasses
55
56 /* Equivalent to DirContext methods */
57 protected abstract Attributes p_getAttributes(Name name, String[] attrIds,
58 Continuation cont)
59 throws NamingException;
60
61 protected abstract void p_modifyAttributes(Name name, int mod_op,
62 Attributes attrs,
63 Continuation cont)
64 throws NamingException;
65
66 protected abstract void p_modifyAttributes(Name name,
67 ModificationItem[] mods,
68 Continuation cont)
69 throws NamingException;
70
71 protected abstract void p_bind(Name name, Object obj,
72 Attributes attrs,
73 Continuation cont)
74 throws NamingException;
75
76 protected abstract void p_rebind(Name name, Object obj,
77 Attributes attrs,
78 Continuation cont)
79 throws NamingException;
80
81 protected abstract DirContext p_createSubcontext(Name name,
82 Attributes attrs,
83 Continuation cont)
84 throws NamingException;
85
86 protected abstract NamingEnumeration p_search(Name name,
87 Attributes matchingAttributes,
88 String[] attributesToReturn,
89 Continuation cont)
90 throws NamingException;
91
92 protected abstract NamingEnumeration p_search(Name name,
93 String filter,
94 SearchControls cons,
95 Continuation cont)
96 throws NamingException;
97
98 protected abstract NamingEnumeration p_search(Name name,
99 String filterExpr,
100 Object[] filterArgs,
101 SearchControls cons,
102 Continuation cont)
103 throws NamingException;
104
105 protected abstract DirContext p_getSchema(Name name, Continuation cont)
106 throws NamingException;
107
108 protected abstract DirContext p_getSchemaClassDefinition(Name name,
109 Continuation cont)
110 throws NamingException;
111
112// ------ implementation for DirContext methods using
113// ------ corresponding p_ methods
114
115 public Attributes getAttributes(String name)
116 throws NamingException {
117 return getAttributes(name, null);
118 }
119
120 public Attributes getAttributes(Name name)
121 throws NamingException {
122 return getAttributes(name, null);
123 }
124
125 public Attributes getAttributes(String name, String[] attrIds)
126 throws NamingException {
127 return getAttributes(new CompositeName(name), attrIds);
128 }
129
130 public Attributes getAttributes(Name name, String[] attrIds)
131 throws NamingException {
132 PartialCompositeDirContext ctx = this;
133 Hashtable env = p_getEnvironment();
134 Continuation cont = new Continuation(name, env);
135 Attributes answer;
136 Name nm = name;
137
138 try {
139 answer = ctx.p_getAttributes(nm, attrIds, cont);
140 while (cont.isContinue()) {
141 nm = cont.getRemainingName();
142 ctx = getPCDirContext(cont);
143 answer = ctx.p_getAttributes(nm, attrIds, cont);
144 }
145 } catch (CannotProceedException e) {
146 DirContext cctx = DirectoryManager.getContinuationDirContext(e);
147 answer = cctx.getAttributes(e.getRemainingName(), attrIds);
148 }
149 return answer;
150 }
151
152 public void modifyAttributes(String name, int mod_op, Attributes attrs)
153 throws NamingException {
154 modifyAttributes(new CompositeName(name), mod_op, attrs);
155 }
156
157 public void modifyAttributes(Name name, int mod_op, Attributes attrs)
158 throws NamingException {
159 PartialCompositeDirContext ctx = this;
160 Hashtable env = p_getEnvironment();
161 Continuation cont = new Continuation(name, env);
162 Name nm = name;
163
164 try {
165 ctx.p_modifyAttributes(nm, mod_op, attrs, cont);
166 while (cont.isContinue()) {
167 nm = cont.getRemainingName();
168 ctx = getPCDirContext(cont);
169 ctx.p_modifyAttributes(nm, mod_op, attrs, cont);
170 }
171 } catch (CannotProceedException e) {
172 DirContext cctx = DirectoryManager.getContinuationDirContext(e);
173 cctx.modifyAttributes(e.getRemainingName(), mod_op, attrs);
174 }
175 }
176
177 public void modifyAttributes(String name, ModificationItem[] mods)
178 throws NamingException {
179 modifyAttributes(new CompositeName(name), mods);
180 }
181
182 public void modifyAttributes(Name name, ModificationItem[] mods)
183 throws NamingException {
184 PartialCompositeDirContext ctx = this;
185 Hashtable env = p_getEnvironment();
186 Continuation cont = new Continuation(name, env);
187 Name nm = name;
188
189 try {
190 ctx.p_modifyAttributes(nm, mods, cont);
191 while (cont.isContinue()) {
192 nm = cont.getRemainingName();
193 ctx = getPCDirContext(cont);
194 ctx.p_modifyAttributes(nm, mods, cont);
195 }
196 } catch (CannotProceedException e) {
197 DirContext cctx = DirectoryManager.getContinuationDirContext(e);
198 cctx.modifyAttributes(e.getRemainingName(), mods);
199 }
200 }
201
202 public void bind(String name, Object obj, Attributes attrs)
203 throws NamingException {
204 bind(new CompositeName(name), obj, attrs);
205 }
206
207 public void bind(Name name, Object obj, Attributes attrs)
208 throws NamingException {
209 PartialCompositeDirContext ctx = this;
210 Hashtable env = p_getEnvironment();
211 Continuation cont = new Continuation(name, env);
212 Name nm = name;
213
214 try {
215 ctx.p_bind(nm, obj, attrs, cont);
216 while (cont.isContinue()) {
217 nm = cont.getRemainingName();
218 ctx = getPCDirContext(cont);
219 ctx.p_bind(nm, obj, attrs, cont);
220 }
221 } catch (CannotProceedException e) {
222 DirContext cctx = DirectoryManager.getContinuationDirContext(e);
223 cctx.bind(e.getRemainingName(), obj, attrs);
224 }
225 }
226
227 public void rebind(String name, Object obj, Attributes attrs)
228 throws NamingException {
229 rebind(new CompositeName(name), obj, attrs);
230 }
231
232 public void rebind(Name name, Object obj, Attributes attrs)
233 throws NamingException {
234 PartialCompositeDirContext ctx = this;
235 Hashtable env = p_getEnvironment();
236 Continuation cont = new Continuation(name, env);
237 Name nm = name;
238
239 try {
240 ctx.p_rebind(nm, obj, attrs, cont);
241 while (cont.isContinue()) {
242 nm = cont.getRemainingName();
243 ctx = getPCDirContext(cont);
244 ctx.p_rebind(nm, obj, attrs, cont);
245 }
246 } catch (CannotProceedException e) {
247 DirContext cctx = DirectoryManager.getContinuationDirContext(e);
248 cctx.rebind(e.getRemainingName(), obj, attrs);
249 }
250 }
251
252 public DirContext createSubcontext(String name, Attributes attrs)
253 throws NamingException {
254 return createSubcontext(new CompositeName(name), attrs);
255 }
256
257 public DirContext createSubcontext(Name name, Attributes attrs)
258 throws NamingException {
259 PartialCompositeDirContext ctx = this;
260 Hashtable env = p_getEnvironment();
261 Continuation cont = new Continuation(name, env);
262 DirContext answer;
263 Name nm = name;
264
265 try {
266 answer = ctx.p_createSubcontext(nm, attrs, cont);
267 while (cont.isContinue()) {
268 nm = cont.getRemainingName();
269 ctx = getPCDirContext(cont);
270 answer = ctx.p_createSubcontext(nm, attrs, cont);
271 }
272 } catch (CannotProceedException e) {
273 DirContext cctx = DirectoryManager.getContinuationDirContext(e);
274 answer = cctx.createSubcontext(e.getRemainingName(), attrs);
275 }
276 return answer;
277 }
278
279 public NamingEnumeration<SearchResult>
280 search(String name, Attributes matchingAttributes)
281 throws NamingException
282 {
283 return search(name, matchingAttributes, null);
284 }
285
286 public NamingEnumeration<SearchResult>
287 search(Name name, Attributes matchingAttributes)
288 throws NamingException
289 {
290 return search(name, matchingAttributes, null);
291 }
292
293 public NamingEnumeration<SearchResult>
294 search(String name,
295 Attributes matchingAttributes,
296 String[] attributesToReturn)
297 throws NamingException
298 {
299 return search(new CompositeName(name),
300 matchingAttributes, attributesToReturn);
301 }
302
303 public NamingEnumeration<SearchResult>
304 search(Name name,
305 Attributes matchingAttributes,
306 String[] attributesToReturn)
307 throws NamingException
308 {
309
310 PartialCompositeDirContext ctx = this;
311 Hashtable env = p_getEnvironment();
312 Continuation cont = new Continuation(name, env);
313 NamingEnumeration answer;
314 Name nm = name;
315
316 try {
317 answer = ctx.p_search(nm, matchingAttributes,
318 attributesToReturn, cont);
319 while (cont.isContinue()) {
320 nm = cont.getRemainingName();
321 ctx = getPCDirContext(cont);
322 answer = ctx.p_search(nm, matchingAttributes,
323 attributesToReturn, cont);
324 }
325 } catch (CannotProceedException e) {
326 DirContext cctx = DirectoryManager.getContinuationDirContext(e);
327 answer = cctx.search(e.getRemainingName(), matchingAttributes,
328 attributesToReturn);
329 }
330 return answer;
331 }
332
333 public NamingEnumeration<SearchResult>
334 search(String name,
335 String filter,
336 SearchControls cons)
337 throws NamingException
338 {
339 return search(new CompositeName(name), filter, cons);
340 }
341
342 public NamingEnumeration<SearchResult>
343 search(Name name,
344 String filter,
345 SearchControls cons)
346 throws NamingException
347 {
348
349 PartialCompositeDirContext ctx = this;
350 Hashtable env = p_getEnvironment();
351 Continuation cont = new Continuation(name, env);
352 NamingEnumeration answer;
353 Name nm = name;
354
355 try {
356 answer = ctx.p_search(nm, filter, cons, cont);
357 while (cont.isContinue()) {
358 nm = cont.getRemainingName();
359 ctx = getPCDirContext(cont);
360 answer = ctx.p_search(nm, filter, cons, cont);
361 }
362 } catch (CannotProceedException e) {
363 DirContext cctx = DirectoryManager.getContinuationDirContext(e);
364 answer = cctx.search(e.getRemainingName(), filter, cons);
365 }
366 return answer;
367 }
368
369 public NamingEnumeration<SearchResult>
370 search(String name,
371 String filterExpr,
372 Object[] filterArgs,
373 SearchControls cons)
374 throws NamingException
375 {
376 return search(new CompositeName(name), filterExpr, filterArgs, cons);
377 }
378
379 public NamingEnumeration<SearchResult>
380 search(Name name,
381 String filterExpr,
382 Object[] filterArgs,
383 SearchControls cons)
384 throws NamingException
385 {
386
387 PartialCompositeDirContext ctx = this;
388 Hashtable env = p_getEnvironment();
389 Continuation cont = new Continuation(name, env);
390 NamingEnumeration answer;
391 Name nm = name;
392
393 try {
394 answer = ctx.p_search(nm, filterExpr, filterArgs, cons, cont);
395 while (cont.isContinue()) {
396 nm = cont.getRemainingName();
397 ctx = getPCDirContext(cont);
398 answer = ctx.p_search(nm, filterExpr, filterArgs, cons, cont);
399 }
400 } catch (CannotProceedException e) {
401 DirContext cctx = DirectoryManager.getContinuationDirContext(e);
402 answer = cctx.search(e.getRemainingName(), filterExpr, filterArgs,
403 cons);
404 }
405 return answer;
406 }
407
408 public DirContext getSchema(String name) throws NamingException {
409 return getSchema(new CompositeName(name));
410 }
411
412 public DirContext getSchema(Name name) throws NamingException {
413 PartialCompositeDirContext ctx = this;
414 Hashtable env = p_getEnvironment();
415 Continuation cont = new Continuation(name, env);
416 DirContext answer;
417 Name nm = name;
418
419 try {
420 answer = ctx.p_getSchema(nm, cont);
421 while (cont.isContinue()) {
422 nm = cont.getRemainingName();
423 ctx = getPCDirContext(cont);
424 answer = ctx.p_getSchema(nm, cont);
425 }
426 } catch (CannotProceedException e) {
427 DirContext cctx = DirectoryManager.getContinuationDirContext(e);
428 answer = cctx.getSchema(e.getRemainingName());
429 }
430 return answer;
431 }
432
433 public DirContext getSchemaClassDefinition(String name)
434 throws NamingException {
435 return getSchemaClassDefinition(new CompositeName(name));
436 }
437
438 public DirContext getSchemaClassDefinition(Name name)
439 throws NamingException {
440 PartialCompositeDirContext ctx = this;
441 Hashtable env = p_getEnvironment();
442 Continuation cont = new Continuation(name, env);
443 DirContext answer;
444 Name nm = name;
445
446 try {
447 answer = ctx.p_getSchemaClassDefinition(nm, cont);
448 while (cont.isContinue()) {
449 nm = cont.getRemainingName();
450 ctx = getPCDirContext(cont);
451 answer = ctx.p_getSchemaClassDefinition(nm, cont);
452 }
453 } catch (CannotProceedException e) {
454 DirContext cctx = DirectoryManager.getContinuationDirContext(e);
455 answer = cctx.getSchemaClassDefinition(e.getRemainingName());
456 }
457 return answer;
458 }
459
460// ------ internal method used by PartialCompositeDirContext
461
462 /**
463 * Retrieves a PartialCompositeDirContext for the resolved object in
464 * cont. Throws CannotProceedException if not successful.
465 */
466 protected static PartialCompositeDirContext getPCDirContext(Continuation cont)
467 throws NamingException {
468
469 PartialCompositeContext pctx =
470 PartialCompositeContext.getPCContext(cont);
471
472 if (!(pctx instanceof PartialCompositeDirContext)) {
473 throw cont.fillInException(
474 new NotContextException(
475 "Resolved object is not a DirContext."));
476 }
477
478 return (PartialCompositeDirContext)pctx;
479 }
480
481
482//------ Compensation for inheriting from AtomicContext
483
484 /*
485 * Dummy implementations defined here so that direct subclasses
486 * of PartialCompositeDirContext or ComponentDirContext do not
487 * have to provide dummy implementations for these.
488 * Override these for subclasses of AtomicDirContext.
489 */
490
491 protected StringHeadTail c_parseComponent(String inputName,
492 Continuation cont) throws NamingException {
493 OperationNotSupportedException e = new
494 OperationNotSupportedException();
495 throw cont.fillInException(e);
496 }
497
498 protected Object a_lookup(String name, Continuation cont)
499 throws NamingException {
500 OperationNotSupportedException e = new
501 OperationNotSupportedException();
502 throw cont.fillInException(e);
503 }
504
505 protected Object a_lookupLink(String name, Continuation cont)
506 throws NamingException {
507 OperationNotSupportedException e = new
508 OperationNotSupportedException();
509 throw cont.fillInException(e);
510 }
511
512 protected NamingEnumeration a_list(
513 Continuation cont) throws NamingException {
514 OperationNotSupportedException e = new
515 OperationNotSupportedException();
516 throw cont.fillInException(e);
517 }
518
519 protected NamingEnumeration a_listBindings(
520 Continuation cont) throws NamingException {
521 OperationNotSupportedException e = new
522 OperationNotSupportedException();
523 throw cont.fillInException(e);
524 }
525
526 protected void a_bind(String name, Object obj, Continuation cont)
527 throws NamingException {
528 OperationNotSupportedException e = new
529 OperationNotSupportedException();
530 throw cont.fillInException(e);
531 }
532
533 protected void a_rebind(String name, Object obj, Continuation cont)
534 throws NamingException {
535 OperationNotSupportedException e = new
536 OperationNotSupportedException();
537 throw cont.fillInException(e);
538 }
539
540 protected void a_unbind(String name, Continuation cont)
541 throws NamingException {
542 OperationNotSupportedException e = new
543 OperationNotSupportedException();
544 throw cont.fillInException(e);
545 }
546
547 protected void a_destroySubcontext(String name, Continuation cont)
548 throws NamingException {
549 OperationNotSupportedException e = new
550 OperationNotSupportedException();
551 throw cont.fillInException(e);
552 }
553
554 protected Context a_createSubcontext(String name, Continuation cont)
555 throws NamingException {
556 OperationNotSupportedException e = new
557 OperationNotSupportedException();
558 throw cont.fillInException(e);
559 }
560
561 protected void a_rename(String oldname, Name newname,
562 Continuation cont) throws NamingException {
563 OperationNotSupportedException e = new
564 OperationNotSupportedException();
565 throw cont.fillInException(e);
566 }
567
568 protected NameParser a_getNameParser(Continuation cont)
569 throws NamingException {
570 OperationNotSupportedException e = new
571 OperationNotSupportedException();
572 throw cont.fillInException(e);
573 }
574}