if (change.type == ADD_OBJECT)
{
if (ownerSM.getObjectManager().getApiAdapter().isDeleted(change.value))
{
// The element was added but was then the element object was deleted!
throw new JPOXUserException(LOCALISER.msg("013008",
StringUtils.toJVMIDString(pc), mmd.getName(), StringUtils.toJVMIDString(change.value)));
}
else
{
AbstractMemberMetaData relatedMmd = mmd.getRelatedMemberMetaData(clr)[0];
org.jpox.StateManager newElementSM = om.findStateManager(change.value);
if (newElementSM != null)
{
newElementSM.loadField(relatedMmd.getAbsoluteFieldNumber());
RelationshipManager newElementRelMgr = newElementSM.getRelationshipManager();
if (newElementRelMgr != null && newElementRelMgr.managesField(relatedMmd.getAbsoluteFieldNumber()))
{
// Element has had the owner set, so make sure it is set to this object
Object newValueFieldValue = newElementSM.provideField(relatedMmd.getAbsoluteFieldNumber());
if (newValueFieldValue != pc && newValueFieldValue != null)
{
// The element has a different owner than the PC with this collection
// This catches cases where the user has set the wrong owner, and also
// will catch cases where the user has added it to two collections
throw new JPOXUserException(LOCALISER.msg(
"013009",
StringUtils.toJVMIDString(pc), mmd.getName(),
StringUtils.toJVMIDString(change.value),
StringUtils.toJVMIDString(newValueFieldValue)));
}
}
}
}
}
else if (change.type == REMOVE_OBJECT)
{
if (ownerSM.getObjectManager().getApiAdapter().isDeleted(change.value))
{
// The element was removed and was then the element object was deleted so do nothing
}
else
{
AbstractMemberMetaData relatedMmd = mmd.getRelatedMemberMetaData(clr)[0];
org.jpox.StateManager newElementSM = om.findStateManager(change.value);
if (newElementSM != null)
{
newElementSM.loadField(relatedMmd.getAbsoluteFieldNumber());
RelationshipManager newElementRelMgr = newElementSM.getRelationshipManager();
if (newElementRelMgr != null && newElementRelMgr.managesField(relatedMmd.getAbsoluteFieldNumber()))
{
// Element has had the owner set, so make sure it is not set to this object
Object newValueFieldValue = newElementSM.provideField(relatedMmd.getAbsoluteFieldNumber());
if (newValueFieldValue == pc)
{
// The element was removed from the collection, but was updated to have its owner
// set to the collection owner!
throw new JPOXUserException(LOCALISER.msg(
"013010",
StringUtils.toJVMIDString(pc), mmd.getName(),
StringUtils.toJVMIDString(change.value)));
}
}