/**
   * Deeply list the opaque ports connected to this port on the outside. Begin by listing the ports
   * that are connected to this port. If any of those are transparent ports that we are connected to
   * from the inside, then list all the ports deeply connected on the outside to that transparent
   * port. If any are transparent ports that we are connected to from the outside, then list opaque
   * ports deeply inside that port. Note that a port may be listed more than once. The path argument
   * is the path from the port that originally calls this method to this port. If this port is
   * already on the list of ports on the path to this port in deeply traversing the topology, then
   * there is a loop in the topology, and an InvalidStateException is thrown. This method not
   * synchronized on the workspace, so the caller should.
   *
   * @param path The list of ports on the path to this port in deeply traversing the topology.
   * @return An unmodifiable list of ComponentPort objects.
   */
  protected List _deepConnectedPortList(LinkedList path) {
    if (_deepLinkedPortsVersion == _workspace.getVersion()) {
      // Cache is valid.  Use it.
      return _deepLinkedPorts;
    }

    if (path == null) {
      path = new LinkedList();
    } else {
      if (path.indexOf(this) >= 0) {
        throw new InvalidStateException(path, "Loop in topology!");
      }
    }

    path.add(0, this);

    Iterator nearRelations = linkedRelationList().iterator();
    LinkedList result = new LinkedList();

    while (nearRelations.hasNext()) {
      ComponentRelation relation = (ComponentRelation) nearRelations.next();

      // A null link (supported since indexed links) might
      // yield a null relation here. EAL 7/19/00.
      if (relation != null) {
        Iterator connectedPorts = relation.linkedPortList(this).iterator();

        while (connectedPorts.hasNext()) {
          ComponentPort port = (ComponentPort) connectedPorts.next();

          // NOTE: If level-crossing transitions are not allowed,
          // then a simpler test than that of the following
          // would work.
          if (port._isInsideLinkable(relation.getContainer())) {
            // We are coming at the port from the inside.
            if (port.isOpaque()) {
              result.add(port);
            } else {
              // Port is transparent
              result.addAll(port._deepConnectedPortList(path));
            }
          } else {
            // We are coming at the port from the outside.
            if (port.isOpaque()) {
              result.add(port);
            } else {
              // It is transparent.
              result.addAll(port._deepInsidePortList(path));
            }
          }
        }
      }
    }

    _deepLinkedPorts = Collections.unmodifiableList(result);
    _deepLinkedPortsVersion = _workspace.getVersion();
    path.remove(0);
    return _deepLinkedPorts;
  }
Beispiel #2
0
 /**
  * Propagate existence of this object to the specified object. This overrides the base class to
  * set the container.
  *
  * @param container Object to contain the new object.
  * @exception IllegalActionException If the object cannot be cloned.
  * @return A new object of the same class and name as this one.
  */
 protected NamedObj _propagateExistence(NamedObj container) throws IllegalActionException {
   try {
     ComponentRelation newObject = (ComponentRelation) super._propagateExistence(container);
     newObject.setContainer((CompositeEntity) container);
     return newObject;
   } catch (NameDuplicationException e) {
     throw new InternalErrorException(e);
   }
 }
Beispiel #3
0
 /**
  * Clone the object into the specified workspace. The new object is <i>not</i> added to the
  * directory of that workspace (you must do this yourself if you want it there). The result is a
  * new relation with no links and no container.
  *
  * @param workspace The workspace for the cloned object.
  * @exception CloneNotSupportedException If one or more of the attributes cannot be cloned.
  * @return A new ComponentRelation.
  */
 public Object clone(Workspace workspace) throws CloneNotSupportedException {
   ComponentRelation newObject = (ComponentRelation) super.clone(workspace);
   newObject._container = null;
   return newObject;
 }
  /**
   * Write a MoML description of the contents of this object, wrapped in a configure element. This
   * is done by first populating the model, and then exporting its contents into a configure
   * element. This method is called by exportMoML(). Each description is indented according to the
   * specified depth and terminated with a newline character.
   *
   * @param output The output stream to write to.
   * @param depth The depth in the hierarchy, to determine indenting.
   * @exception IOException If an I/O error occurs.
   */
  protected void _exportMoMLContents(Writer output, int depth) throws IOException {
    populate();
    // Export top level attributes and ports

    List _attributes = attributeList();
    String _displayName = getDisplayName();

    // FIXME: start of duplicated code from NamedObj
    // If the display name has been set, then include a display element.
    // Note that copying parameters that have _displayName set need
    // to export _displayName.
    // See: http://bugzilla.ecoinformatics.org/show_bug.cgi?id=3361
    if (!_displayName.equals(getName())) {
      output.write("<display name=\"");
      output.write(StringUtilities.escapeForXML(_displayName));
      output.write("\"/>");
    }

    // Callers of this method should hold read access
    // so as to avoid ConcurrentModificationException.
    if (_attributes != null) {
      // Iterator attributes = _attributes.elementList().iterator();
      Iterator attributes = _attributes.iterator();

      while (attributes.hasNext()) {
        Attribute attribute = (Attribute) attributes.next();
        attribute.exportMoML(output, depth);
      }
    }
    // FIXME: end of duplicated code from NamedObj

    // FIXME: start of duplicated code from Entity
    Iterator ports = portList().iterator();

    while (ports.hasNext()) {
      Port port = (Port) ports.next();
      port.exportMoML(output, depth);
    }
    // FIXME: end of duplicated code from Entity

    // Everything else is in a configure

    output.write(_getIndentPrefix(depth) + "<configure>\n");
    output.write(_getIndentPrefix(depth + 1) + "<group>\n");

    // FIXME: start of duplicated code from CompositeEntity
    Iterator classes = classDefinitionList().iterator();

    while (classes.hasNext()) {
      ComponentEntity entity = (ComponentEntity) classes.next();
      entity.exportMoML(output, depth + 2);
    }

    Iterator entities = entityList().iterator();

    while (entities.hasNext()) {
      ComponentEntity entity = (ComponentEntity) entities.next();
      entity.exportMoML(output, depth + 2);
    }

    Iterator relations = relationList().iterator();

    while (relations.hasNext()) {
      ComponentRelation relation = (ComponentRelation) relations.next();
      relation.exportMoML(output, depth + 2);
    }

    // NOTE: We used to write the links only if
    // this object did not defer to another
    // (getMoMLInfo().deferTo was null), and
    // would instead record links in a MoMLAttribute.
    // That mechanism was far too fragile.
    // EAL 3/10/04
    output.write(exportLinks(depth + 2, null));
    // FIXME: end of duplicated code from CompositeEntity

    output.write(_getIndentPrefix(depth + 1) + "</group>\n");
    output.write(_getIndentPrefix(depth) + "</configure>\n");
  }