NamedObj head = (NamedObj) getSemanticObject(linkHead);
NamedObj tail = (NamedObj) getSemanticObject(linkTail);
if (head instanceof ComponentPort
&& tail instanceof ComponentPort) {
ComponentPort headPort = (ComponentPort) head;
ComponentPort tailPort = (ComponentPort) tail;
NamedObj ptolemyModel = getPtolemyModel();
// Linking two ports with a new relation.
String relationName = ptolemyModel.uniqueName("relation");
// If the context is not the entity that we're editing,
// then we need to set the context correctly.
if (ptolemyModel != container) {
String contextString = "<entity name=\""
+ ptolemyModel.getName(container) + "\">\n";
moml.append(contextString);
failmoml.append(contextString);
}
// Note that we use no class so that we use the container's
// factory method when this gets parsed
moml.append("<relation name=\"" + relationName + "\"/>\n");
moml.append("<link port=\""
+ headPort.getName(ptolemyModel) + "\" relation=\""
+ relationName + "\"/>\n");
moml.append("<link port=\""
+ tailPort.getName(ptolemyModel) + "\" relation=\""
+ relationName + "\"/>\n");
// Record moml so that we can blow away these
// links in case we can't create them
failmoml.append("<unlink port=\""
+ headPort.getName(ptolemyModel) + "\" relation=\""
+ relationName + "\"/>\n");
failmoml.append("<unlink port=\""
+ tailPort.getName(ptolemyModel) + "\" relation=\""
+ relationName + "\"/>\n");
failmoml.append("<deleteRelation name=\"" + relationName
+ "\"/>\n");
// close the context