Merge "Bug:1238 - Revert changes to SshClientAdapter."
[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 /**
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         throw new UnsupportedOperationException("Utility class should not be instantiated");
21     }
22
23     /**
24      * Create a new AbstractTreeNode from a data node, descending recursively as needed.
25      * This method should only ever be used for new data.
26      *
27      * @param data data node
28      * @param version data node version
29      * @return new AbstractTreeNode instance, covering the data tree provided
30      */
31     public static final TreeNode createTreeNode(final NormalizedNode<?, ?> data, final Version version) {
32         if (data instanceof NormalizedNodeContainer<?, ?, ?>) {
33             @SuppressWarnings("unchecked")
34             NormalizedNodeContainer<?, ?, NormalizedNode<?, ?>> container = (NormalizedNodeContainer<?, ?, NormalizedNode<?, ?>>) data;
35             return ContainerNode.create(version, container);
36
37         }
38         if (data instanceof OrderedNodeContainer<?>) {
39             @SuppressWarnings("unchecked")
40             OrderedNodeContainer<NormalizedNode<?, ?>> container = (OrderedNodeContainer<NormalizedNode<?, ?>>) data;
41             return ContainerNode.create(version, container);
42         }
43
44         return new ValueNode(data, version);
45     }
46 }