protected void doUpdateCollection(Session session,
Node parentNode,
CollectionDescriptor collectionDescriptor,
ManageableCollection collection) throws RepositoryException {
ClassDescriptor elementClassDescriptor = mapper.getClassDescriptorByClass(
ReflectionUtils.forName(collectionDescriptor.getElementClassName()));
if (collection == null || !elementClassDescriptor.hasIdField()) {
this.deleteCollectionItems(session,
parentNode,
elementClassDescriptor.getJcrType());
}
if (collection == null) {
return;
}
Iterator collectionIterator = collection.getIterator();
Map updatedItems = new HashMap();
while (collectionIterator.hasNext()) {
Object item = collectionIterator.next();
String elementJcrName = null;
if (elementClassDescriptor.hasIdField()) {
String idFieldName = elementClassDescriptor.getIdFieldDescriptor().getFieldName();
elementJcrName = ReflectionUtils.getNestedProperty(item, idFieldName).toString();
// Update existing JCR Nodes
if (parentNode.hasNode(elementJcrName)) {
objectConverter.update(session, parentNode, elementJcrName, item);
}
else {
// Add new collection elements
objectConverter.insert(session, parentNode, elementJcrName, item);
}
updatedItems.put(elementJcrName, item);
}
else {
elementJcrName = COLLECTION_ELEMENT_NAME;
objectConverter.insert(session, parentNode, elementJcrName, item);
}
}
// Delete JCR nodes that are not present in the collection
NodeIterator nodes = this.getCollectionNodes(session, parentNode,
elementClassDescriptor.getJcrType());
if (nodes != null && elementClassDescriptor.hasIdField()) {
while (nodes.hasNext()) {
Node child = (Node) nodes.next();