Cleanup use of Guava library
[yangtools.git] / yang / yang-data-impl / src / main / java / org / opendaylight / yangtools / yang / data / impl / schema / tree / ModificationApplyOperation.java
1 /*
2  * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.yangtools.yang.data.impl.schema.tree;
9
10 import java.util.Optional;
11 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
12 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
13 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
14 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataValidationFailedException;
15 import org.opendaylight.yangtools.yang.data.api.schema.tree.StoreTreeNode;
16 import org.opendaylight.yangtools.yang.data.api.schema.tree.spi.TreeNode;
17 import org.opendaylight.yangtools.yang.data.api.schema.tree.spi.Version;
18
19 /**
20  * Operation responsible for applying {@link ModifiedNode} on tree.
21  *
22  * <p>
23  * Operation is composite - operation on top level node consists of
24  * suboperations on child nodes. This allows to walk operation hierarchy and
25  * invoke suboperations independently.
26  *
27  * <p>
28  * <b>Implementation notes</b>
29  * <ul>
30  * <li>
31  * Implementations MUST expose all nested suboperations which operates on child
32  * nodes expose via {@link #getChild(PathArgument)} method.
33  * <li>Same suboperations SHOULD be used when invoked via
34  * {@link #apply(ModifiedNode, Optional, Version)} if applicable.
35  * </ul>
36  *
37  * <p>
38  * Hierarchical composite operation which is responsible for applying
39  * modification on particular subtree and creating updated subtree
40  */
41 abstract class ModificationApplyOperation implements StoreTreeNode<ModificationApplyOperation> {
42     /**
43      * Implementation of this operation must be stateless and must not change state of this object.
44      *
45      * @param modification
46      *            NodeModification to be applied
47      * @param storeMeta
48      *            Store Metadata Node on which NodeModification should be
49      *            applied
50      * @param version New subtree version of parent node
51      * @return new {@link TreeNode} if operation resulted in updating
52      *         node, {@link Optional#absent()} if {@link ModifiedNode}
53      *         resulted in deletion of this node.
54      * @throws IllegalArgumentException
55      *             If it is not possible to apply Operation on provided Metadata
56      *             node
57      */
58     abstract Optional<TreeNode> apply(ModifiedNode modification, Optional<TreeNode> storeMeta, Version version);
59
60     /**
61      * Checks if provided node modification could be applied to current metadata node.
62      *
63      * @param modification Modification
64      * @param current Metadata Node to which modification should be applied
65      * @param version Metadata version
66      * @throws DataValidationFailedException if the modification is not applicable
67      */
68     abstract void checkApplicable(YangInstanceIdentifier path, NodeModification modification,
69             Optional<TreeNode> current, Version version) throws DataValidationFailedException;
70
71     /**
72      * Performs structural verification of NodeModification, such as writen values / types uses
73      * right structural elements.
74      *
75      * @param modification data to be verified.
76      * @param verifyChildren true if structure verification should be run against children.
77      * @throws IllegalArgumentException If provided NodeModification does not adhere to the
78      *         structure.
79      */
80     abstract void verifyStructure(NormalizedNode<?, ?> modification, boolean verifyChildren);
81
82     /**
83      * Return the tracking policy for this node's children.
84      *
85      * @return Tracking policy, may not be null.
86      */
87     abstract ChildTrackingPolicy getChildPolicy();
88
89     /**
90      * Stage a merge operation into a {@link ModifiedNode} such that it will be processed correctly by
91      * {@link #apply(ModifiedNode, Optional, Version)}. This method is the context which is introducing this operation,
92      * and so any overheads are charged to whoever is in control of the access pattern.
93      *
94      * @param modification Original modification node
95      * @param value Value which should be merge into the modification
96      * @param version Data version as carried in the containing {@link InMemoryDataTreeModification}
97      */
98     abstract void mergeIntoModifiedNode(ModifiedNode modification, NormalizedNode<?, ?> value, Version version);
99
100     /**
101      * Returns a suboperation for specified tree node.
102      *
103      * @return Reference to suboperation for specified tree node, {@link Optional#absent()}
104      *         if suboperation is not supported for specified tree node.
105      */
106     @Override
107     public abstract Optional<ModificationApplyOperation> getChild(PathArgument child);
108
109     abstract void recursivelyVerifyStructure(NormalizedNode<?, ?> value);
110 }