예제 #1
0
  /**
   * Insert a link to the specified relation at the specified index, and notify the container by
   * calling its connectionsChanged() method. This overrides the base class to allow inside links as
   * well as links at the same level of the hierarchy.
   *
   * <p>The specified index can be any non-negative integer. Any links with indices larger than or
   * equal to the one specified here will henceforth have indices that are larger by one. If the
   * index is larger than the number of existing links (as returned by numLinks()), then empty links
   * are inserted (these will be null elements in the list returned by linkedRelationsList() or in
   * the enumeration returned by linkedRelations()). If the specified relation is null, then an
   * empty outside link is inserted at the specified index.
   *
   * <p>Note that a port may be linked to the same relation more than once, in which case the link
   * will be reported more than once by the linkedRelations() method.
   *
   * <p>In derived classes, the relation may be required to be an instance of a particular subclass
   * of Relation (this is checked by the _checkLink() protected method).
   *
   * <p>This method is write-synchronized on the workspace and increments its version number.
   *
   * @param index The index at which to insert the link.
   * @param relation The relation to link to this port.
   * @exception IllegalActionException If the link would cross levels of the hierarchy, or the
   *     relation is incompatible, or the port has no container, or the port is not in the same
   *     workspace as the relation.
   */
  @Override
  public void insertLink(int index, Relation relation) throws IllegalActionException {
    if (relation != null && _workspace != relation.workspace()) {
      throw new IllegalActionException(
          this, relation, "Cannot link because workspaces are different.");
    }

    try {
      _workspace.getWriteAccess();

      if (relation == null) {
        // Assume outside link
        _relationsList.insertLink(index, null);
      } else {
        _checkLink(relation);

        if (_isInsideLinkable(relation.getContainer())) {
          // An inside link
          _insideLinks.insertLink(index, relation._linkList);
        } else {
          // An outside link
          _relationsList.insertLink(index, relation._linkList);
        }
      }

      // NOTE: _checkLink() ensures that the container is
      // not null, and the class ensures that it is an Entity.
      ((Entity) getContainer()).connectionsChanged(this);
    } finally {
      _workspace.doneWriting();
    }
  }
예제 #2
0
  /**
   * Link this port with the specified relation. Note that a port may be linked to the same relation
   * more than once, in which case the link will be reported more than once by the linkedRelations()
   * method. If the argument is null, then create a null link (on the outside). This method is
   * write-synchronized on the workspace and increments its version number.
   *
   * @param relation The relation to link to.
   * @exception IllegalActionException If the link crosses levels of the hierarchy, or the port has
   *     no container, or the relation is not a ComponentRelation, or if the port is contained by a
   *     class definition.
   */
  public void link(Relation relation) throws IllegalActionException {
    if (relation != null) {
      _checkLink(relation);
    }

    _doLink(relation);
  }