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.NodeModification;
11 import org.opendaylight.controller.md.sal.dom.store.impl.tree.StoreMetadataNode;
12 import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier.PathArgument;
13 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
15 import com.google.common.base.Optional;
16 import com.google.common.primitives.UnsignedLong;
18 public class OperationWithModification {
20 private final NodeModification modification;
22 private final ModificationApplyOperation applyOperation;
24 private OperationWithModification(final ModificationApplyOperation op, final NodeModification mod) {
25 this.modification = mod;
26 this.applyOperation = op;
29 public OperationWithModification write(final NormalizedNode<?, ?> value) {
30 modification.write(value);
31 applyOperation.verifyStructure(modification);
35 public OperationWithModification delete() {
36 modification.delete();
40 public NodeModification getModification() {
44 public ModificationApplyOperation getApplyOperation() {
45 return applyOperation;
48 public Optional<StoreMetadataNode> apply(final Optional<StoreMetadataNode> data, final UnsignedLong subtreeVersion) {
49 return applyOperation.apply(modification, data, subtreeVersion);
52 public static OperationWithModification from(final ModificationApplyOperation operation,
53 final NodeModification modification) {
54 return new OperationWithModification(operation, modification);
58 public void merge(final NormalizedNode<?, ?> data) {
59 modification.merge(data);
60 applyOperation.verifyStructure(modification);
64 public OperationWithModification forChild(final PathArgument childId) {
65 NodeModification childMod = modification.modifyChild(childId);
66 Optional<ModificationApplyOperation> childOp = applyOperation.getChild(childId);
67 return from(childOp.get(),childMod);