Deprecate DOMDataTreeProducer-related classes
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / cluster / databroker / actors / dds / ClientTransactionCursor.java
1 /*
2  * Copyright (c) 2016 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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  */
8 package org.opendaylight.controller.cluster.databroker.actors.dds;
9
10 import static com.google.common.base.Preconditions.checkState;
11 import static java.util.Objects.requireNonNull;
12
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;
18
19 /**
20  * A {@link DOMDataTreeWriteCursor} tied to a {@link ClientTransaction}.
21  *
22  * @author Robert Varga
23  */
24 @Deprecated(forRemoval = true)
25 final class ClientTransactionCursor implements DOMDataTreeWriteCursor {
26     private YangInstanceIdentifier current = YangInstanceIdentifier.empty();
27     private final ClientTransaction parent;
28
29     ClientTransactionCursor(final ClientTransaction parent) {
30         this.parent = requireNonNull(parent);
31     }
32
33     @Override
34     public void enter(final PathArgument child) {
35         current = current.node(child);
36     }
37
38     @Override
39     public void enter(final PathArgument... path) {
40         enter(Arrays.asList(path));
41     }
42
43     @Override
44     public void enter(final Iterable<PathArgument> path) {
45         path.forEach(this::enter);
46     }
47
48     @Override
49     public void exit() {
50         final YangInstanceIdentifier currentParent = current.getParent();
51         checkState(currentParent != null);
52         current = currentParent;
53     }
54
55     @Override
56     public void exit(final int depth) {
57         for (int i = 0; i < depth; ++i) {
58             exit();
59         }
60     }
61
62     @Override
63     public void close() {
64         parent.closeCursor(this);
65     }
66
67     @Override
68     public void delete(final PathArgument child) {
69         parent.delete(current.node(child));
70     }
71
72     @Override
73     public void merge(final PathArgument child, final NormalizedNode<?, ?> data) {
74         parent.merge(current.node(child), data);
75     }
76
77     @Override
78     public void write(final PathArgument child, final NormalizedNode<?, ?> data) {
79         parent.write(current.node(child), data);
80     }
81 }

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.