2 * Copyright (c) 2016 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.cluster.databroker.actors.dds;
10 import static com.google.common.base.Preconditions.checkState;
11 import static java.util.Objects.requireNonNull;
13 import java.util.Arrays;
14 import org.opendaylight.mdsal.dom.api.DOMDataTreeWriteCursor;
15 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
16 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
17 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
20 * A {@link DOMDataTreeWriteCursor} tied to a {@link ClientTransaction}.
22 * @author Robert Varga
24 final class ClientTransactionCursor implements DOMDataTreeWriteCursor {
25 private YangInstanceIdentifier current = YangInstanceIdentifier.empty();
26 private final ClientTransaction parent;
28 ClientTransactionCursor(final ClientTransaction parent) {
29 this.parent = requireNonNull(parent);
33 public void enter(final PathArgument child) {
34 current = current.node(child);
38 public void enter(final PathArgument... path) {
39 enter(Arrays.asList(path));
43 public void enter(final Iterable<PathArgument> path) {
44 path.forEach(this::enter);
49 final YangInstanceIdentifier currentParent = current.getParent();
50 checkState(currentParent != null);
51 current = currentParent;
55 public void exit(final int depth) {
56 for (int i = 0; i < depth; ++i) {
63 parent.closeCursor(this);
67 public void delete(final PathArgument child) {
68 parent.delete(current.node(child));
72 public void merge(final PathArgument child, final NormalizedNode<?, ?> data) {
73 parent.merge(current.node(child), data);
77 public void write(final PathArgument child, final NormalizedNode<?, ?> data) {
78 parent.write(current.node(child), data);