Merge "BUG-624 make netconf tcp address optional in config.ini with default value...
[controller.git] / opendaylight / md-sal / sal-dom-broker / src / main / java / org / opendaylight / controller / md / sal / dom / store / impl / 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.controller.md.sal.dom.store.impl.tree.spi;
9
10 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
11 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNodeContainer;
12 import org.opendaylight.yangtools.yang.data.api.schema.OrderedNodeContainer;
13
14 public final class TreeNodeFactory {
15     private TreeNodeFactory() {
16         throw new UnsupportedOperationException("Utility class should not be instantiated");
17     }
18
19     /**
20      * Create a new AbstractTreeNode from a data node, descending recursively as needed.
21      * This method should only ever be used for new data.
22      *
23      * @param data data node
24      * @param version data node version
25      * @return new AbstractTreeNode instance, covering the data tree provided
26      */
27     public static final TreeNode createTreeNode(final NormalizedNode<?, ?> data, final Version version) {
28         if (data instanceof NormalizedNodeContainer<?, ?, ?>) {
29             @SuppressWarnings("unchecked")
30             NormalizedNodeContainer<?, ?, NormalizedNode<?, ?>> container = (NormalizedNodeContainer<?, ?, NormalizedNode<?, ?>>) data;
31             return ContainerNode.create(version, container);
32
33         }
34         if (data instanceof OrderedNodeContainer<?>) {
35             @SuppressWarnings("unchecked")
36             OrderedNodeContainer<NormalizedNode<?, ?>> container = (OrderedNodeContainer<NormalizedNode<?, ?>>) data;
37             return ContainerNode.create(version, container);
38         }
39
40         return new ValueNode(data, version);
41     }
42 }