2 * Copyright (c) 2015 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.api.schema.tree;
10 import com.google.common.annotations.Beta;
11 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
12 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
15 * Utility class holding methods useful when dealing with {@link DataTreeCandidate} instances.
18 public final class DataTreeCandidates {
19 private DataTreeCandidates() {
20 throw new UnsupportedOperationException();
23 public static DataTreeCandidate newDataTreeCandidate(final YangInstanceIdentifier rootPath, final DataTreeCandidateNode rootNode) {
24 return new DefaultDataTreeCandidate(rootPath, rootNode);
27 public static DataTreeCandidate fromNormalizedNode(final YangInstanceIdentifier rootPath, final NormalizedNode<?, ?> node) {
28 return new DefaultDataTreeCandidate(rootPath, new NormalizedNodeDataTreeCandidateNode(node));
31 public static void applyToModification(final DataTreeModification modification, final DataTreeCandidate candidate) {
32 applyNode(modification, candidate.getRootPath(), candidate.getRootNode());
35 private static void applyNode(final DataTreeModification modification, final YangInstanceIdentifier path, final DataTreeCandidateNode node) {
36 switch (node.getModificationType()) {
38 modification.delete(path);
40 case SUBTREE_MODIFIED:
41 for (DataTreeCandidateNode child : node.getChildNodes()) {
42 applyNode(modification, path.node(child.getIdentifier()), child);
49 modification.write(path, node.getDataAfter().get());
52 throw new IllegalArgumentException("Unsupported modification " + node.getModificationType());