/**
  * Returns the root of the tree. Returns <code>null</code> only if the tree has no nodes.
  *
  * @return the root of the tree
  */
 public Object getRoot() {
   CatalogDirectory rootDir = null, catDir = this;
   while (catDir != null) {
     rootDir = catDir;
     catDir = catDir.getParent();
   }
   return rootDir;
 }
  /** Return an array of catalogs describing the path to the given catalog or catalog directory. */
  public Catalog[] getPath(Catalog cat) {
    if (cat == null) return null;

    List l = new Vector();
    CatalogDirectory dir;
    if (cat instanceof CatalogDirectory) {
      dir = (CatalogDirectory) cat;
    } else {
      dir = cat.getParent();
      l.add(cat);
    }
    while (dir != null) {
      l.add(dir);
      dir = dir.getParent();
    }

    int n = l.size();
    Catalog[] ar = new Catalog[n];
    for (int i = 0; i < n; i++) ar[n - i - 1] = (Catalog) l.get(i);

    return ar;
  }