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