NamedObj container = getPtolemyModel();
moml.append(_deleteRelation(container, linkRelation));
// See whether refinement(s) need to be removed.
CompositeEntity master = (CompositeEntity) linkRelation
.getContainer();
// Nothing to do if there is no container.
if (master != null) {
// Remove any referenced refinements that are not also
// referenced by other states.
TypedActor[] refinements = null;
try {
refinements = ((Transition) linkRelation).getRefinement();
} catch (IllegalActionException e) {
// Ignore, no refinement to remove.
}
if (refinements != null) {
for (int i = 0; i < refinements.length; i++) {
TypedActor refinement = refinements[i];
// By default, if no other state or transition refers
// to this refinement, then we will remove it.
boolean removeIt = true;
Iterator states = master.entityList(State.class)
.iterator();
while (removeIt && states.hasNext()) {
State state = (State) states.next();
TypedActor[] stateRefinements = null;
try {
stateRefinements = state.getRefinement();
} catch (IllegalActionException e1) {
// Ignore, no refinement to check.
}
if (stateRefinements == null) {
continue;
}
for (int j = 0; j < stateRefinements.length; j++) {
if (stateRefinements[j] == refinement) {
removeIt = false;
break;
}
}
}
// Next check transitions.
Iterator transitions = master.relationList().iterator();
while (removeIt && transitions.hasNext()) {
Relation transition = (Relation) transitions.next();
if ((transition == linkRelation)