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.controller.md.sal.dom.store.impl;
10 import org.opendaylight.controller.md.sal.dom.store.impl.tree.ModificationApplyOperation;
11 import org.opendaylight.controller.md.sal.dom.store.impl.tree.data.NodeModification;
12 import org.opendaylight.controller.md.sal.dom.store.impl.tree.data.StoreMetadataNode;
13 import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier.PathArgument;
14 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
16 import com.google.common.base.Optional;
17 import com.google.common.primitives.UnsignedLong;
19 public class OperationWithModification {
21 private final NodeModification modification;
23 private final ModificationApplyOperation applyOperation;
25 private OperationWithModification(final ModificationApplyOperation op, final NodeModification mod) {
26 this.modification = mod;
27 this.applyOperation = op;
30 public OperationWithModification write(final NormalizedNode<?, ?> value) {
31 modification.write(value);
32 applyOperation.verifyStructure(modification);
36 public OperationWithModification delete() {
37 modification.delete();
41 public NodeModification getModification() {
45 public ModificationApplyOperation getApplyOperation() {
46 return applyOperation;
49 public Optional<StoreMetadataNode> apply(final Optional<StoreMetadataNode> data, final UnsignedLong subtreeVersion) {
50 return applyOperation.apply(modification, data, subtreeVersion);
53 public static OperationWithModification from(final ModificationApplyOperation operation,
54 final NodeModification modification) {
55 return new OperationWithModification(operation, modification);
59 public void merge(final NormalizedNode<?, ?> data) {
60 modification.merge(data);
61 applyOperation.verifyStructure(modification);
65 public OperationWithModification forChild(final PathArgument childId) {
66 NodeModification childMod = modification.modifyChild(childId);
67 Optional<ModificationApplyOperation> childOp = applyOperation.getChild(childId);
68 return from(childOp.get(),childMod);