Example #1
0
  /**
   * Add an item to the directory. The names of the objects in the directory are not required to be
   * unique. Only items with no container can be added. Items with a container are still viewed as
   * being within the workspace, but they are not explicitly listed in the directory. Instead, their
   * top-level container is expected to be listed (although this is not enforced). Increment the
   * version number.
   *
   * @param item Item to list in the directory.
   * @exception IllegalActionException If the item has a container, is already in the directory, or
   *     is not in this workspace.
   */
  public synchronized void add(NamedObj item) throws IllegalActionException {
    if (item.workspace() != this) {
      throw new IllegalActionException(
          this, item, "Cannot add an item to the directory of a workspace " + "that it is not in.");
    }

    if (item.getContainer() != null) {
      throw new IllegalActionException(
          this, item, "Cannot add an object with a container to a workspace " + "directory.");
    }

    if (_directory.indexOf(item) >= 0) {
      throw new IllegalActionException(
          this, item, "Object is already listed in the workspace directory.");
    }

    _directory.add(item);
    incrVersion();
  }