/** Returns the URLs contained within an RMI registry reference. */
  private static String[] getURLs(Reference ref) throws NamingException {

    int size = 0; // number of URLs
    String[] urls = new String[ref.size()];

    Enumeration<RefAddr> addrs = ref.getAll();
    while (addrs.hasMoreElements()) {
      RefAddr addr = addrs.nextElement();

      if ((addr instanceof StringRefAddr) && addr.getType().equals(ADDRESS_TYPE)) {

        urls[size++] = (String) addr.getContent();
      }
    }
    if (size == 0) {
      throw (new ConfigurationException("Reference contains no valid addresses"));
    }

    // Trim URL array down to size.
    if (size == ref.size()) {
      return urls;
    }
    String[] urls2 = new String[size];
    System.arraycopy(urls, 0, urls2, 0, size);
    return urls2;
  }
  /** Returns true if argument is an RMI registry reference. */
  private static boolean isRegistryRef(Object obj) {

    if (!(obj instanceof Reference)) {
      return false;
    }
    String thisClassName = RegistryContextFactory.class.getName();
    Reference ref = (Reference) obj;

    return thisClassName.equals(ref.getFactoryClassName());
  }