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 * An operation responsible for applying {@link ModifiedNode} on tree. The operation is a hierachical composite -
22 * the operation on top level node consists of suboperations on child nodes. This allows to walk operation hierarchy and
23 * invoke suboperations independently.
26 * <b>Implementation notes</b>
28 * <li>Implementations MUST expose all nested suboperations which operates on child nodes expose via
29 * {@link #getChild(PathArgument)} method.</li>
30 * <li>Same suboperations SHOULD be used when invoked via {@link #apply(ModifiedNode, Optional, Version)},
32 * <li>There are exactly two base implementations:
34 * <li>{@link SchemaAwareApplyOperation}, which serves as the base class for stateful mutators -- directly
35 * impacting the layout and transitions of the {@link TreeNode} hierarchy.
36 * <li>{@link AbstractValidation}, which serves as the base class for stateless checks, which work purely on top
37 * of the {@link TreeNode} hierarchy. These are always overlaid on top of some other
38 * {@link ModificationApplyOperation}, ultimately leading to a {@link SchemaAwareApplyOperation}.
40 * This allows baseline invocations from {@link OperationWithModification} to be bimorphic in the first line of
45 abstract class ModificationApplyOperation implements StoreTreeNode<ModificationApplyOperation> {
47 * Implementation of this operation must be stateless and must not change state of this object.
50 * NodeModification to be applied
52 * Store Metadata Node on which NodeModification should be
54 * @param version New subtree version of parent node
55 * @return new {@link TreeNode} if operation resulted in updating
56 * node, {@link Optional#absent()} if {@link ModifiedNode}
57 * resulted in deletion of this node.
58 * @throws IllegalArgumentException
59 * If it is not possible to apply Operation on provided Metadata
62 abstract Optional<? extends TreeNode> apply(ModifiedNode modification, Optional<? extends TreeNode> storeMeta,
66 * Checks if provided node modification could be applied to current metadata node.
68 * @param path Path to modification
69 * @param modification Modification
70 * @param current Metadata Node to which modification should be applied
71 * @param version Metadata version
72 * @throws DataValidationFailedException if the modification is not applicable
74 abstract void checkApplicable(ModificationPath path, NodeModification modification,
75 Optional<? extends TreeNode> current, Version version) throws DataValidationFailedException;
78 * Performs a quick structural verification of NodeModification, such as written values / types uses right
79 * structural elements.
81 * @param modification data to be verified.
82 * @throws IllegalArgumentException If provided NodeModification does not adhere to the
85 abstract void quickVerifyStructure(NormalizedNode<?, ?> modification);
88 * Performs a full structural verification of NodeModification, such as written values / types uses right
89 * structural elements. Unlike {@link #quickVerifyStructure(NormalizedNode)} this includes recursively checking
92 * @param modification data to be verified.
93 * @throws IllegalArgumentException If provided NodeModification does not adhere to the
96 abstract void fullVerifyStructure(NormalizedNode<?, ?> modification);
99 * Return the tracking policy for this node's children.
101 * @return Tracking policy, may not be null.
103 abstract ChildTrackingPolicy getChildPolicy();
106 * Stage a merge operation into a {@link ModifiedNode} such that it will be processed correctly by
107 * {@link #apply(ModifiedNode, Optional, Version)}. This method is the context which is introducing this operation,
108 * and so any overheads are charged to whoever is in control of the access pattern.
110 * @param modification Original modification node
111 * @param value Value which should be merge into the modification
112 * @param version Data version as carried in the containing {@link InMemoryDataTreeModification}
114 abstract void mergeIntoModifiedNode(ModifiedNode modification, NormalizedNode<?, ?> value, Version version);
117 * Returns a suboperation for specified tree node.
119 * @return Reference to suboperation for specified tree node, {@link Optional#empty()}
120 * if suboperation is not supported for specified tree node.
123 public abstract Optional<ModificationApplyOperation> getChild(PathArgument child);
125 abstract void recursivelyVerifyStructure(NormalizedNode<?, ?> value);
127 abstract ToStringHelper addToStringAttributes(ToStringHelper helper);
130 public final String toString() {
131 return addToStringAttributes(MoreObjects.toStringHelper(this)).toString();