in src/main/java/org/apache/jackrabbit/ocm/manager/collectionconverter/impl/NTCollectionConverterImpl.java [140:203]
protected void doUpdateCollection(Session session,
Node parentNode,
CollectionDescriptor collectionDescriptor,
ManageableObjects objects) throws RepositoryException {
ClassDescriptor elementClassDescriptor = mapper.getClassDescriptorByClass(
ReflectionUtils.forName(collectionDescriptor.getElementClassName()));
if (objects == null || !elementClassDescriptor.hasIdField()) {
this.deleteCollectionItems(session,
parentNode,
elementClassDescriptor.getJcrType());
}
if (objects == null) {
return;
}
Iterator collectionIterator = objects.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 = collectionDescriptor.getJcrElementName();
if (elementJcrName == null) { // use PathFormat.checkFormat() here?
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();
if (!updatedItems.containsKey(child.getName())) {
child.remove();
}
}
}
}