2 * Copyright (c) 2015 Brocade Communications 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.datastore.utils;
10 import com.google.common.base.Optional;
11 import com.google.common.base.Preconditions;
12 import java.util.ArrayDeque;
13 import java.util.Deque;
14 import javax.annotation.Nonnull;
15 import org.opendaylight.controller.cluster.datastore.messages.BatchedModifications;
16 import org.opendaylight.controller.cluster.datastore.modification.DeleteModification;
17 import org.opendaylight.controller.cluster.datastore.modification.MergeModification;
18 import org.opendaylight.controller.cluster.datastore.modification.WriteModification;
19 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
20 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
21 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
22 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModificationCursor;
25 * Base class for a DataTreeModificationCursor that publishes to BatchedModifications instance(s).
27 * @author Thomas Pantelis
29 public abstract class AbstractBatchedModificationsCursor implements DataTreeModificationCursor {
30 private final Deque<YangInstanceIdentifier> stack = new ArrayDeque<>();
32 protected AbstractBatchedModificationsCursor() {
33 stack.push(YangInstanceIdentifier.EMPTY);
36 protected abstract BatchedModifications getModifications();
39 public void delete(final PathArgument child) {
40 getModifications().addModification(new DeleteModification(stack.peek().node(child)));
44 public void merge(final PathArgument child, final NormalizedNode<?, ?> data) {
45 getModifications().addModification(new MergeModification(stack.peek().node(child), data));
49 public void write(final PathArgument child, final NormalizedNode<?, ?> data) {
50 getModifications().addModification(new WriteModification(stack.peek().node(child), data));
54 public void enter(@Nonnull final PathArgument child) {
55 stack.push(stack.peek().node(child));
59 public void enter(@Nonnull final PathArgument... path) {
60 for (PathArgument arg : path) {
66 public void enter(@Nonnull final Iterable<PathArgument> path) {
67 for (PathArgument arg : path) {
78 public void exit(final int depth) {
79 Preconditions.checkArgument(depth < stack.size(), "Stack holds only %s elements, cannot exit %s levels", stack.size(), depth);
80 for (int i = 0; i < depth; ++i) {
86 public Optional<NormalizedNode<?, ?>> readNode(@Nonnull final PathArgument child) {
87 throw new UnsupportedOperationException("Not implemented");