88 * If the name is empty or if the first component is empty,
89 * head is the empty name and tail is the entire name.
90 * (This means that this context does not have any name to work with).
91 * Otherwise, it returns the first component as head, and the rest of
92 * the components as tail.
93 *
94 * Subclass should override this method according its own policies.
95 *
96 * For example, a weakly separated system with dynamic boundary
97 * determination would simply return as head 'name'.
98 * A weakly separated with static boundary
99 * determination would select the components in the front of 'name'
100 * that conform to some syntax rules. (e.g. in X.500 syntax, perhaps
101 * select front components that have a equal sign).
102 * If none conforms, return an empty name.
103 */
104 protected HeadTail p_parseComponent(Name name, Continuation cont)
105 throws NamingException {
106 int separator;
107 // if no name to parse, or if we're already at boundary
108 if (name.isEmpty() || name.get(0).equals("")) {
109 separator = 0;
110 } else {
111 separator = 1;
112 }
113 Name head, tail;
114
115 if (name instanceof CompositeName) {
116 head = name.getPrefix(separator);
117 tail = name.getSuffix(separator);
118 } else {
119 // treat like compound name
120 head = new CompositeName().add(name.toString());
121 tail = null;
122 }
123
124 if (debug > 2) {
125 System.err.println("ORIG: " + name);
126 System.err.println("PREFIX: " + name);
127 System.err.println("SUFFIX: " + null);
128 }
362 * can perform context operation on this name.
363 *
364 * If not, then the first component(s) of 'name' names
365 * an intermediate context. In that case, resolve these components
366 * and set Continuation to be the object named.
367 *
368 * see test cases at bottom of file.
369 */
370
371 protected HeadTail p_resolveIntermediate(Name name, Continuation cont)
372 throws NamingException {
373 int ret = USE_CONTINUATION;
374 cont.setSuccess(); // initialize
375 HeadTail p = p_parseComponent(name, cont);
376 Name tail = p.getTail();
377 Name head = p.getHead();
378
379 if (tail == null || tail.isEmpty()) {
380 //System.out.println("terminal : " + head);
381 ret = TERMINAL_COMPONENT;
382 } else if (!tail.get(0).equals("")) {
383 // tail does not begin with "/"
384 /*
385 if (head.isEmpty()) {
386 // Context could not find name that it can use
387 // illegal syntax error or name not found
388 //System.out.println("nnf exception : " + head);
389 NamingException e = new NameNotFoundException();
390 cont.setError(this, name);
391 throw cont.fillInException(e);
392 } else {
393 */
394 // head is being used as intermediate context,
395 // resolve head and set Continuation with tail
396 try {
397 Object obj = c_resolveIntermediate_nns(head, cont);
398 //System.out.println("resInter : " + head + "=" + obj);
399 if (obj != null)
400 cont.setContinue(obj, head, this, tail);
401 else if (cont.isContinue()) {
402 checkAndAdjustRemainingName(cont.getRemainingName());
451 }
452 }
453 }
454
455 p.setStatus(ret);
456 return p;
457 }
458
459 // When c_resolveIntermediate_nns() or c_lookup_nns() sets up
460 // its continuation, to indicate "nns", it appends an empty
461 // component to the remaining name (e.g. "eng/"). If last
462 // component of remaining name is empty; delete empty component
463 // before appending tail so that composition of the names work
464 // correctly. For example, when merging "eng/" and "c.b.a", we want
465 // the result to be "eng/c.b.a" because the trailing slash in eng
466 // is extraneous. When merging "" and "c.b.a", we want the result
467 // to be "/c.b.a" and so must keep the trailing slash (empty name).
468 void checkAndAdjustRemainingName(Name rname) throws InvalidNameException {
469 int count;
470 if (rname != null && (count=rname.size()) > 1 &&
471 rname.get(count-1).equals("")) {
472 rname.remove(count-1);
473 }
474 }
475
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)) {
|
88 * If the name is empty or if the first component is empty,
89 * head is the empty name and tail is the entire name.
90 * (This means that this context does not have any name to work with).
91 * Otherwise, it returns the first component as head, and the rest of
92 * the components as tail.
93 *
94 * Subclass should override this method according its own policies.
95 *
96 * For example, a weakly separated system with dynamic boundary
97 * determination would simply return as head 'name'.
98 * A weakly separated with static boundary
99 * determination would select the components in the front of 'name'
100 * that conform to some syntax rules. (e.g. in X.500 syntax, perhaps
101 * select front components that have a equal sign).
102 * If none conforms, return an empty name.
103 */
104 protected HeadTail p_parseComponent(Name name, Continuation cont)
105 throws NamingException {
106 int separator;
107 // if no name to parse, or if we're already at boundary
108 if (name.isEmpty() || name.get(0).isEmpty()) {
109 separator = 0;
110 } else {
111 separator = 1;
112 }
113 Name head, tail;
114
115 if (name instanceof CompositeName) {
116 head = name.getPrefix(separator);
117 tail = name.getSuffix(separator);
118 } else {
119 // treat like compound name
120 head = new CompositeName().add(name.toString());
121 tail = null;
122 }
123
124 if (debug > 2) {
125 System.err.println("ORIG: " + name);
126 System.err.println("PREFIX: " + name);
127 System.err.println("SUFFIX: " + null);
128 }
362 * can perform context operation on this name.
363 *
364 * If not, then the first component(s) of 'name' names
365 * an intermediate context. In that case, resolve these components
366 * and set Continuation to be the object named.
367 *
368 * see test cases at bottom of file.
369 */
370
371 protected HeadTail p_resolveIntermediate(Name name, Continuation cont)
372 throws NamingException {
373 int ret = USE_CONTINUATION;
374 cont.setSuccess(); // initialize
375 HeadTail p = p_parseComponent(name, cont);
376 Name tail = p.getTail();
377 Name head = p.getHead();
378
379 if (tail == null || tail.isEmpty()) {
380 //System.out.println("terminal : " + head);
381 ret = TERMINAL_COMPONENT;
382 } else if (!tail.get(0).isEmpty()) {
383 // tail does not begin with "/"
384 /*
385 if (head.isEmpty()) {
386 // Context could not find name that it can use
387 // illegal syntax error or name not found
388 //System.out.println("nnf exception : " + head);
389 NamingException e = new NameNotFoundException();
390 cont.setError(this, name);
391 throw cont.fillInException(e);
392 } else {
393 */
394 // head is being used as intermediate context,
395 // resolve head and set Continuation with tail
396 try {
397 Object obj = c_resolveIntermediate_nns(head, cont);
398 //System.out.println("resInter : " + head + "=" + obj);
399 if (obj != null)
400 cont.setContinue(obj, head, this, tail);
401 else if (cont.isContinue()) {
402 checkAndAdjustRemainingName(cont.getRemainingName());
451 }
452 }
453 }
454
455 p.setStatus(ret);
456 return p;
457 }
458
459 // When c_resolveIntermediate_nns() or c_lookup_nns() sets up
460 // its continuation, to indicate "nns", it appends an empty
461 // component to the remaining name (e.g. "eng/"). If last
462 // component of remaining name is empty; delete empty component
463 // before appending tail so that composition of the names work
464 // correctly. For example, when merging "eng/" and "c.b.a", we want
465 // the result to be "eng/c.b.a" because the trailing slash in eng
466 // is extraneous. When merging "" and "c.b.a", we want the result
467 // to be "/c.b.a" and so must keep the trailing slash (empty name).
468 void checkAndAdjustRemainingName(Name rname) throws InvalidNameException {
469 int count;
470 if (rname != null && (count=rname.size()) > 1 &&
471 rname.get(count-1).isEmpty()) {
472 rname.remove(count-1);
473 }
474 }
475
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).isEmpty()) {
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)) {
|