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