Exemplo n.º 1
0
  /**
   * Resolves to penultimate context named by 'name'. Returns true if penultimate context has been
   * reached (i.e. name only has one atomic component left). Returns false otherwise, and sets
   * Continuation to parts of name not yet resolved.
   */
  protected boolean resolve_to_penultimate_context(Name name, Continuation cont)
      throws NamingException {
    String target = name.toString();

    if (debug > 0) System.out.println("RESOLVE TO PENULTIMATE" + target);

    StringHeadTail ht = c_parseComponent(target, cont);
    String tail = ht.getTail();
    String head = ht.getHead();
    if (head == null) {
      // something is wrong; no name at all
      InvalidNameException e = new InvalidNameException();
      throw cont.fillInException(e);
    }

    if (!isEmpty(tail)) {
      // more components; hence not at penultimate context yet
      try {
        Object headCtx = a_lookup(head, cont);
        if (headCtx != null) cont.setContinue(headCtx, head, this, tail);
        else if (cont.isContinue()) cont.appendRemainingComponent(tail);
      } catch (NamingException e) {
        e.appendRemainingComponent(tail);
        throw e;
      }
    } else {
      // already at penultimate context
      cont.setSuccess(); // clear
      return true;
    }
    return false;
  }
Exemplo n.º 2
0
  /**
   * Resolve to context named by 'name'. Returns true if at named context (i.e. 'name' is empty
   * name). Returns false otherwise, and sets Continuation on parts of 'name' not yet resolved.
   */
  protected boolean resolve_to_context(Name name, Continuation cont) throws NamingException {
    String target = name.toString();

    StringHeadTail ht = c_parseComponent(target, cont);
    String tail = ht.getTail();
    String head = ht.getHead();

    if (debug > 0)
      System.out.println("RESOLVE TO CONTEXT(" + target + ") = {" + head + ", " + tail + "}");

    if (head == null) {
      // something is wrong; no name at all
      InvalidNameException e = new InvalidNameException();
      throw cont.fillInException(e);
    }
    if (!isEmpty(head)) {
      // if there is head is a non-empty name
      // this means more resolution to be done
      try {
        Object headCtx = a_lookup(head, cont);
        //              System.out.println("answer " + headCtx);
        if (headCtx != null) cont.setContinue(headCtx, head, this, (tail == null ? "" : tail));
        else if (cont.isContinue()) cont.appendRemainingComponent(tail);
      } catch (NamingException e) {
        e.appendRemainingComponent(tail);
        throw e;
      }
    } else {
      cont.setSuccess(); // clear
      return true;
    }
    return false;
  }
Exemplo n.º 3
0
  /** Resolves to nns associated with 'name' and set Continuation to the result. */
  protected void resolve_to_nns_and_continue(Name name, Continuation cont) throws NamingException {
    if (debug > 0) System.out.println("RESOLVE TO NNS AND CONTINUE" + name.toString());

    if (resolve_to_penultimate_context_nns(name, cont)) {
      Object nns = a_lookup_nns(name.toString(), cont);
      if (nns != null) cont.setContinue(nns, name, this);
    }
  }
Exemplo n.º 4
0
 protected Object c_lookup(Name name, Continuation cont) throws NamingException {
   Object ret = null;
   if (resolve_to_penultimate_context(name, cont)) {
     ret = a_lookup(name.toString(), cont);
     if (ret != null && ret instanceof LinkRef) {
       cont.setContinue(ret, name, this);
       ret = null;
     }
   }
   return ret;
 }
Exemplo n.º 5
0
  /**
   * Resolves the nns for 'name' when the named context is acting as an intermediate context.
   *
   * <p>For a system that supports junctions, this would be equilvalent to a_lookup(name, cont);
   * because for junctions, an intermediate slash simply signifies a syntactic separator.
   *
   * <p>For a system that supports implicit nns, this would be equivalent to a_lookup_nns(name,
   * cont); because for implicit nns, a slash always signifies the implicit nns, regardless of
   * whether it is intermediate or trailing.
   *
   * <p>By default this method supports junctions, and also allows for an implicit nns to be
   * dynamically determined through the use of the "nns" reference (see a_processJunction_nns()).
   * Contexts that implement implicit nns directly should provide an appropriate override.
   */
  protected Object a_resolveIntermediate_nns(String name, Continuation cont)
      throws NamingException {
    try {
      final Object obj = a_lookup(name, cont);

      // Do not append "" to Continuation 'cont' even if set
      // because the intention is to ignore the nns

      //
      if (obj != null && getClass().isInstance(obj)) {
        // If "obj" is in the same type as this object, it must
        // not be a junction. Continue the lookup with "/".

        cont.setContinueNNS(obj, name, this);
        return null;

      } else if (obj != null && !(obj instanceof Context)) {
        // obj is not even a context, so try to find its nns
        // dynamically by constructing a Reference containing obj.
        RefAddr addr =
            new RefAddr("nns") {
              public Object getContent() {
                return obj;
              }

              private static final long serialVersionUID = -3399518522645918499L;
            };
        Reference ref = new Reference("java.lang.Object", addr);

        // Resolved name has trailing slash to indicate nns
        CompositeName resName = new CompositeName();
        resName.add(name);
        resName.add(""); // add trailing slash

        // Set continuation leave it to
        // PartialCompositeContext.getPCContext() to throw CPE.
        // Do not use setContinueNNS() because we've already
        // consumed "/" (i.e., moved it to resName).

        cont.setContinue(ref, resName, this);
        return null;

      } else {
        return obj;
      }

    } catch (NamingException e) {
      e.appendRemainingComponent(""); // add nns back
      throw e;
    }
  }
Exemplo n.º 6
0
 protected Object c_lookup_nns(Name name, Continuation cont) throws NamingException {
   if (_contextType == _ATOMIC) {
     Object ret = null;
     if (resolve_to_penultimate_context_nns(name, cont)) {
       ret = a_lookup_nns(name.toString(), cont);
       if (ret != null && ret instanceof LinkRef) {
         cont.setContinue(ret, name, this);
         ret = null;
       }
     }
     return ret;
   } else {
     return super.c_lookup_nns(name, cont);
   }
 }
Exemplo n.º 7
0
  /**
   * This function is used when implementing a naming system that supports junctions. For example,
   * when the a_list_nns(newobj) method is invoked, that means the caller is attempting to list the
   * the nns context of of this context. For a context that supports junctions, it by default does
   * not have any nns. Consequently, a NameNotFoundException is thrown.
   */
  protected void a_processJunction_nns(Continuation cont) throws NamingException {

    // Construct a new Reference that contains this context.
    RefAddr addr =
        new RefAddr("nns") {
          public Object getContent() {
            return AtomicContext.this;
          }

          private static final long serialVersionUID = 3449785852664978312L;
        };
    Reference ref = new Reference("java.lang.Object", addr);

    // Set continuation leave it to PartialCompositeContext.getPCContext()
    // to throw the exception.
    // Do not use setContinueNNS() because we've are
    // setting relativeResolvedName to "/".
    cont.setContinue(ref, _NNS_NAME, this);
  }