if (propertyProcessorsEnabled) {
propertyDescriptor.preprocessSetter(proxy, actualNewProperty);
}
if (propertyDescriptor instanceof IRelationshipEndPropertyDescriptor) {
// It's a relation end
IRelationshipEndPropertyDescriptor reversePropertyDescriptor = ((IRelationshipEndPropertyDescriptor) propertyDescriptor)
.getReverseRelationEnd();
try {
if (propertyDescriptor instanceof IReferencePropertyDescriptor) {
// It's a 'one' relation end
storeReferenceProperty(
(IReferencePropertyDescriptor<?>) propertyDescriptor,
oldProperty, actualNewProperty);
if (reversePropertyDescriptor != null) {
// It is bidirectionnal, so we are going to update the other end.
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());