Track current path in a stack
[yangtools.git] / yang / yang-data-impl / src / main / java / org / opendaylight / yangtools / yang / data / impl / schema / tree / StructuralContainerModificationStrategy.java
index be35b5aa673402019e2b2210365194577f223c42..6216339d0ae75f0cd2bee2490782938449ff0947 100644 (file)
@@ -7,15 +7,14 @@
  */
 package org.opendaylight.yangtools.yang.data.impl.schema.tree;
 
-import com.google.common.base.Optional;
-import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
+import java.util.Optional;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNodeContainer;
+import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeConfiguration;
 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataValidationFailedException;
 import org.opendaylight.yangtools.yang.data.api.schema.tree.ModificationType;
-import org.opendaylight.yangtools.yang.data.api.schema.tree.TreeType;
 import org.opendaylight.yangtools.yang.data.api.schema.tree.spi.TreeNode;
 import org.opendaylight.yangtools.yang.data.api.schema.tree.spi.TreeNodeFactory;
 import org.opendaylight.yangtools.yang.data.api.schema.tree.spi.Version;
@@ -32,15 +31,17 @@ import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
  */
 final class StructuralContainerModificationStrategy extends ModificationApplyOperation {
     /**
-     * Fake TreeNode version used in {@link #checkApplicable(YangInstanceIdentifier, NodeModification, Optional)}.
+     * Fake TreeNode version used in
+     * {@link #checkApplicable(ModificationPath, NodeModification, Optional, Version)}.
      * It is okay to use a global constant, as the delegate will ignore it anyway. For
      * {@link #apply(ModifiedNode, Optional, Version)} we will use the appropriate version as provided to us.
      */
     private static final Version FAKE_VERSION = Version.initial();
     private final ContainerModificationStrategy delegate;
 
-    StructuralContainerModificationStrategy(final ContainerSchemaNode schemaNode, final TreeType treeType) {
-        this.delegate = new ContainerModificationStrategy(schemaNode, treeType);
+    StructuralContainerModificationStrategy(final ContainerSchemaNode schemaNode,
+        final DataTreeConfiguration treeConfig) {
+        this.delegate = new ContainerModificationStrategy(schemaNode, treeConfig);
     }
 
     private Optional<TreeNode> fakeMeta(final Version version) {
@@ -49,7 +50,8 @@ final class StructuralContainerModificationStrategy extends ModificationApplyOpe
     }
 
     @Override
-    Optional<TreeNode> apply(final ModifiedNode modification, final Optional<TreeNode> storeMeta, final Version version) {
+    Optional<TreeNode> apply(final ModifiedNode modification, final Optional<TreeNode> storeMeta,
+            final Version version) {
         final Optional<TreeNode> ret;
         if (modification.getOperation() == LogicalOperation.TOUCH && !storeMeta.isPresent()) {
             // Container is not present, let's take care of the 'magically appear' part of our job
@@ -82,29 +84,30 @@ final class StructuralContainerModificationStrategy extends ModificationApplyOpe
          */
         if (((NormalizedNodeContainer<?, ?, ?>) ret.get().getData()).getValue().isEmpty()) {
             modification.resolveModificationType(ModificationType.DISAPPEARED);
-            return Optional.absent();
+            return Optional.empty();
         }
 
         return ret;
     }
 
     @Override
-    void checkApplicable(final YangInstanceIdentifier path, final NodeModification modification, final Optional<TreeNode> current) throws DataValidationFailedException {
+    void checkApplicable(final ModificationPath path, final NodeModification modification,
+            final Optional<TreeNode> current, final Version version) throws DataValidationFailedException {
         if (modification.getOperation() == LogicalOperation.TOUCH && !current.isPresent()) {
             // Structural containers are created as needed, so we pretend this container is here
-            delegate.checkApplicable(path, modification, fakeMeta(FAKE_VERSION));
+            delegate.checkApplicable(path, modification, fakeMeta(FAKE_VERSION), version);
         } else {
-            delegate.checkApplicable(path, modification, current);
+            delegate.checkApplicable(path, modification, current, version);
         }
     }
 
     @Override
-    void verifyStructure(final NormalizedNode<?, ?> modification, final boolean verifyChildren) throws IllegalArgumentException {
+    void verifyStructure(final NormalizedNode<?, ?> modification, final boolean verifyChildren) {
         delegate.verifyStructure(modification, verifyChildren);
     }
 
     @Override
-    void recursivelyVerifyStructure(NormalizedNode<?, ?> value) {
+    void recursivelyVerifyStructure(final NormalizedNode<?, ?> value) {
         delegate.recursivelyVerifyStructure(value);
     }
 
@@ -114,7 +117,8 @@ final class StructuralContainerModificationStrategy extends ModificationApplyOpe
     }
 
     @Override
-    void mergeIntoModifiedNode(ModifiedNode modification, NormalizedNode<?, ?> value, Version version) {
+    void mergeIntoModifiedNode(final ModifiedNode modification, final NormalizedNode<?, ?> value,
+            final Version version) {
         delegate.mergeIntoModifiedNode(modification, value, version);
     }