2 * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.yangtools.yang.data.impl.schema.tree;
10 import com.google.common.base.MoreObjects;
11 import com.google.common.base.MoreObjects.ToStringHelper;
12 import java.util.Optional;
13 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
14 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
15 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataValidationFailedException;
16 import org.opendaylight.yangtools.yang.data.api.schema.tree.StoreTreeNode;
17 import org.opendaylight.yangtools.yang.data.api.schema.tree.spi.TreeNode;
18 import org.opendaylight.yangtools.yang.data.api.schema.tree.spi.Version;
21 * Operation responsible for applying {@link ModifiedNode} on tree.
24 * Operation is composite - operation on top level node consists of
25 * suboperations on child nodes. This allows to walk operation hierarchy and
26 * invoke suboperations independently.
29 * <b>Implementation notes</b>
32 * Implementations MUST expose all nested suboperations which operates on child
33 * nodes expose via {@link #getChild(PathArgument)} method.
34 * <li>Same suboperations SHOULD be used when invoked via
35 * {@link #apply(ModifiedNode, Optional, Version)} if applicable.
39 * Hierarchical composite operation which is responsible for applying
40 * modification on particular subtree and creating updated subtree
42 abstract class ModificationApplyOperation implements StoreTreeNode<ModificationApplyOperation> {
44 * Implementation of this operation must be stateless and must not change state of this object.
47 * NodeModification to be applied
49 * Store Metadata Node on which NodeModification should be
51 * @param version New subtree version of parent node
52 * @return new {@link TreeNode} if operation resulted in updating
53 * node, {@link Optional#absent()} if {@link ModifiedNode}
54 * resulted in deletion of this node.
55 * @throws IllegalArgumentException
56 * If it is not possible to apply Operation on provided Metadata
59 abstract Optional<? extends TreeNode> apply(ModifiedNode modification, Optional<? extends TreeNode> storeMeta,
63 * Checks if provided node modification could be applied to current metadata node.
65 * @param path Path to modification
66 * @param modification Modification
67 * @param current Metadata Node to which modification should be applied
68 * @param version Metadata version
69 * @throws DataValidationFailedException if the modification is not applicable
71 abstract void checkApplicable(ModificationPath path, NodeModification modification,
72 Optional<? extends TreeNode> current, Version version) throws DataValidationFailedException;
75 * Performs a quick structural verification of NodeModification, such as written values / types uses right
76 * structural elements.
78 * @param modification data to be verified.
79 * @throws IllegalArgumentException If provided NodeModification does not adhere to the
82 abstract void quickVerifyStructure(NormalizedNode<?, ?> modification);
85 * Performs a full structural verification of NodeModification, such as written values / types uses right
86 * structural elements. Unlike {@link #quickVerifyStructure(NormalizedNode)} this includes recursively checking
89 * @param modification data to be verified.
90 * @throws IllegalArgumentException If provided NodeModification does not adhere to the
93 abstract void fullVerifyStructure(NormalizedNode<?, ?> modification);
96 * Return the tracking policy for this node's children.
98 * @return Tracking policy, may not be null.
100 abstract ChildTrackingPolicy getChildPolicy();
103 * Stage a merge operation into a {@link ModifiedNode} such that it will be processed correctly by
104 * {@link #apply(ModifiedNode, Optional, Version)}. This method is the context which is introducing this operation,
105 * and so any overheads are charged to whoever is in control of the access pattern.
107 * @param modification Original modification node
108 * @param value Value which should be merge into the modification
109 * @param version Data version as carried in the containing {@link InMemoryDataTreeModification}
111 abstract void mergeIntoModifiedNode(ModifiedNode modification, NormalizedNode<?, ?> value, Version version);
114 * Returns a suboperation for specified tree node.
116 * @return Reference to suboperation for specified tree node, {@link Optional#empty()}
117 * if suboperation is not supported for specified tree node.
120 public abstract Optional<ModificationApplyOperation> getChild(PathArgument child);
122 abstract void recursivelyVerifyStructure(NormalizedNode<?, ?> value);
124 abstract ToStringHelper addToStringAttributes(ToStringHelper helper);
127 public final String toString() {
128 return addToStringAttributes(MoreObjects.toStringHelper(this)).toString();