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;
11 import com.google.common.base.Optional;
12 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
13 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
14 import org.opendaylight.yangtools.yang.data.api.schema.tree.spi.TreeNode;
15 import org.opendaylight.yangtools.yang.data.api.schema.tree.spi.Version;
17 final class OperationWithModification {
19 private final ModifiedNode modification;
21 private final ModificationApplyOperation applyOperation;
23 private OperationWithModification(final ModificationApplyOperation op, final ModifiedNode mod) {
24 this.modification = mod;
25 this.applyOperation = op;
28 public OperationWithModification write(final NormalizedNode<?, ?> value) {
29 modification.write(value);
30 applyOperation.verifyStructure(modification);
34 public OperationWithModification delete() {
35 modification.delete();
39 public ModifiedNode getModification() {
43 public ModificationApplyOperation getApplyOperation() {
44 return applyOperation;
47 public Optional<TreeNode> apply(final Optional<TreeNode> data, final Version version) {
48 return applyOperation.apply(modification, data, version);
51 public static OperationWithModification from(final ModificationApplyOperation operation,
52 final ModifiedNode modification) {
53 return new OperationWithModification(operation, modification);
56 public void merge(final NormalizedNode<?, ?> data) {
57 modification.merge(data);
58 applyOperation.verifyStructure(modification);
61 public OperationWithModification forChild(final PathArgument childId) {
62 ModificationApplyOperation childOp = applyOperation.getChild(childId).get();
64 final boolean isOrdered;
65 if (childOp instanceof SchemaAwareApplyOperation) {
66 isOrdered = ((SchemaAwareApplyOperation) childOp).isOrdered();
71 ModifiedNode childMod = modification.modifyChild(childId, isOrdered);
73 return from(childOp,childMod);