synchronized (this) {
try {
workspace().getWriteAccess();
// Entity most recently added.
ComponentEntity entity = null;
// Delete any previously contained entities.
// The strategy here is a bit tricky if this MirrorComposite
// is within a class definition (that is, if it has derived objects).
// The key is that derived objects do not permit deletion (via
// MoML) of contained entities. They cannot because this would
// violate the invariant of classes where derived objects
// always contain the same objects as their parents.
// Thus, if this is derived, we _cannot_ delete contained
// entities. Thus, we should not generate entity removal
// commands.
List priorEntities = entityList();
Iterator priors = priorEntities.iterator();
while (priors.hasNext()) {
ComponentEntity prior = (ComponentEntity) priors
.next();
// If there is at least one more contained object,
// then delete this one.
// NOTE: How do we prevent the user from attempting to
// override the contained object in a subclass?
// It doesn't work to not remove this if the object
// is derived, because then derived objects won't
// track the prototype.
if (priors.hasNext()) {
prior.setContainer(null);
} else {
// The last entity in the entityList is
// the one that we just added.
entity = prior;
}