Cleanup use of Guava library
[yangtools.git] / yang / yang-data-impl / src / main / java / org / opendaylight / yangtools / yang / data / impl / schema / tree / AbstractValueNodeModificationStrategy.java
index 8fdba96aacb0d6faf3ae28ed1420a57be69cd667..f7ff505d3b54ef7e17bbfb1ced44f233acf116fc 100644 (file)
@@ -8,8 +8,9 @@
 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 java.util.Optional;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
@@ -24,13 +25,14 @@ abstract class AbstractValueNodeModificationStrategy<T extends DataSchemaNode> e
     private final Class<? extends NormalizedNode<?, ?>> nodeClass;
     private final T schema;
 
-    protected AbstractValueNodeModificationStrategy(final T schema, final Class<? extends NormalizedNode<?, ?>> nodeClass) {
+    protected AbstractValueNodeModificationStrategy(final T schema,
+            final Class<? extends NormalizedNode<?, ?>> nodeClass) {
         this.nodeClass = Preconditions.checkNotNull(nodeClass);
         this.schema = schema;
     }
 
     @Override
-    protected final void verifyWrittenStructure(final NormalizedNode<?, ?> writtenValue) {
+    protected final void verifyStructure(final NormalizedNode<?, ?> writtenValue, final boolean verifyChildren) {
         checkArgument(nodeClass.isInstance(writtenValue), "Node should must be of type %s", nodeClass);
     }
 
@@ -46,7 +48,7 @@ abstract class AbstractValueNodeModificationStrategy<T extends DataSchemaNode> e
     }
 
     @Override
-    protected final TreeNode applySubtreeChange(final ModifiedNode modification,
+    protected final TreeNode applyTouch(final ModifiedNode modification,
             final TreeNode currentMeta, final Version version) {
         throw new UnsupportedOperationException("Node " + schema.getPath()
                 + "is leaf type node. Subtree change is not allowed.");
@@ -55,7 +57,8 @@ abstract class AbstractValueNodeModificationStrategy<T extends DataSchemaNode> e
     @Override
     protected final TreeNode applyMerge(final ModifiedNode modification, final TreeNode currentMeta,
             final Version version) {
-        // Just overwrite whatever was there
+        // Just overwrite whatever was there, but be sure to run validation
+        verifyStructure(modification.getWrittenValue(), true);
         modification.resolveModificationType(ModificationType.WRITE);
         return applyWrite(modification, null, version);
     }
@@ -63,12 +66,33 @@ abstract class AbstractValueNodeModificationStrategy<T extends DataSchemaNode> e
     @Override
     protected final TreeNode applyWrite(final ModifiedNode modification,
             final Optional<TreeNode> currentMeta, final Version version) {
-        return TreeNodeFactory.createTreeNodeRecursively(modification.getWrittenValue(), version);
+        return TreeNodeFactory.createTreeNode(modification.getWrittenValue(), version);
     }
 
     @Override
-    protected final void checkSubtreeModificationApplicable(final YangInstanceIdentifier path, final NodeModification modification,
-            final Optional<TreeNode> current) throws IncorrectDataStructureException {
+    protected final void checkTouchApplicable(final YangInstanceIdentifier path, final NodeModification modification,
+            final Optional<TreeNode> current, final Version version) throws IncorrectDataStructureException {
         throw new IncorrectDataStructureException(path, "Subtree modification is not allowed.");
     }
-}
\ No newline at end of file
+
+    @Override
+    void mergeIntoModifiedNode(final ModifiedNode node, final NormalizedNode<?, ?> value, final Version version) {
+
+        switch (node.getOperation()) {
+            // Delete performs a data dependency check on existence of the node. Performing a merge
+            // on DELETE means we
+            // are really performing a write.
+            case DELETE:
+            case WRITE:
+                node.write(value);
+                break;
+            default:
+                node.updateValue(LogicalOperation.MERGE, value);
+        }
+    }
+
+    @Override
+    void recursivelyVerifyStructure(final NormalizedNode<?, ?> value) {
+        verifyStructure(value, false);
+    }
+}