Rework NormalizedNode type hierarchy
[yangtools.git] / yang / yang-data-api / src / main / java / org / opendaylight / yangtools / yang / data / api / schema / tree / spi / TreeNodeFactory.java
1 /*
2  * Copyright (c) 2014 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.yangtools.yang.data.api.schema.tree.spi;
9
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;
13
14 /**
15  * Public entrypoint for other packages. Allows instantiating a tree node
16  * with specified version.
17  */
18 public final class TreeNodeFactory {
19     private TreeNodeFactory() {
20         // Hidden on purpose
21     }
22
23     /**
24      * Create a new AbstractTreeNode from a data node.
25      *
26      * @param data data node
27      * @param version data node version
28      * @return new AbstractTreeNode instance, covering the data tree provided
29      */
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);
36         }
37         if (data instanceof OrderedNodeContainer<?>) {
38             return new SimpleContainerNode(data, version);
39         }
40         return new ValueNode(data, version);
41     }
42 }