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 static com.google.common.base.Preconditions.checkArgument;
11 import com.google.common.base.Optional;
12 import com.google.common.base.Preconditions;
13 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
14 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
15 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
16 import org.opendaylight.yangtools.yang.data.api.schema.tree.IncorrectDataStructureException;
17 import org.opendaylight.yangtools.yang.data.api.schema.tree.ModificationType;
18 import org.opendaylight.yangtools.yang.data.api.schema.tree.spi.TreeNode;
19 import org.opendaylight.yangtools.yang.data.api.schema.tree.spi.TreeNodeFactory;
20 import org.opendaylight.yangtools.yang.data.api.schema.tree.spi.Version;
21 import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
23 abstract class AbstractValueNodeModificationStrategy<T extends DataSchemaNode> extends SchemaAwareApplyOperation {
24 private final Class<? extends NormalizedNode<?, ?>> nodeClass;
25 private final T schema;
27 protected AbstractValueNodeModificationStrategy(final T schema, final Class<? extends NormalizedNode<?, ?>> nodeClass) {
28 this.nodeClass = Preconditions.checkNotNull(nodeClass);
33 protected final void verifyWrittenStructure(final NormalizedNode<?, ?> writtenValue) {
34 checkArgument(nodeClass.isInstance(writtenValue), "Node should must be of type %s", nodeClass);
38 public final Optional<ModificationApplyOperation> getChild(final PathArgument child) {
39 throw new UnsupportedOperationException("Node " + schema.getPath()
40 + "is leaf type node. Child nodes not allowed");
44 protected final ChildTrackingPolicy getChildPolicy() {
45 return ChildTrackingPolicy.NONE;
49 protected final TreeNode applyTouch(final ModifiedNode modification,
50 final TreeNode currentMeta, final Version version) {
51 throw new UnsupportedOperationException("Node " + schema.getPath()
52 + "is leaf type node. Subtree change is not allowed.");
56 protected final TreeNode applyMerge(final ModifiedNode modification, final TreeNode currentMeta,
57 final Version version) {
58 // Just overwrite whatever was there
59 modification.resolveModificationType(ModificationType.WRITE);
60 return applyWrite(modification, null, version);
64 protected final TreeNode applyWrite(final ModifiedNode modification,
65 final Optional<TreeNode> currentMeta, final Version version) {
66 return TreeNodeFactory.createTreeNode(modification.getWrittenValue(), version);
70 protected final void checkTouchApplicable(final YangInstanceIdentifier path, final NodeModification modification,
71 final Optional<TreeNode> current) throws IncorrectDataStructureException {
72 throw new IncorrectDataStructureException(path, "Subtree modification is not allowed.");