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);
}
}
}