public Object setEmbeddedModelObject(
Proxy proxy, Object newEmbeddedModelObject) {
PropertyDescriptor descriptor = findPropertyDescriptor(proxy);
PropertyAccessor accessor = descriptor.getPropertyAccessor();
if (accessor == null) {
throw new IllegalStateException("Cannot access property directly");
}
Object modelObject = getModelObject(true);
Object oldEmbeddedObject = accessor.get(modelObject);
// Only do something if the old value and the new value are different.
if (!equals(oldEmbeddedObject, newEmbeddedModelObject)) {
accessor.set(modelObject, newEmbeddedModelObject);
}
return oldEmbeddedObject;
}