Merge "Bug 2366: Introducing support for statement ANTLR4 parser as defined in RFC602...
[yangtools.git] / yang / yang-data-impl / src / main / java / org / opendaylight / yangtools / yang / data / impl / schema / tree / OperationWithModification.java
index bcf2101ff07d49572d3cbdb8a92cc3e849dbfc45..6d20d385ee194b908f6aa015679324fb5cbd3e39 100644 (file)
@@ -31,13 +31,13 @@ final class OperationWithModification {
         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);
             }
         }
 
@@ -45,8 +45,16 @@ final class OperationWithModification {
     }
 
     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() {
@@ -72,15 +80,7 @@ final class OperationWithModification {
 
     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);
     }