if (reversePropertyDescriptor instanceof IReferencePropertyDescriptor) {
// It's a one-to-one relationship
if (oldProperty instanceof IEntity) {
entityDetached((IEntity) oldProperty);
}
IAccessor reversePropertyAccessor = accessorFactory
.createPropertyAccessor(reversePropertyDescriptor.getName(),
((IReferencePropertyDescriptor<?>) propertyDescriptor)
.getReferencedDescriptor().getComponentContract());
if (oldProperty != null) {
reversePropertyAccessor.setValue(oldProperty, null);
}
if (actualNewProperty != null) {
reversePropertyAccessor.setValue(actualNewProperty, proxy);
}
} else if (reversePropertyDescriptor instanceof ICollectionPropertyDescriptor) {
// It's a one-to-many relationship
ICollectionAccessor reversePropertyAccessor = accessorFactory
.createCollectionPropertyAccessor(
reversePropertyDescriptor.getName(),
((IReferencePropertyDescriptor<?>) propertyDescriptor)
.getReferencedDescriptor().getComponentContract(),
((ICollectionPropertyDescriptor<?>) reversePropertyDescriptor)
.getCollectionDescriptor().getElementDescriptor()
.getComponentContract());
if (reversePropertyAccessor instanceof IModelDescriptorAware) {
((IModelDescriptorAware) reversePropertyAccessor)
.setModelDescriptor(reversePropertyDescriptor);
}
if (oldProperty != null) {
reversePropertyAccessor.removeFromValue(oldProperty, proxy);
}
if (actualNewProperty != null) {
reversePropertyAccessor.addToValue(actualNewProperty, proxy);
}
}
}
} else if (propertyDescriptor instanceof ICollectionPropertyDescriptor) {
// It's a 'many' relation end