BUG-4295: instantiate MERGE operations lazily
[yangtools.git] / yang / yang-data-impl / src / main / java / org / opendaylight / yangtools / yang / data / impl / schema / tree / ModificationApplyOperation.java
index fd678e61c0b52ed808cb33fd4ecdb99e9c204e6f..933bf9c5704a9f788d0882dd2b1e6d4d06966bd5 100644 (file)
@@ -10,13 +10,13 @@ package org.opendaylight.yangtools.yang.data.impl.schema.tree;
 import com.google.common.base.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;
+import org.opendaylight.yangtools.yang.data.api.schema.tree.DataValidationFailedException;
 import org.opendaylight.yangtools.yang.data.api.schema.tree.StoreTreeNode;
 import org.opendaylight.yangtools.yang.data.api.schema.tree.spi.TreeNode;
 import org.opendaylight.yangtools.yang.data.api.schema.tree.spi.Version;
-import org.opendaylight.yangtools.yang.data.api.schema.tree.DataValidationFailedException;
 
 /**
- *
  * Operation responsible for applying {@link ModifiedNode} on tree.
  *
  * Operation is composite - operation on top level node consists of
@@ -34,11 +34,8 @@ import org.opendaylight.yangtools.yang.data.api.schema.tree.DataValidationFailed
  *
  * Hierarchical composite operation which is responsible for applying
  * modification on particular subtree and creating updated subtree
- *
- *
  */
-interface ModificationApplyOperation extends StoreTreeNode<ModificationApplyOperation> {
-
+abstract class ModificationApplyOperation implements StoreTreeNode<ModificationApplyOperation> {
     /**
      *
      * Implementation of this operation must be stateless and must not change
@@ -57,36 +54,59 @@ interface ModificationApplyOperation extends StoreTreeNode<ModificationApplyOper
      *         node, {@link Optional#absent()} if {@link ModifiedNode}
      *         resulted in deletion of this node.
      */
-    Optional<TreeNode> apply(ModifiedNode modification, Optional<TreeNode> storeMeta, Version version);
+    abstract Optional<TreeNode> apply(ModifiedNode modification, Optional<TreeNode> storeMeta, Version version);
+
+    /**
+    *
+    * Checks if provided node modification could be applied to current metadata node.
+    *
+    * @param modification Modification
+    * @param current Metadata Node to which modification should be applied
+    * @return true if modification is applicable
+    *         false if modification is no applicable
+    * @throws DataValidationFailedException
+    */
+   abstract void checkApplicable(YangInstanceIdentifier path, NodeModification modification, Optional<TreeNode> current) throws DataValidationFailedException;
 
     /**
      *
-     * Performs structural verification of NodeModification, such as writen values / types
-     * uses right structural elements.
+     * Performs structural verification of NodeModification, such as writen values / types uses
+     * right structural elements.
      *
-     * @param modification to be verified.
-     * @throws IllegalArgumentException If provided NodeModification does not adhere to the structure.
+     * @param modification data to be verified.
+     * @param verifyChildren true if structure verification should be run against children.
+     * @throws IllegalArgumentException If provided NodeModification does not adhere to the
+     *         structure.
      */
-    void verifyStructure(ModifiedNode modification) throws IllegalArgumentException;
+    abstract void verifyStructure(NormalizedNode<?, ?> modification, boolean verifyChildren)
+            throws IllegalArgumentException;
 
     /**
-     * Returns a suboperation for specified tree node
+     * Return the tracking policy for this node's children.
      *
-     * @return Reference to suboperation for specified tree node, {@link Optional#absent()}
-     *    if suboperation is not supported for specified tree node.
+     * @return Tracking policy, may not be null.
      */
-    @Override
-    Optional<ModificationApplyOperation> getChild(PathArgument child);
+    abstract ChildTrackingPolicy getChildPolicy();
 
     /**
+     * Stage a merge operation into a {@link ModifiedNode} such that it will be processed correctly by
+     * {@link #apply(ModifiedNode, Optional, Version)}. This method is the context which is introducing this operation,
+     * and so any overheads are charged to whoever is in control of the access pattern.
      *
-     * Checks if provided node modification could be applied to current metadata node.
+     * @param modification Original modification node
+     * @param value Value which should be merge into the modification
+     * @param version Data version as carried in the containing {@link InMemoryDataTreeModification}
+     */
+    abstract void mergeIntoModifiedNode(ModifiedNode modification, NormalizedNode<?, ?> value, Version version);
+
+    /**
+     * Returns a suboperation for specified tree node
      *
-     * @param modification Modification
-     * @param current Metadata Node to which modification should be applied
-     * @return true if modification is applicable
-     *         false if modification is no applicable
-     * @throws DataValidationFailedException
+     * @return Reference to suboperation for specified tree node, {@link Optional#absent()}
+     *    if suboperation is not supported for specified tree node.
      */
-    void checkApplicable(YangInstanceIdentifier path, NodeModification modification, Optional<TreeNode> current) throws DataValidationFailedException;
+    @Override
+    public abstract Optional<ModificationApplyOperation> getChild(PathArgument child);
+
+    abstract void recursivelyVerifyStructure(NormalizedNode<?, ?> value);
 }