Example #1
0
  /**
   * This method returns true if this category directly contains a {@link
   * arlut.csd.ganymede.rmi.CategoryNode CategoryNode} with name <name>
   */
  public synchronized boolean contains(String name) {
    for (CategoryNode node : contents) {
      try {
        if (node.getName().equals(name)) {
          return true;
        }
      } catch (RemoteException ex) {
        throw new RuntimeException("caught remote: " + ex);
      }
    }

    return false;
  }
Example #2
0
  /**
   * Returns a subcategory of name <name>.
   *
   * @see arlut.csd.ganymede.rmi.Category
   */
  public CategoryNode getNode(String name) {
    for (CategoryNode candidate : contents) {
      try {
        if (candidate.getName().equals(name)) {
          return candidate;
        }
      } catch (RemoteException ex) {
        throw new RuntimeException("caught remote: " + ex);
      }
    }

    return null;
  }
Example #3
0
  /**
   * This method is used to remove a Category Node from under us.
   *
   * @see arlut.csd.ganymede.rmi.Category
   */
  public synchronized void removeNode(CategoryNode node) throws RemoteException {
    int i, index = -1;

    /* -- */

    if (node == null) {
      throw new IllegalArgumentException("Can't remove a null node");
    }

    // find our deletion point

    if (debug) {
      try {
        Ganymede.debug("DBBaseCategory (" + getName() + ").removeNode(" + node.getPath() + ")");
      } catch (RemoteException ex) {
        Ganymede.logError(ex);
        throw new RuntimeException("rmi local failure?" + ex.getMessage());
      }
    }

    for (i = 0; i < contents.size(); i++) {
      if (debug) {
        try {
          Ganymede.debug(" examining: " + ((CategoryNode) contents.elementAt(i)).getPath());
        } catch (RemoteException ex) {
          Ganymede.logError(ex);
          throw new RuntimeException("rmi local failure?" + ex.getMessage());
        }
      }

      if (contents.elementAt(i).equals(node)) {
        index = i;
      }
    }

    if (index == -1) {
      throw new IllegalArgumentException("can't delete a node that's not in the category");
    }

    // remove our node from our content list

    contents.removeElementAt(index);

    if (false) {
      if (node instanceof DBObjectBase) {
        DBObjectBase base = (DBObjectBase) node;

        if (!base.isEditing()) {
          System.err.println(
              "DBBaseCategory.removeNode(): " + base.getName() + " has a null editor!");
        } else {
          System.err.println(
              "DBBaseCategory.removeNode(): " + base.getName() + " has a non-null editor!");
        }
      }
    }

    // Sorry, kid, yer on your own now!

    node.setCategory(null);
  }
Example #4
0
  /**
   * This method can be used to move a Category from another Category to this Category, or to move a
   * Category around within this Category.
   *
   * @param catPath the fully specified path of the node to be moved
   * @param prevNodeName the name of the node that the catPath node is to be placed after in this
   *     category, or null if the node is to be placed at the first element of this category
   * @see arlut.csd.ganymede.rmi.Category
   */
  public synchronized void moveCategoryNode(String catPath, String prevNodeName) {
    if (debug) {
      System.err.println("DBBaseCategory.moveCategoryNode(" + catPath + "," + prevNodeName + ")");
    }

    CategoryNode categoryNode;
    DBBaseCategory oldCategory;

    try {
      categoryNode = editor.getCategoryNode(catPath);
      oldCategory = (DBBaseCategory) categoryNode.getCategory();
    } catch (RemoteException ex) {
      Ganymede.logError(ex);
      throw new RuntimeException("wow, surprising remote local exception");
    }

    if (oldCategory == this) {
      if (debug) {
        System.err.println("DBBaseCategory.moveCategoryNode(): moving node within category");
      }

      contents.removeElement(categoryNode);
    } else {
      if (debug) {
        System.err.println(
            "DBBaseCategory.moveCategoryNode(): moving node from "
                + oldCategory.getPath()
                + " to "
                + getPath());
      }

      try {
        oldCategory.removeNode(categoryNode);
      } catch (RemoteException ex) {
        throw new RuntimeException("Local category threw a remote exception.. ? " + ex);
      }
    }

    try {
      categoryNode.setCategory(this);
    } catch (RemoteException ex) {
      throw new RuntimeException("Local category node threw a remote exception.. ? " + ex);
    }

    if (prevNodeName == null) {
      contents.insertElementAt(categoryNode, 0);
    } else {
      for (int i = 0; i < contents.size(); i++) {
        CategoryNode cNode = (CategoryNode) contents.elementAt(i);

        try {
          if (cNode.getName().equals(prevNodeName)) {
            contents.insertElementAt(categoryNode, i + 1);
            return;
          }
        } catch (RemoteException ex) {
        }
      }

      throw new RuntimeException(
          "Couldn't move category node " + catPath + " after non-existent " + prevNodeName);
    }
  }
Example #5
0
  /**
   * This method is used to place a Category Node under us. This method adds a new node into this
   * category, before nextNodeName if nextNodeName is not null, or at the beginning of the category
   * if it is.
   *
   * @param node Node to place under this category
   * @param nextNodeName the name of the node that the new node is to be added before, must not be
   *     path-qualified.
   * @see arlut.csd.ganymede.rmi.Category
   */
  public synchronized void addNodeBefore(CategoryNode node, String nextNodeName) {
    if (node == null) {
      throw new IllegalArgumentException("Can't add a null node, not even before " + nextNodeName);
    }

    if (debug) {
      try {
        System.err.println(
            "DBBaseCategory<"
                + getName()
                + ">.addNodeBefore("
                + node.getPath()
                + ","
                + nextNodeName
                + ")");
      } catch (RemoteException ex) {
        throw new RuntimeException(ex.getMessage());
      }
    }

    // make sure we've got a local reference if we're being given a
    // Base

    if ((node instanceof Base) && !(node instanceof DBObjectBase)) {
      node = getBaseFromBase((Base) node);
    }

    // find our insertion point

    //    if (debug)
    //      {
    //	System.err.println("DBBaseCategory.addNodeBefore(): searching to see if node is already in
    // this category");
    //      }

    for (CategoryNode cNode : contents) {
      try {
        if (cNode.getName().equals(node.getName())) {
          throw new IllegalArgumentException("can't add a node that's already in the category");
        }
      } catch (RemoteException ex) {
        throw new RuntimeException("Couldn't check node name: " + ex);
      }
    }

    // put our node into our content list

    // if nextNodeName is null, we're just going to add this node to
    // the end of our category list.

    if (nextNodeName == null) {
      contents.insertElementAt(node, 0);
    } else {
      for (int i = 0; i < contents.size(); i++) {
        CategoryNode cNode = (CategoryNode) contents.elementAt(i);

        try {
          if (cNode.getName().equals(nextNodeName)) {
            contents.insertElementAt(node, i);
            break;
          }
        } catch (RemoteException ex) {
          throw new RuntimeException(ex.getMessage());
        }
      }
    }

    // tell the node who's its daddy

    try {
      //	if (debug)
      //	  {
      //	    System.err.println("DBBaseCategory.addNodeBefore(): setting category for node");
      //	  }

      node.setCategory(this);
    } catch (RemoteException ex) {
      throw new RuntimeException("caught remote exception " + ex);
    }
  }
Example #6
0
  /**
   * This method is used to remove a Category Node from under us.
   *
   * @see arlut.csd.ganymede.rmi.Category
   */
  public synchronized void removeNode(String name) throws RemoteException {
    int i, index = -1;

    CategoryNode node = null;

    /* -- */

    if (name == null) {
      throw new IllegalArgumentException("Can't remove a null name");
    }

    // find our deletion point

    if (debug) {
      Ganymede.debug("DBBaseCategory (" + getName() + ").removeNode(" + name + ")");
    }

    for (i = 0; i < contents.size() && (index == -1); i++) {
      if (debug) {
        Ganymede.debug(" examining: " + contents.elementAt(i));
      }

      node = (CategoryNode) contents.elementAt(i);

      try {
        if (node.getName().equals(name)) {
          index = i;
        }
      } catch (RemoteException ex) {
        throw new RuntimeException("caught remote: " + ex);
      }
    }

    if (index == -1) {
      throw new IllegalArgumentException("can't delete a name that's not in the category");
    } else if (debug) {
      System.err.println("DBBaseCategory.removeNode(): found node " + node);

      if (node instanceof DBObjectBase) {
        System.err.println("DBBaseCategory.removeNode(): node is DBObjectBase");
      } else if (node instanceof Base) {
        System.err.println("DBBaseCategory.removeNode(): node is Base");
      } else if (node instanceof DBBaseCategory) {
        System.err.println("DBBaseCategory.removeNode(): node is DBBaseCategory");
      } else if (node instanceof Category) {
        System.err.println("DBBaseCategory.removeNode(): node is Category");
      } else {
        System.err.println("DBBaseCategory.removeNode(): node is <unrecognized>");
      }
    }

    // remove our node from our content list

    contents.removeElementAt(index);

    if (debug) {
      if (node instanceof DBObjectBase) {
        DBObjectBase base = (DBObjectBase) node;

        if (!base.isEditing()) {
          System.err.println(
              "DBBaseCategory.removeNode(2): " + base.getName() + " has a null editor!");
        } else {
          System.err.println(
              "DBBaseCategory.removeNode(2): " + base.getName() + " has a non-null editor!");
        }
      }
    }

    // Sorry, kid, yer on your own now!

    node.setCategory(null);
  }