while (iter.hasNext())
{
RelationChange change = (RelationChange)iter.next();
if (change.type == ChangeType.ADD_OBJECT)
{
StateManager sm = om.findStateManager(change.value);
if (sm != null)
{
// make sure the link to the owner is now set
AbstractMemberMetaData relatedMmd = mmd.getRelatedMemberMetaData(clr)[0];
if (sm.isFieldLoaded(relatedMmd.getAbsoluteFieldNumber()))
{
Object currentVal = sm.provideField(relatedMmd.getAbsoluteFieldNumber());
if (currentVal != ownerSM.getObject())
{
sm.replaceFieldValue(relatedMmd.getAbsoluteFieldNumber(), ownerSM.getObject());
}
}
}
}
else if (change.type == ChangeType.REMOVE_OBJECT)
{
StateManager sm = om.findStateManager(change.value);
if (sm != null)
{
// make sure the link back to the owner is not still set
AbstractMemberMetaData relatedMmd = mmd.getRelatedMemberMetaData(clr)[0];
if (sm.isFieldLoaded(relatedMmd.getAbsoluteFieldNumber()))
{
Object currentVal = sm.provideField(relatedMmd.getAbsoluteFieldNumber());
if (currentVal == ownerSM.getObject())
{
sm.replaceFieldValue(relatedMmd.getAbsoluteFieldNumber(), null);
}
}
}
}
}