StringBuffer moml = new StringBuffer("<group>\n");
moml.append("<deleteEntity name=\"" + deleteObj.getName(container)
+ "\"/>\n");
CompositeEntity master = (CompositeEntity) deleteObj.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 = ((State) deleteObj).getRefinement();
} catch (IllegalActionException ex) {
// 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();
if (state == deleteObj) {
continue;
}
TypedActor[] stateRefinements = null;
try {
stateRefinements = state.getRefinement();
} catch (IllegalActionException ex) {
// 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 instanceof Transition)) {