2 * Copyright (c) 2014 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.spi;
10 import org.opendaylight.yangtools.yang.data.api.schema.DistinctNodeContainer;
11 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
12 import org.opendaylight.yangtools.yang.data.api.schema.OrderedNodeContainer;
15 * Public entrypoint for other packages. Allows instantiating a tree node
16 * with specified version.
18 public final class TreeNodeFactory {
19 private TreeNodeFactory() {
24 * Create a new AbstractTreeNode from a data node.
26 * @param data data node
27 * @param version data node version
28 * @return new AbstractTreeNode instance, covering the data tree provided
30 public static TreeNode createTreeNode(final NormalizedNode data, final Version version) {
31 if (data instanceof DistinctNodeContainer<?, ?, ?>) {
32 @SuppressWarnings("unchecked")
33 final DistinctNodeContainer<?, ?, NormalizedNode> container =
34 (DistinctNodeContainer<?, ?, NormalizedNode>) data;
35 return new SimpleContainerNode(container, version);
37 if (data instanceof OrderedNodeContainer<?>) {
38 return new SimpleContainerNode(data, version);
40 return new ValueNode(data, version);