}
// Remove the composite entity here because when the objects are
// added back, their names will not conflict with the name of this
// composite entity.
MoMLChangeRequest request = GTTools.getDeletionChangeRequest(this,
object);
request.execute();
_removeReplacementToHostEntries(object);
// Move the entities and relations inside to the outside.
for (Object childObject : preservedChildren) {
NamedObj child = (NamedObj) childObject;
String moml = "<group name=\"auto\">\n"
+ child.exportMoMLPlain() + "</group>";
request = new MoMLChangeRequest(this, container, moml);
request.execute();
NamedObj newlyAddedObject = _getNewlyAddedObject(container,
child.getClass());
_addReplacementToHostEntries(newlyAddedObject);
_replaceMatchResultEntries(child, newlyAddedObject);
entityMap.put(child, newlyAddedObject);
}
// Create new relations for the ports.
for (Map.Entry<Port, List<Object>> entry : portLinks.entrySet()) {
Port port = entry.getKey();
List<Object> linkedRelations = entry.getValue();
int width = 1;
for (Object relationObject : linkedRelations) {
Relation relation = (Relation) relationObject;
Parameter widthParameter = (Parameter) relation
.getAttribute("width");
if (widthParameter != null) {
try {
int thisWidth = ((IntToken) widthParameter
.getToken()).intValue();
if (thisWidth > width) {
width = thisWidth;
}
} catch (IllegalActionException e) {
throw new TransformationException("Cannot get "
+ "width of relation " + relation.getName()
+ ".", e);
}
}
}
String moml = "<group name=\"auto\">"
+ "<relation name=\"relation\" "
+ " class=\"ptolemy.actor.TypedIORelation\">"
+ "</relation>" + "</group>";
request = new MoMLChangeRequest(this, container, moml);
request.execute();
Relation newRelation = (Relation) _getNewlyAddedObject(
container, Relation.class);
entityMap.put(port, newRelation);
}
// Fix the connections between the moved entities and relations.
for (Map.Entry<NamedObj, NamedObj> entry : entityMap.entrySet()) {
NamedObj originalObject = entry.getKey();
NamedObj newObject = entry.getValue();
if (originalObject instanceof Relation
|| originalObject instanceof Port
&& newObject instanceof Relation) {
List<?> linkedObjectList;
if (originalObject instanceof Relation) {
linkedObjectList = ((Relation) originalObject)
.linkedObjectsList();
} else {
linkedObjectList = portLinks.get(originalObject);
}
Relation relation2 = (Relation) newObject;
for (Object linkedObject : linkedObjectList) {
if (linkedObject instanceof Relation) {
Relation relation1 = (Relation) entityMap
.get(linkedObject);
if (relation1 == null) {
relation1 = (Relation) linkedObject;
}
String moml = _getLinkMoML(relation1, relation2);
request = new MoMLChangeRequest(this, container,
moml);
request.execute();
} else if (linkedObject instanceof Port) {
Port originalPort = (Port) linkedObject;
Entity linkedEntity = (Entity) entityMap
.get(originalPort.getContainer());
if (linkedEntity != null) {
Port port1 = linkedEntity.getPort(originalPort
.getName());
String moml = _getLinkMoML(port1, relation2);
request = new MoMLChangeRequest(this,
container, moml);
request.execute();
}
}
}
}
}
return entityMap.values();
} else {
MoMLChangeRequest request = GTTools.getDeletionChangeRequest(this,
object);
request.execute();
return null;
}
}