BUG-868: migrate InstanceIdentifer.builder() users
[controller.git] / opendaylight / md-sal / sal-dom-broker / src / main / java / org / opendaylight / controller / md / sal / dom / store / impl / tree / data / 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.controller.md.sal.dom.store.impl.tree.data;
9
10 import org.opendaylight.controller.md.sal.dom.store.impl.tree.DataPreconditionFailedException;
11 import org.opendaylight.controller.md.sal.dom.store.impl.tree.StoreTreeNode;
12 import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier;
13 import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier.PathArgument;
14
15 import com.google.common.base.Optional;
16 import com.google.common.primitives.UnsignedLong;
17
18 /**
19  *
20  * Operation responsible for applying {@link NodeModification} on tree.
21  *
22  * Operation is composite - operation on top level node consists of
23  * suboperations on child nodes. This allows to walk operation hierarchy and
24  * invoke suboperations independently.
25  *
26  * <b>Implementation notes</b>
27  * <ul>
28  * <li>
29  * Implementations MUST expose all nested suboperations which operates on child
30  * nodes expose via {@link #getChild(PathArgument)} method.
31  * <li>Same suboperations SHOULD be used when invoked via
32  * {@link #apply(NodeModification, Optional)} if applicable.
33  *
34  *
35  * Hierarchical composite operation which is responsible for applying
36  * modification on particular subtree and creating updated subtree
37  *
38  *
39  */
40 interface ModificationApplyOperation extends StoreTreeNode<ModificationApplyOperation> {
41
42     /**
43      *
44      * Implementation of this operation must be stateless and must not change
45      * state of this object.
46      *
47      * @param modification
48      *            NodeModification to be applied
49      * @param storeMeta
50      *            Store Metadata Node on which NodeModification should be
51      *            applied
52      * @param subtreeVersion New subtree version of parent node
53      * @throws IllegalArgumentException
54      *             If it is not possible to apply Operation on provided Metadata
55      *             node
56      * @return new {@link StoreMetadataNode} if operation resulted in updating
57      *         node, {@link Optional#absent()} if {@link NodeModification}
58      *         resulted in deletion of this node.
59      */
60     Optional<StoreMetadataNode> apply(NodeModification modification, Optional<StoreMetadataNode> storeMeta, UnsignedLong subtreeVersion);
61
62     /**
63      *
64      * Performs structural verification of NodeModification, such as writen values / types
65      * uses right structural elements.
66      *
67      * @param modification to be verified.
68      * @throws IllegalArgumentException If provided NodeModification does not adhere to the structure.
69      */
70     void verifyStructure(NodeModification modification) throws IllegalArgumentException;
71
72     /**
73      * Returns a suboperation for specified tree node
74      *
75      * @return Reference to suboperation for specified tree node, {@link Optional#absent()}
76      *    if suboperation is not supported for specified tree node.
77      */
78     @Override
79     Optional<ModificationApplyOperation> getChild(PathArgument child);
80
81     /**
82      *
83      * Checks if provided node modification could be applied to current metadata node.
84      *
85      * @param modification Modification
86      * @param current Metadata Node to which modification should be applied
87      * @return true if modification is applicable
88      *         false if modification is no applicable
89      * @throws DataPreconditionFailedException
90      */
91     void checkApplicable(InstanceIdentifier path, NodeModification modification, Optional<StoreMetadataNode> current) throws DataPreconditionFailedException;
92 }