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() {
private OperationWithModification forChild(final PathArgument childId) {
ModificationApplyOperation childOp = applyOperation.getChild(childId).get();
-
- final boolean isOrdered;
- if (childOp instanceof SchemaAwareApplyOperation) {
- isOrdered = ((SchemaAwareApplyOperation) childOp).isOrdered();
- } else {
- isOrdered = true;
- }
-
- ModifiedNode childMod = modification.modifyChild(childId, isOrdered);
+ ModifiedNode childMod = modification.modifyChild(childId, childOp.getChildPolicy());
return from(childOp,childMod);
}