Object destinationTarget = destinationSource != null ? detach(
destinationSource,
property.getTargetDescriptor(),
child) : null;
ToOneProperty targetProperty = (ToOneProperty) targetDescriptor
.getProperty(property.getName());
Object oldTarget = targetProperty.isFault(target)
? null
: targetProperty.readProperty(target);
targetProperty
.writeProperty(target, oldTarget, destinationTarget);
}
}
return true;
}
public boolean visitToMany(ToManyProperty property) {
if (prefetchTree != null) {
PrefetchTreeNode child = prefetchTree.getNode(property.getName());
if (child != null) {
Object value = property.readProperty(source);
Object targetValue;
if (property instanceof ToManyMapProperty) {
Map<?, ?> map = (Map) value;
Map targetMap = new HashMap();
for (Entry entry : map.entrySet()) {
Object destinationSource = entry.getValue();
Object destinationTarget = destinationSource != null
? detach(destinationSource, property
.getTargetDescriptor(), child)
: null;
targetMap.put(entry.getKey(), destinationTarget);
}
targetValue = targetMap;
}
else {
Collection collection = (Collection) value;
Collection targetCollection = new ArrayList(collection.size());
for (Object destinationSource : collection) {
Object destinationTarget = destinationSource != null
? detach(destinationSource, property
.getTargetDescriptor(), child)
: null;
targetCollection.add(destinationTarget);
}
targetValue = targetCollection;
}
ToManyProperty targetProperty = (ToManyProperty) targetDescriptor
.getProperty(property.getName());
targetProperty.writeProperty(target, null, targetValue);
}
}
return true;
}
public boolean visitAttribute(AttributeProperty property) {
PropertyDescriptor targetProperty = targetDescriptor
.getProperty(property.getName());
targetProperty.writeProperty(target, null, property.readProperty(source));
return true;
}
});
return target;