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
7 */package org.opendaylight.controller.md.sal.dom.store.impl.tree.data;
9 import static com.google.common.base.Preconditions.checkArgument;
11 import org.opendaylight.controller.md.sal.dom.store.impl.tree.DataPreconditionFailedException;
12 import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier;
13 import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier.PathArgument;
14 import org.opendaylight.yangtools.yang.data.api.schema.LeafNode;
15 import org.opendaylight.yangtools.yang.data.api.schema.LeafSetEntryNode;
16 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
17 import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
18 import org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode;
19 import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
21 import com.google.common.base.Optional;
22 import com.google.common.primitives.UnsignedLong;
24 abstract class ValueNodeModificationStrategy<T extends DataSchemaNode> extends SchemaAwareApplyOperation {
26 private final T schema;
27 private final Class<? extends NormalizedNode<?, ?>> nodeClass;
29 protected ValueNodeModificationStrategy(final T schema, final Class<? extends NormalizedNode<?, ?>> nodeClass) {
32 this.nodeClass = nodeClass;
36 protected void verifyWrittenStructure(final NormalizedNode<?, ?> writtenValue) {
37 checkArgument(nodeClass.isInstance(writtenValue), "Node should must be of type %s", nodeClass);
41 public Optional<ModificationApplyOperation> getChild(final PathArgument child) {
42 throw new UnsupportedOperationException("Node " + schema.getPath()
43 + "is leaf type node. Child nodes not allowed");
47 protected StoreMetadataNode applySubtreeChange(final NodeModification modification,
48 final StoreMetadataNode currentMeta, final UnsignedLong subtreeVersion) {
49 throw new UnsupportedOperationException("Node " + schema.getPath()
50 + "is leaf type node. Subtree change is not allowed.");
54 protected StoreMetadataNode applyMerge(final NodeModification modification, final StoreMetadataNode currentMeta,
55 final UnsignedLong subtreeVersion) {
56 return applyWrite(modification, Optional.of(currentMeta), subtreeVersion);
60 protected StoreMetadataNode applyWrite(final NodeModification modification,
61 final Optional<StoreMetadataNode> currentMeta, final UnsignedLong subtreeVersion) {
62 return StoreMetadataNode.builder(subtreeVersion).setSubtreeVersion(subtreeVersion)
63 .setData(modification.getWrittenValue()).build();
67 protected void checkSubtreeModificationApplicable(final InstanceIdentifier path,final NodeModification modification,
68 final Optional<StoreMetadataNode> current) throws DataPreconditionFailedException {
69 throw new DataPreconditionFailedException(path, "Subtree modification is not allowed.");
72 public static class LeafSetEntryModificationStrategy extends ValueNodeModificationStrategy<LeafListSchemaNode> {
73 @SuppressWarnings({ "unchecked", "rawtypes" })
74 protected LeafSetEntryModificationStrategy(final LeafListSchemaNode schema) {
75 super(schema, (Class) LeafSetEntryNode.class);
79 public static class LeafModificationStrategy extends ValueNodeModificationStrategy<LeafSchemaNode> {
80 @SuppressWarnings({ "unchecked", "rawtypes" })
81 protected LeafModificationStrategy(final LeafSchemaNode schema) {
82 super(schema, (Class) LeafNode.class);