{
// "Will somebody please think of the children!!"
// if (wrappedNode.hasCreatedOrRemovedChildren() handleChildNodes(wrappedNode);
//if (wrappedNode.isModified())
//{
OptimisticTreeNode current = (OptimisticTreeNode) wrappedNode.getNode();
boolean updateVersion = false;
if (wrappedNode.isChildrenModified())
{
log.trace("Updating children since node has modified children");
// merge children.
List deltas = wrappedNode.getMergedChildren();
if (trace) log.trace("Applying children deltas to parent node " + current.getFqn());
for (Iterator i = ((Set) deltas.get(0)).iterator(); i.hasNext();)
{
TreeNode child = (TreeNode) i.next();
current.addChild(child.getName(), child);
}
for (Iterator i = ((Set) deltas.get(1)).iterator(); i.hasNext();)
{
TreeNode child = (TreeNode) i.next();
current.removeChild(child.getName());
}
updateVersion = cache.getLockParentForChildInsertRemove();
}
if (wrappedNode.isModified() || wrappedNode.isCreated())
{
cache.notifyNodeModify(wrappedNode.getFqn(), true);
log.trace("Merging data since node is dirty");
Map mergedData = wrappedNode.getMergedData();
current.put(mergedData, true);
updateVersion = true;
cache.notifyNodeModified(wrappedNode.getFqn());
cache.notifyNodeModify(wrappedNode.getFqn(), false);
}
if (updateVersion)
{
if (wrappedNode.isVersioningImplicit())
{
if (trace) log.trace("Versioning is implicit; incrementing.");
if (wrappedNode.getVersion() instanceof DefaultDataVersion)
current.setVersion(((DefaultDataVersion)wrappedNode.getVersion()).increment());
else
log.debug("Even though no explicit version was passed in, node has an external DataVersion impl. Don't know how to increment, not incrementing.");
}
else
{
if (trace) log.trace("Versioning is explicit; not attempting an increment.");
current.setVersion(wrappedNode.getVersion());
}
if (trace) log.trace("Setting version of node from " + wrappedNode.getVersion() + " to " + current.getVersion());
}
else
{
if (trace) log.trace("Version update on " + wrappedNode.getFqn() + " not necessary since the node is not dirty or LockParentForChildInsertRemove is set to false");
cache.notifyNodeVisited(wrappedNode.getFqn());