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;
13 import org.slf4j.Logger;
14 import org.slf4j.LoggerFactory;
17 * Utility class holding methods useful when dealing with {@link DataTreeCandidate} instances.
20 public final class DataTreeCandidates {
21 private static final Logger LOG = LoggerFactory.getLogger(DataTreeCandidates.class);
22 private DataTreeCandidates() {
23 throw new UnsupportedOperationException();
26 public static DataTreeCandidate newDataTreeCandidate(final YangInstanceIdentifier rootPath, final DataTreeCandidateNode rootNode) {
27 return new DefaultDataTreeCandidate(rootPath, rootNode);
30 public static DataTreeCandidate fromNormalizedNode(final YangInstanceIdentifier rootPath, final NormalizedNode<?, ?> node) {
31 return new DefaultDataTreeCandidate(rootPath, new NormalizedNodeDataTreeCandidateNode(node));
34 public static void applyToModification(final DataTreeModification modification, final DataTreeCandidate candidate) {
35 applyNode(modification, candidate.getRootPath(), candidate.getRootNode());
38 private static void applyNode(final DataTreeModification modification, final YangInstanceIdentifier path, final DataTreeCandidateNode node) {
39 switch (node.getModificationType()) {
41 modification.delete(path);
42 LOG.debug("Modification {} deleted path {}", modification, path);
44 case SUBTREE_MODIFIED:
45 LOG.debug("Modification {} modified path {}", modification, path);
46 for (DataTreeCandidateNode child : node.getChildNodes()) {
47 applyNode(modification, path.node(child.getIdentifier()), child);
51 LOG.debug("Modification {} unmodified path {}", modification, path);
55 modification.write(path, node.getDataAfter().get());
56 LOG.debug("Modification {} written path {}", modification, path);
59 throw new IllegalArgumentException("Unsupported modification " + node.getModificationType());