Beispiel #1
0
  /**
   * Return the argument contained by this entity that is return. If there is no such argument,
   * return null. This method is read-synchronized on the workspace.
   *
   * @return the argument return, or null if none exists.
   */
  public Argument getArgumentReturn() {
    try {
      _workspace.getReadAccess();

      Iterator arguments = this.argumentsList().iterator();
      Argument returnValue = null;

      while (arguments.hasNext()) {
        Argument argument = (Argument) arguments.next();

        if ((argument != null) && argument.isReturn()) {
          return argument;
        }
      }

      return returnValue;
    } finally {
      _workspace.doneReading();
    }
  }
Beispiel #2
0
  /**
   * Update the ports to match the arguments. If an Argument has no corresponding port, a Port is
   * added. If a Port does not have a corresponding Argument, then the Port is removed. If a input
   * and/or output nature of a Port does not match the Argument with the same name, then the Port is
   * adjusted.
   *
   * @exception IllegalActionException If there is a problem updating the ports.
   */
  public void updatePorts() throws IllegalActionException {
    Iterator arguments = this.argumentsList().iterator();
    TypedIOPort port;

    while (arguments.hasNext()) {
      Argument argument = (Argument) arguments.next();
      port = (TypedIOPort) this.getPort(argument.getName());

      if (port == null) {
        MoMLChangeRequest request = null;

        try {
          if (argument.isReturn()) {

            request =
                new MoMLChangeRequest(
                    this,
                    this,
                    "<port name=\""
                        + argument.getName()
                        + "\" class=\"ptolemy.actor.TypedIOPort\">\n"
                        + "    <property name=\"output\"/>\n"
                        + "</port>");
          } else if (argument.isInput() && argument.isOutput()) {
            request =
                new MoMLChangeRequest(
                    this,
                    this,
                    "<port name=\""
                        + argument.getName()
                        + "in"
                        + "\" class=\"ptolemy.actor.TypedIOPort\">\n"
                        + "    <property name=\"input\"/>\n"
                        + "</port>\n"
                        + "<port name=\""
                        + argument.getName()
                        + "out"
                        + "\" class=\"ptolemy.actor.TypedIOPort\">\n"
                        + "    <property name=\"output\"/>\n"
                        + "</port>");
          } else {
            request =
                new MoMLChangeRequest(
                    this,
                    this,
                    "<port name=\""
                        + argument.getName()
                        + "\" class=\"ptolemy.actor.TypedIOPort\">\n"
                        + (argument.isInput() ? "    <property name=\"input\"/>\n" : "")
                        + (argument.isOutput() ? "    <property name=\"output\"/>\n" : "")
                        + "</port>");
          }
          request.setUndoable(true);
          requestChange(request);
        } catch (Throwable throwable) {
          throw new IllegalActionException(
              this,
              throwable,
              "MoMLChangeRequest for \""
                  + argument.getName()
                  + "\" failed. Request was:\n"
                  + request);
        }
      } else {
        // We have a preexisting port, synchronized the
        // arguments and the ports.

        if (argument.isReturn()) {
          if (port.isInput()) {
            MoMLChangeRequest request =
                new MoMLChangeRequest(
                    this,
                    this,
                    "<port name=\""
                        + argument.getName()
                        + "\" class=\"ptolemy.actor.TypedIOPort\">\n"
                        + "    <deleteProperty name=\"input\"/>\n"
                        + (port.isOutput() ? "" : "    <property name=\"output\"/>\n")
                        + "</port>");
            request.setUndoable(true);
            requestChange(request);
          }
          if (!port.isOutput()) {
            MoMLChangeRequest request =
                new MoMLChangeRequest(
                    this,
                    this,
                    "<port name=\""
                        + argument.getName()
                        + "\" class=\"ptolemy.actor.TypedIOPort\">\n"
                        + "    <property name=\"output\"/>\n"
                        + "</port>");
            request.setUndoable(true);
            requestChange(request);
          }
        } else /*if (port.isInput() != argument.isInput()
               || port.isOutput() != argument.isOutput())*/ {
          MoMLChangeRequest request =
              new MoMLChangeRequest(
                  this,
                  this,
                  "<port name=\""
                      + argument.getName()
                      + "\" class=\"ptolemy.actor.TypedIOPort\">\n"
                      + (port.isInput()
                          ? (argument.isInput() ? "" : "<deleteProperty name=\"input\"/>\n")
                          : (argument.isInput() ? "<property name=\"input\"/>\n" : ""))
                      + (port.isOutput()
                          ? (argument.isOutput() ? "" : "<deleteProperty name=\"output\"/>\n")
                          : (argument.isOutput() ? "<property name=\"output\"/>\n" : ""))
                      + "</port>");
          request.setUndoable(true);
          requestChange(request);
        }
      }
    }

    // Remove any ports that do not have arguments.
    Iterator ports = portList().iterator();

    while (ports.hasNext()) {
      port = (TypedIOPort) ports.next();
      Argument argument = (Argument) _argumentsList.get(port.getName());
      if (argument == null) {
        MoMLChangeRequest request =
            new MoMLChangeRequest(this, this, "<deletePort name=\"" + port.getName() + "\"/>");
        request.setUndoable(true);
        requestChange(request);
      }
    }
  }
Beispiel #3
0
  /**
   * For each Argument, a port of the same name is created, belonging to this argument.
   *
   * @exception IllegalActionException If there is a problem creating the ports.
   */
  public void createPorts() throws IllegalActionException {
    Iterator arguments = this.argumentsList().iterator();
    TypedIOPort port;

    while (arguments.hasNext()) {
      Argument argument = (Argument) arguments.next();
      port = (TypedIOPort) this.getPort(argument.getName());

      if (port == null) {
        if (argument.isReturn()) {
          try {
            MoMLChangeRequest request =
                new MoMLChangeRequest(
                    this,
                    this,
                    "<port name=\""
                        + argument.getName()
                        + "\" class=\"ptolemy.actor.TypedIOPort\">\n"
                        + "    <property name=\"output\"/>\n"
                        + "</port>");
            request.setUndoable(true);
            requestChange(request);

          } catch (Exception ex) {
            throw new IllegalActionException(
                this,
                ex,
                "Unable to construct port " + "port for argument \"" + argument.getName() + "\"");
          }
        } else if (argument.isInput() && argument.isOutput()) {
          try {
            MoMLChangeRequest request =
                new MoMLChangeRequest(
                    this,
                    this,
                    "<group>\n"
                        + " <port name=\""
                        + argument.getName()
                        + "in"
                        + "\" class=\"ptolemy.actor.TypedIOPort\">\n"
                        + "    <property name=\"input\"/>\n"
                        + " </port>\n"
                        + " <port name=\""
                        + argument.getName()
                        + "out"
                        + "\" class=\"ptolemy.actor.TypedIOPort\">\n"
                        + "    <property name=\"output\"/>\n"
                        + " </port>\n"
                        + "</group>");
            request.setUndoable(true);
            requestChange(request);
          } catch (Exception ex) {
            throw new IllegalActionException(
                this,
                ex,
                "Unable to construct "
                    + "input or output "
                    + "port for argument \""
                    + argument.getName()
                    + "\"");
          }
        } else {
          try {
            MoMLChangeRequest request =
                new MoMLChangeRequest(
                    this,
                    this,
                    "<port name=\""
                        + argument.getName()
                        + "\" class=\"ptolemy.actor.TypedIOPort\">\n"
                        + (argument.isInput() ? "    <property name=\"input\"/>\n" : "")
                        + (argument.isOutput() ? "    <property name=\"output\"/>\n" : "")
                        + "</port>");
            request.setUndoable(true);
            requestChange(request);
          } catch (Exception ex) {
            throw new IllegalActionException(
                this,
                ex,
                "Unable to construct " + "port for argument \"" + argument.getName() + "\"");
          }
        }
      } else {

        // synchronized the arguments and the ports
        if (argument.isReturn()) {
          MoMLChangeRequest request =
              new MoMLChangeRequest(
                  this,
                  this,
                  "<port name=\""
                      + argument.getName()
                      + "\" class=\"ptolemy.actor.TypedIOPort\"\n"
                      + "    <property name=\"output\"/>\n"
                      + "</port>");
          request.setUndoable(true);
          requestChange(request);
        } else {
          MoMLChangeRequest request =
              new MoMLChangeRequest(
                  this,
                  this,
                  "<port name=\""
                      + argument.getName()
                      + "\" class=\"ptolemy.actor.TypedIOPort\"\n"
                      + "    <property name=\"input\"/>\n"
                      + "</port>");
          request.setUndoable(true);
          requestChange(request);
        }
      }
      port = (TypedIOPort) this.getPort(argument.getName());
      if (port != null) {
        port.setTypeEquals(BaseType.GENERAL);
      }
    }
  }