/**
* Set the value on the underlying POJO, unwrapping values as necessary.
*/
public void setDeclaredProperty(int propertyIndex, Object value) {
SDOProperty declaredProperty = (SDOProperty) dataObject.getType().getDeclaredProperties().get(propertyIndex);
DatabaseMapping mapping = this.getJAXBMappingForProperty(declaredProperty);
Object newValue = value;
Object oldValue = mapping.getAttributeAccessor().getAttributeValueFromObject(entity);
if (declaredProperty.getType().isDataType()) {
if (!declaredProperty.isMany()) {
AbstractSession session = ((JAXBContext) jaxbHelperContext.getJAXBContext()).getXMLContext().getSession(entity);
XMLDirectMapping directMapping = (XMLDirectMapping) mapping;
if (directMapping.hasConverter()) {
newValue = directMapping.getConverter().convertDataValueToObjectValue(newValue, session);
} else {
DatabaseField field = mapping.getField();
newValue = session.getDatasourcePlatform().getConversionManager().convertObject(newValue, descriptor.getObjectBuilder().getFieldClassification(field));
}
}
mapping.setAttributeValueInObject(entity, newValue);
} else if (declaredProperty.isMany()) {
// Get a ListWrapper and set it's current elements
ListWrapper listWrapper = (ListWrapper) getDeclaredProperty(propertyIndex);
listWrapper.setCurrentElements((List) newValue);
} else {
// OLD VALUE
if (mapping.isAbstractCompositeObjectMapping()) {
XMLCompositeObjectMapping compositeMapping = (XMLCompositeObjectMapping) mapping;
if (oldValue != null && compositeMapping.getContainerAccessor() != null) {
compositeMapping.getContainerAccessor().setAttributeValueInObject(oldValue, null);
}
}
// NEW VALUE
newValue = jaxbHelperContext.unwrap((DataObject) value);
mapping.getAttributeAccessor().setAttributeValueInObject(entity, newValue);
if (mapping.isAbstractCompositeObjectMapping()) {
XMLCompositeObjectMapping compositeMapping = (XMLCompositeObjectMapping) mapping;
if (value != null && compositeMapping.getContainerAccessor() != null) {
compositeMapping.getContainerAccessor().setAttributeValueInObject(newValue, entity);
}
}