log.error(msg);
throw new ItemStateException(msg, e);
}
if (parent != null) {
// check if node has been renamed
ChildNodeEntry moved = null;
for (ChildNodeEntry child : parent.getRemovedChildNodeEntries()) {
if (child.getId().equals(n.getNodeId())) {
// found node re-added with different name
moved = child;
}
}
if (moved != null) {
NodeTypeImpl nodeType = getNodeType(parent, session);
Set<Name> mixins = parent.getMixinTypeNames();
Path newPath = getPath(state.getId(), hmgr);
Path parentPath = getParent(newPath);
Path oldPath;
try {
if (moved.getIndex() == 0) {
oldPath = PathFactoryImpl.getInstance().create(parentPath, moved.getName(), false);
} else {
oldPath = PathFactoryImpl.getInstance().create(
parentPath, moved.getName(), moved.getIndex(), false);
}
} catch (RepositoryException e) {
// should never happen actually
String msg = "Malformed path for item: " + state.getId();
log.error(msg);
throw new ItemStateException(msg, e);
}
events.add(EventState.childNodeRemoved(
parent.getNodeId(), parentPath,
n.getNodeId(), oldPath.getNameElement(),
nodeType.getQName(), mixins, session));
events.add(EventState.childNodeAdded(
parent.getNodeId(), parentPath,
n.getNodeId(), newPath.getNameElement(),
nodeType.getQName(), mixins, session));
events.add(EventState.nodeMoved(
parent.getNodeId(), newPath, n.getNodeId(),
oldPath, nodeType.getQName(), mixins,
session, false));
}
}
}
}
// check if child nodes of modified node state have been reordered
List<ChildNodeEntry> reordered = n.getReorderedChildNodeEntries();
NodeTypeImpl nodeType = getNodeType(n, session);
Set<Name> mixins = n.getMixinTypeNames();
if (reordered.size() > 0) {
// create a node removed and a node added event for every
// reorder
for (ChildNodeEntry child : reordered) {
Path.Element addedElem = getPathElement(child);
Path parentPath = getPath(n.getNodeId(), hmgr);
// get removed index
NodeState overlayed = (NodeState) n.getOverlayedState();
ChildNodeEntry entry = overlayed.getChildNodeEntry(child.getId());
if (entry == null) {
throw new ItemStateException("Unable to retrieve old child index for item: " + child.getId());
}
Path.Element removedElem = getPathElement(entry);