Improve error message when child schema not found
[yangtools.git] / yang / yang-data-impl / src / main / java / org / opendaylight / yangtools / yang / data / impl / schema / tree / AbstractNodeContainerModificationStrategy.java
index 59ed52d04a9d242c3149a006b858233da2f21c13..4a1e598e42bb0a3fefc71387017c09f5ccfabd03 100644 (file)
@@ -8,7 +8,6 @@
 package org.opendaylight.yangtools.yang.data.impl.schema.tree;
 
 import static com.google.common.base.Preconditions.checkArgument;
-
 import com.google.common.base.Optional;
 import com.google.common.base.Preconditions;
 import com.google.common.base.Verify;
@@ -54,12 +53,14 @@ abstract class AbstractNodeContainerModificationStrategy extends SchemaAwareAppl
                     childOp.get().verifyStructure(castedChild, verifyChildren);
                 } else {
                     throw new SchemaValidationFailedException(String.format(
-                            "Child %s is not valid child according to schema.", castedChild.getIdentifier()));
+                            "Node %s is not a valid child of %s according to the schema.",
+                            castedChild.getIdentifier(), container.getIdentifier()));
                 }
             }
         }
     }
 
+    @Override
     protected void recursivelyVerifyStructure(NormalizedNode<?, ?> value) {
         final NormalizedNodeContainer container = (NormalizedNodeContainer) value;
         for (final Object child : container.getValue()) {
@@ -70,7 +71,8 @@ abstract class AbstractNodeContainerModificationStrategy extends SchemaAwareAppl
                 childOp.get().recursivelyVerifyStructure(castedChild);
             } else {
                 throw new SchemaValidationFailedException(
-                        String.format("Child %s is not valid child according to schema.", castedChild.getIdentifier()));
+                        String.format("Node %s is not a valid child of %s according to the schema.",
+                                castedChild.getIdentifier(), container.getIdentifier()));
             }
         }
     }
@@ -161,7 +163,7 @@ abstract class AbstractNodeContainerModificationStrategy extends SchemaAwareAppl
         final Collection<NormalizedNode<?, ?>> children = ((NormalizedNodeContainer) value).getValue();
         for (NormalizedNode<?, ?> c : children) {
             final PathArgument id = c.getIdentifier();
-            modification.modifyChild(id, resolveChildOperation(id).getChildPolicy(), version);
+            modification.modifyChild(id, resolveChildOperation(id), version);
         }
         return applyTouch(modification, currentMeta, version);
     }
@@ -170,7 +172,7 @@ abstract class AbstractNodeContainerModificationStrategy extends SchemaAwareAppl
             final Collection<NormalizedNode<?, ?>> children, final Version version) {
         for (NormalizedNode<?, ?> c : children) {
             final ModificationApplyOperation childOp = resolveChildOperation(c.getIdentifier());
-            final ModifiedNode childNode = modification.modifyChild(c.getIdentifier(), childOp.getChildPolicy(), version);
+            final ModifiedNode childNode = modification.modifyChild(c.getIdentifier(), childOp, version);
             childOp.mergeIntoModifiedNode(childNode, c, version);
         }
     }
@@ -232,16 +234,6 @@ abstract class AbstractNodeContainerModificationStrategy extends SchemaAwareAppl
         throw new IllegalArgumentException("Unsupported operation " + modification.getOperation());
     }
 
-    @SuppressWarnings({"rawtypes", "unchecked"})
-    private NormalizedNode<?, ?> createEmptyValue(NormalizedNode<?, ?> value,
-            Collection<NormalizedNode<?, ?>> children) {
-        NormalizedNodeContainerBuilder builder = createBuilder(value);
-        for (NormalizedNode<?, ?> child : children) {
-            builder.removeChild(child.getIdentifier());
-        }
-        return builder.build();
-    }
-
     @Override
     protected TreeNode applyTouch(final ModifiedNode modification, final TreeNode currentMeta, final Version version) {
         /*
@@ -282,7 +274,7 @@ abstract class AbstractNodeContainerModificationStrategy extends SchemaAwareAppl
 
     @Override
     protected void checkTouchApplicable(final YangInstanceIdentifier path, final NodeModification modification,
-            final Optional<TreeNode> current) throws DataValidationFailedException {
+            final Optional<TreeNode> current, final Version version) throws DataValidationFailedException {
         if (!modification.getOriginal().isPresent() && !current.isPresent()) {
             throw new ModifiedNodeDoesNotExistException(path, String.format("Node %s does not exist. Cannot apply modification to its children.", path));
         }
@@ -291,7 +283,7 @@ abstract class AbstractNodeContainerModificationStrategy extends SchemaAwareAppl
             throw new ConflictingModificationAppliedException(path, "Node was deleted by other transaction.");
         }
 
-        checkChildPreconditions(path, modification, current.get());
+        checkChildPreconditions(path, modification, current.get(), version);
     }
 
     /**
@@ -301,21 +293,22 @@ abstract class AbstractNodeContainerModificationStrategy extends SchemaAwareAppl
      * @param modification current modification
      * @param current Current data tree node.
      */
-    private void checkChildPreconditions(final YangInstanceIdentifier path, final NodeModification modification, final TreeNode current) throws DataValidationFailedException {
+    private void checkChildPreconditions(final YangInstanceIdentifier path, final NodeModification modification,
+            final TreeNode current, final Version version) throws DataValidationFailedException {
         for (final NodeModification childMod : modification.getChildren()) {
             final YangInstanceIdentifier.PathArgument childId = childMod.getIdentifier();
             final Optional<TreeNode> childMeta = current.getChild(childId);
 
             final YangInstanceIdentifier childPath = path.node(childId);
-            resolveChildOperation(childId).checkApplicable(childPath, childMod, childMeta);
+            resolveChildOperation(childId).checkApplicable(childPath, childMod, childMeta, version);
         }
     }
 
     @Override
     protected void checkMergeApplicable(final YangInstanceIdentifier path, final NodeModification modification,
-            final Optional<TreeNode> current) throws DataValidationFailedException {
+            final Optional<TreeNode> current, final Version version) throws DataValidationFailedException {
         if (current.isPresent()) {
-            checkChildPreconditions(path, modification, current.get());
+            checkChildPreconditions(path, modification, current.get(), version);
         }
     }