}
}
int sameNameIndex = 0;
List<ItemState> changes = new ArrayList<ItemState>();
ItemState deleteState = null;
for (int j = 0; j < siblings.size(); j++)
{
NodeData sdata = siblings.get(j);
// calculating same name index
if (sdata.getQPath().getName().getAsString().equals(srcPath.getName().getAsString()))
{
++sameNameIndex;
}
// skeep unchanged
if (sdata.getOrderNumber() == j)
{
continue;
}
NodeData newData = sdata;
// change same name index
if (sdata.getQPath().getName().getAsString().equals(srcPath.getName().getAsString())
&& sdata.getQPath().getIndex() != sameNameIndex)
{
// update with new index
QPath siblingPath =
QPath.makeChildPath(newData.getQPath().makeParentPath(), newData.getQPath().getName(), sameNameIndex);
newData =
new TransientNodeData(siblingPath, newData.getIdentifier(), newData.getPersistedVersion(),
newData.getPrimaryTypeName(), newData.getMixinTypeNames(), j, newData.getParentIdentifier(),
newData.getACL());
}
else
{
newData =
new TransientNodeData(newData.getQPath(), newData.getIdentifier(), newData.getPersistedVersion(),
newData.getPrimaryTypeName(), newData.getMixinTypeNames(), j, newData.getParentIdentifier(),
newData.getACL());
}
/*
* 8.3.7.8 Re-ordering a set of Child Nodes. When an orderBefore(A, B) is
* performed, an implementation must generate a NODE_REMOVED for node A
* and a NODE_ADDED for node A. Note that the paths associated with these
* two events will either differ by the last index number (if the movement
* of A causes it to be re-ordered with respect to its same-name siblings)
* or be identical (if A does not have same-name siblings or if the
* movement of A does not change its order relative to its same-name
* siblings). Additionally, an implementation should generate appropriate
* events reflecting the "shifting" over of the node B and any nodes that
* come after it in the child node ordering. Each such shifted node would
* also produce a NODE_REMOVED and NODE_ADDED event pair with paths
* differing at most by a final index.
*/
if (sdata.getQPath().equals(srcPath))
{
deleteState = new ItemState(sdata, ItemState.DELETED, true, null, false, false);
changes.add(new ItemState(newData, ItemState.UPDATED, true, null, false, true));
}
else
{
ItemState state = ItemState.createUpdatedState(newData);
state.eraseEventFire();
changes.add(state);
}
}
// delete state first
if (deleteState != null)