8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 package com.sun.jndi.toolkit.ctx;
27
28 import java.util.Hashtable;
29
30 import javax.naming.*;
31 import javax.naming.spi.ResolveResult;
32
33 /**
34 * Provides implementation of p_* operations using
35 * c_* operations provided by subclasses.
36 *
37 * Clients: deal only with names for its own naming service. Must
38 * provide implementations for c_* methods, and for p_parseComponent()
39 * and the c_*_nns methods if the defaults are not appropriate.
40 *
41 * @author Rosanna Lee
42 * @author Scott Seligman
43 */
44
45 public abstract class ComponentContext extends PartialCompositeContext {
46 private static int debug = 0;
47
48 protected ComponentContext() {
49 _contextType = _COMPONENT;
50 }
51
52 // ------ Abstract methods whose implementation are provided by subclass
53
54 /* Equivalent methods in Context interface */
55 protected abstract Object c_lookup(Name name, Continuation cont)
56 throws NamingException;
57 protected abstract Object c_lookupLink(Name name, Continuation cont)
58 throws NamingException;
59
60 protected abstract NamingEnumeration c_list(Name name,
61 Continuation cont) throws NamingException;
62 protected abstract NamingEnumeration c_listBindings(Name name,
63 Continuation cont) throws NamingException;
64 protected abstract void c_bind(Name name, Object obj, Continuation cont)
65 throws NamingException;
66 protected abstract void c_rebind(Name name, Object obj, Continuation cont)
67 throws NamingException;
68 protected abstract void c_unbind(Name name, Continuation cont)
69 throws NamingException;
70 protected abstract void c_destroySubcontext(Name name, Continuation cont)
71 throws NamingException;
72 protected abstract Context c_createSubcontext(Name name,
73 Continuation cont) throws NamingException;
74 protected abstract void c_rename(Name oldname, Name newname,
75 Continuation cont) throws NamingException;
76 protected abstract NameParser c_getNameParser(Name name, Continuation cont)
77 throws NamingException;
78
79 // ------ Methods that may need to be overridden by subclass
80
81 /* Parsing method */
82 /**
220 // For naming systems that support implicit nns,
221 // the trailing slash signifies the implicit nns.
222 // For such naming systems, override these c_*_nns methods.
223 //
224 // For naming systems that do not support implicit nns, the
225 // default implementations here throw an exception. See
226 // c_processJunction_nns() for details.
227
228 protected Object c_lookup_nns(Name name, Continuation cont)
229 throws NamingException {
230 c_processJunction_nns(name, cont);
231 return null;
232 }
233
234 protected Object c_lookupLink_nns(Name name, Continuation cont)
235 throws NamingException {
236 c_processJunction_nns(name, cont);
237 return null;
238 }
239
240 protected NamingEnumeration c_list_nns(Name name,
241 Continuation cont) throws NamingException {
242 c_processJunction_nns(name, cont);
243 return null;
244 }
245
246 protected NamingEnumeration c_listBindings_nns(Name name,
247 Continuation cont) throws NamingException {
248 c_processJunction_nns(name, cont);
249 return null;
250 }
251
252 protected void c_bind_nns(Name name, Object obj, Continuation cont)
253 throws NamingException {
254 c_processJunction_nns(name, cont);
255 }
256
257 protected void c_rebind_nns(Name name, Object obj, Continuation cont)
258 throws NamingException {
259 c_processJunction_nns(name, cont);
260 }
261
262 protected void c_unbind_nns(Name name, Continuation cont)
263 throws NamingException {
264 c_processJunction_nns(name, cont);
265 }
266
478 // Returns true if n contains only empty components
479 protected boolean isAllEmpty(Name n) {
480 int count = n.size();
481 for (int i =0; i < count; i++ ) {
482 if (!n.get(i).equals("")) {
483 return false;
484 }
485 }
486 return true;
487 }
488
489
490
491 // ------ implementations of p_ Resolver and Context methods using
492 // ------ corresponding c_ and c_*_nns methods
493
494
495 /* implementation for Resolver method */
496
497 protected ResolveResult p_resolveToClass(Name name,
498 Class contextType,
499 Continuation cont)
500 throws NamingException {
501
502 if (contextType.isInstance(this)) {
503 cont.setSuccess();
504 return (new ResolveResult(this, name));
505 }
506
507 ResolveResult ret = null;
508 HeadTail res = p_resolveIntermediate(name, cont);
509 switch (res.getStatus()) {
510 case TERMINAL_NNS_COMPONENT:
511 Object obj = p_lookup(name, cont);
512 if (!cont.isContinue() && contextType.isInstance(obj)) {
513 ret = new ResolveResult(obj, _EMPTY_NAME);
514 }
515 break;
516
517 case TERMINAL_COMPONENT:
518 cont.setSuccess(); // no contextType found; return null
539 ret = null;
540 }
541 break;
542
543 case TERMINAL_COMPONENT:
544 ret = c_lookup(res.getHead(), cont);
545 if (ret instanceof LinkRef) {
546 cont.setContinue(ret, res.getHead(), this);
547 ret = null;
548 }
549 break;
550
551 default:
552 /* USE_CONTINUATION */
553 /* pcont already set or exception thrown */
554 break;
555 }
556 return ret;
557 }
558
559 protected NamingEnumeration p_list(Name name, Continuation cont)
560 throws NamingException {
561 NamingEnumeration ret = null;
562 HeadTail res = p_resolveIntermediate(name, cont);
563 switch (res.getStatus()) {
564 case TERMINAL_NNS_COMPONENT:
565 if (debug > 0)
566 System.out.println("c_list_nns(" + res.getHead() + ")");
567 ret = c_list_nns(res.getHead(), cont);
568 break;
569
570 case TERMINAL_COMPONENT:
571 if (debug > 0)
572 System.out.println("c_list(" + res.getHead() + ")");
573 ret = c_list(res.getHead(), cont);
574 break;
575
576 default:
577 /* USE_CONTINUATION */
578 /* cont already set or exception thrown */
579 break;
580 }
581 return ret;
582 }
583
584 protected NamingEnumeration p_listBindings(Name name, Continuation cont) throws
585 NamingException {
586 NamingEnumeration ret = null;
587 HeadTail res = p_resolveIntermediate(name, cont);
588 switch (res.getStatus()) {
589 case TERMINAL_NNS_COMPONENT:
590 ret = c_listBindings_nns(res.getHead(), cont);
591 break;
592
593 case TERMINAL_COMPONENT:
594 ret = c_listBindings(res.getHead(), cont);
595 break;
596
597 default:
598 /* USE_CONTINUATION */
599 /* cont already set or exception thrown */
600 break;
601 }
602 return ret;
603 }
604
605 protected void p_bind(Name name, Object obj, Continuation cont) throws
606 NamingException {
|
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 package com.sun.jndi.toolkit.ctx;
27
28 import javax.naming.*;
29 import javax.naming.spi.ResolveResult;
30
31 /**
32 * Provides implementation of p_* operations using
33 * c_* operations provided by subclasses.
34 *
35 * Clients: deal only with names for its own naming service. Must
36 * provide implementations for c_* methods, and for p_parseComponent()
37 * and the c_*_nns methods if the defaults are not appropriate.
38 *
39 * @author Rosanna Lee
40 * @author Scott Seligman
41 */
42
43 public abstract class ComponentContext extends PartialCompositeContext {
44 private static int debug = 0;
45
46 protected ComponentContext() {
47 _contextType = _COMPONENT;
48 }
49
50 // ------ Abstract methods whose implementation are provided by subclass
51
52 /* Equivalent methods in Context interface */
53 protected abstract Object c_lookup(Name name, Continuation cont)
54 throws NamingException;
55 protected abstract Object c_lookupLink(Name name, Continuation cont)
56 throws NamingException;
57
58 protected abstract NamingEnumeration<NameClassPair> c_list(Name name,
59 Continuation cont) throws NamingException;
60 protected abstract NamingEnumeration<Binding> c_listBindings(Name name,
61 Continuation cont) throws NamingException;
62 protected abstract void c_bind(Name name, Object obj, Continuation cont)
63 throws NamingException;
64 protected abstract void c_rebind(Name name, Object obj, Continuation cont)
65 throws NamingException;
66 protected abstract void c_unbind(Name name, Continuation cont)
67 throws NamingException;
68 protected abstract void c_destroySubcontext(Name name, Continuation cont)
69 throws NamingException;
70 protected abstract Context c_createSubcontext(Name name,
71 Continuation cont) throws NamingException;
72 protected abstract void c_rename(Name oldname, Name newname,
73 Continuation cont) throws NamingException;
74 protected abstract NameParser c_getNameParser(Name name, Continuation cont)
75 throws NamingException;
76
77 // ------ Methods that may need to be overridden by subclass
78
79 /* Parsing method */
80 /**
218 // For naming systems that support implicit nns,
219 // the trailing slash signifies the implicit nns.
220 // For such naming systems, override these c_*_nns methods.
221 //
222 // For naming systems that do not support implicit nns, the
223 // default implementations here throw an exception. See
224 // c_processJunction_nns() for details.
225
226 protected Object c_lookup_nns(Name name, Continuation cont)
227 throws NamingException {
228 c_processJunction_nns(name, cont);
229 return null;
230 }
231
232 protected Object c_lookupLink_nns(Name name, Continuation cont)
233 throws NamingException {
234 c_processJunction_nns(name, cont);
235 return null;
236 }
237
238 protected NamingEnumeration<NameClassPair> c_list_nns(Name name,
239 Continuation cont) throws NamingException {
240 c_processJunction_nns(name, cont);
241 return null;
242 }
243
244 protected NamingEnumeration<Binding> c_listBindings_nns(Name name,
245 Continuation cont) throws NamingException {
246 c_processJunction_nns(name, cont);
247 return null;
248 }
249
250 protected void c_bind_nns(Name name, Object obj, Continuation cont)
251 throws NamingException {
252 c_processJunction_nns(name, cont);
253 }
254
255 protected void c_rebind_nns(Name name, Object obj, Continuation cont)
256 throws NamingException {
257 c_processJunction_nns(name, cont);
258 }
259
260 protected void c_unbind_nns(Name name, Continuation cont)
261 throws NamingException {
262 c_processJunction_nns(name, cont);
263 }
264
476 // Returns true if n contains only empty components
477 protected boolean isAllEmpty(Name n) {
478 int count = n.size();
479 for (int i =0; i < count; i++ ) {
480 if (!n.get(i).equals("")) {
481 return false;
482 }
483 }
484 return true;
485 }
486
487
488
489 // ------ implementations of p_ Resolver and Context methods using
490 // ------ corresponding c_ and c_*_nns methods
491
492
493 /* implementation for Resolver method */
494
495 protected ResolveResult p_resolveToClass(Name name,
496 Class<?> contextType,
497 Continuation cont)
498 throws NamingException {
499
500 if (contextType.isInstance(this)) {
501 cont.setSuccess();
502 return (new ResolveResult(this, name));
503 }
504
505 ResolveResult ret = null;
506 HeadTail res = p_resolveIntermediate(name, cont);
507 switch (res.getStatus()) {
508 case TERMINAL_NNS_COMPONENT:
509 Object obj = p_lookup(name, cont);
510 if (!cont.isContinue() && contextType.isInstance(obj)) {
511 ret = new ResolveResult(obj, _EMPTY_NAME);
512 }
513 break;
514
515 case TERMINAL_COMPONENT:
516 cont.setSuccess(); // no contextType found; return null
537 ret = null;
538 }
539 break;
540
541 case TERMINAL_COMPONENT:
542 ret = c_lookup(res.getHead(), cont);
543 if (ret instanceof LinkRef) {
544 cont.setContinue(ret, res.getHead(), this);
545 ret = null;
546 }
547 break;
548
549 default:
550 /* USE_CONTINUATION */
551 /* pcont already set or exception thrown */
552 break;
553 }
554 return ret;
555 }
556
557 protected NamingEnumeration<NameClassPair> p_list(Name name, Continuation cont)
558 throws NamingException {
559 NamingEnumeration<NameClassPair> ret = null;
560 HeadTail res = p_resolveIntermediate(name, cont);
561 switch (res.getStatus()) {
562 case TERMINAL_NNS_COMPONENT:
563 if (debug > 0)
564 System.out.println("c_list_nns(" + res.getHead() + ")");
565 ret = c_list_nns(res.getHead(), cont);
566 break;
567
568 case TERMINAL_COMPONENT:
569 if (debug > 0)
570 System.out.println("c_list(" + res.getHead() + ")");
571 ret = c_list(res.getHead(), cont);
572 break;
573
574 default:
575 /* USE_CONTINUATION */
576 /* cont already set or exception thrown */
577 break;
578 }
579 return ret;
580 }
581
582 protected NamingEnumeration<Binding> p_listBindings(Name name, Continuation cont) throws
583 NamingException {
584 NamingEnumeration<Binding> ret = null;
585 HeadTail res = p_resolveIntermediate(name, cont);
586 switch (res.getStatus()) {
587 case TERMINAL_NNS_COMPONENT:
588 ret = c_listBindings_nns(res.getHead(), cont);
589 break;
590
591 case TERMINAL_COMPONENT:
592 ret = c_listBindings(res.getHead(), cont);
593 break;
594
595 default:
596 /* USE_CONTINUATION */
597 /* cont already set or exception thrown */
598 break;
599 }
600 return ret;
601 }
602
603 protected void p_bind(Name name, Object obj, Continuation cont) throws
604 NamingException {
|