use of org.eclipse.persistence.mappings.ContainerMapping in project eclipselink by eclipse-ee4j.
the class JAXBValueStore method unsetDeclaredProperty.
/**
* For isMany=false properties set the value to null. For isMany=true set
* the value to an empty container of the appropriate type.
*/
@Override
public void unsetDeclaredProperty(int propertyIndex) {
SDOProperty declaredProperty = (SDOProperty) dataObject.getType().getDeclaredProperties().get(propertyIndex);
Mapping mapping = this.getJAXBMappingForProperty(declaredProperty);
if (declaredProperty.isMany()) {
ContainerMapping containerMapping = (ContainerMapping) mapping;
ContainerPolicy containerPolicy = containerMapping.getContainerPolicy();
// OLD VALUE
if (mapping.isAbstractCompositeCollectionMapping()) {
XMLCompositeCollectionMapping compositeMapping = (XMLCompositeCollectionMapping) mapping;
XMLInverseReferenceMapping inverseReferenceMapping = compositeMapping.getInverseReferenceMapping();
if (inverseReferenceMapping != null && inverseReferenceMapping.getAttributeAccessor() != null) {
Object oldContainer = mapping.getAttributeValueFromObject(entity);
if (oldContainer != null) {
AbstractSession session = ((JAXBContext) jaxbHelperContext.getJAXBContext()).getXMLContext().getSession(entity);
Object iterator = containerPolicy.iteratorFor(oldContainer);
while (containerPolicy.hasNext(iterator)) {
Object oldValue = containerPolicy.next(iterator, session);
inverseReferenceMapping.getAttributeAccessor().setAttributeValueInObject(oldValue, null);
}
}
}
}
// NEW VALUE
Object container = containerPolicy.containerInstance();
mapping.getAttributeAccessor().setAttributeValueInObject(entity, container);
} else {
// OLD VALUE
Object oldValue = mapping.getAttributeAccessor().getAttributeValueFromObject(entity);
if (mapping.isAbstractCompositeObjectMapping()) {
XMLCompositeObjectMapping compositeMapping = (XMLCompositeObjectMapping) mapping;
final XMLInverseReferenceMapping inverseReferenceMapping = compositeMapping.getInverseReferenceMapping();
if (inverseReferenceMapping != null && inverseReferenceMapping.getAttributeAccessor() != null) {
if (oldValue != null) {
inverseReferenceMapping.getAttributeAccessor().setAttributeValueInObject(oldValue, null);
}
}
}
// NEW VALUE
mapping.getAttributeAccessor().setAttributeValueInObject(entity, null);
}
}
Aggregations