// We're modifying a reference attribute, so track that puppy
DmcAttribute<?> mod = attr.getNew();
mod.setAttributeInfo(ai);
mod.add(getLastValue());
Modifier backrefMod = new Modifier(ModifyTypeEnum.NTH,mod,this,index);
((DmcObject)((DmcNamedObjectREF<?>)getLastValue()).getObject()).addBackref(backrefMod);
((DmcNamedObjectREF<?>)getLastValue()).setBackrefModifier(backrefMod);
}
}
if (attr instanceof DmcTypeNamedObjectREF){
// And now some tricky stuff. Due to the fact that the nth() mechanisms can
// result in a previous value being removed and replaced in one operation,
// we have to take this into account when tracking back references. Any
// previous value for this index is passed in to us from the generated
// nth() method so that we can clean up the back reference if required.
if (previous != null){
DmcNamedObjectREF<?> ref = (DmcNamedObjectREF<?>) previous;
if (ref.getObject() != null){
if (ref.getBackrefModifier() != null)
((DmcObject)ref.getObject()).removeBackref(ref.getBackrefModifier());
}
}
}
}
}
}
if (getModifier() != null){
if (getLastValue() == null){
// Last value can be null in the case of indexed multi-valued attributes since this
// is how we remove an indexed value.
if ( (ai.indexSize == 0) || (ai.valueType != ValueTypeEnum.MULTI))
throw(new IllegalStateException("Code gen error! The nth() interface is not applicable to attribute: " + ai.name + " of valueType: " + ai.valueType));
getModifier().add(new Modifier(ModifyTypeEnum.NTH, ai, index));
}
else{
// Get an attribute value holder of the same type and hang on to the last
// value that was added to it
DmcAttribute<?> mod = attr.getNew();
mod.setAttributeInfo(ai);
mod.setMVnth(index, getLastValue());
getModifier().add(new Modifier(ModifyTypeEnum.NTH, mod, index));
}
}
// If there are no longer values stored in the attribute, remove it