+ modificationType + ", childModification=" + children + "]";
}
+ /**
+ * Create a node which will reflect the state of this node, except it will behave as newly-written
+ * value. This is useful only for merge validation.
+ *
+ * @param value Value associated with the node
+ * @return An isolated node. This node should never reach a datatree.
+ */
+ ModifiedNode asNewlyWritten(final NormalizedNode<?, ?> value) {
+ final ModifiedNode ret = new ModifiedNode(getIdentifier(), Optional.<TreeNode>absent(), false);
+ ret.write(value);
+ return ret;
+ }
+
public static ModifiedNode createUnmodified(final TreeNode metadataTree, final boolean isOrdered) {
return new ModifiedNode(metadataTree.getIdentifier(), Optional.of(metadataTree), isOrdered);
}
applyOperation.verifyStructure(modification);
}
- private void mergeImpl(final NormalizedNode<?,?> data) {
+ private void recursiveMerge(final NormalizedNode<?,?> data) {
if (data instanceof NormalizedNodeContainer<?,?,?>) {
@SuppressWarnings({ "rawtypes", "unchecked" })
NormalizedNodeContainer<?,?,NormalizedNode<PathArgument, ?>> dataContainer = (NormalizedNodeContainer) data;
for (NormalizedNode<PathArgument, ?> child : dataContainer.getValue()) {
PathArgument childId = child.getIdentifier();
- forChild(childId).mergeImpl(child);
+ forChild(childId).recursiveMerge(child);
}
}
}
void merge(final NormalizedNode<?, ?> data) {
- mergeImpl(data);
- applyOperation.verifyStructure(modification);
+ /*
+ * A merge operation will end up overwriting parts of the tree, retaining others.
+ * We want to make sure we do not validate the complete resulting structure, but
+ * rather just what was written. In order to do that, we first pretend the data
+ * was written, run verification and then perform the merge -- with the explicit
+ * assumption that adding the newly-validated data with the previously-validated
+ * data will not result in invalid data.
+ */
+ applyOperation.verifyStructure(modification.asNewlyWritten(data));
+ recursiveMerge(data);
}
void delete() {