示例#1
0
  /**
   * Join two names together. These are treated as CompoundNames.
   *
   * @param name a <code>Name</code> value
   * @param prefix a <code>Name</code> value
   * @return a <code>Name</code> value
   * @exception NamingException if an error occurs
   */
  public String composeName(String name, String prefix) throws NamingException {
    if (name == null) throw new NamingException("Name cannot be null");
    if (prefix == null) throw new NamingException("Prefix cannot be null");

    Name compoundName = _parser.parse(prefix);
    compoundName.add(name);
    return compoundName.toString();
  }
示例#2
0
  public void appendRemainingComponent(String name)
  {
    try
      {
	remainingName.add(name);
      }
    catch (InvalidNameException _)
      {
      }
  }
示例#3
0
  /**
   * Get the full name of this Context node by visiting it's ancestors back to root.
   *
   * <p>NOTE: if this Context has a URL namespace then the URL prefix will be missing
   *
   * @return the full name of this Context
   * @exception NamingException if an error occurs
   */
  public String getNameInNamespace() throws NamingException {
    Name name = _parser.parse("");

    NamingContext c = this;
    while (c != null) {
      String str = c.getName();
      if (str != null) name.add(0, str);
      c = (NamingContext) c.getParent();
    }
    return name.toString();
  }
示例#4
0
  public ResolveResult(Object robj, String rcomp)
  {
    if (robj == null || rcomp == null)
      throw new IllegalArgumentException ();
    resolvedObj = robj;
    remainingName = new CompositeName ();
    try
      {
	remainingName.add (rcomp);
      }
    catch (InvalidNameException _)
      {
      }
  }
  protected Name stripProtocol(Name name) throws NamingException {
    if ((name != null) && (name.size() > 0)) {
      String head = name.get(0);

      if (__log.isDebugEnabled()) __log.debug("Head element of name is: " + head);

      if (head.startsWith(URL_PREFIX)) {
        head = head.substring(URL_PREFIX.length());
        name.remove(0);
        if (head.length() > 0) name.add(0, head);

        if (__log.isDebugEnabled()) __log.debug("name modified to " + name.toString());
      }
    }

    return name;
  }
  /**
   * Do a deep listing of the bindings for a context.
   *
   * @param ctx the context containing the name for which to list the bindings
   * @param name the name in the context to list
   * @return map: key is fully qualified name, value is the bound object
   * @throws NamingException
   */
  public static Map flattenBindings(Context ctx, String name) throws NamingException {
    HashMap map = new HashMap();

    // the context representation of name arg
    Context c = (Context) ctx.lookup(name);
    NameParser parser = c.getNameParser("");
    NamingEnumeration enm = ctx.listBindings(name);
    while (enm.hasMore()) {
      Binding b = (Binding) enm.next();

      if (b.getObject() instanceof Context) {
        map.putAll(flattenBindings(c, b.getName()));
      } else {
        Name compoundName = parser.parse(c.getNameInNamespace());
        compoundName.add(b.getName());
        map.put(compoundName.toString(), b.getObject());
      }
    }

    return map;
  }