Added missing copyright headers to yang-data-impl
[yangtools.git] / yang / yang-data-impl / src / main / java / org / opendaylight / yangtools / yang / data / impl / schema / tree / InMemoryDataTreeFactory.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.impl.schema.tree;
9
10 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
11 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
12 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeFactory;
13 import org.opendaylight.yangtools.yang.data.api.schema.tree.spi.TreeNodeFactory;
14 import org.opendaylight.yangtools.yang.data.api.schema.tree.spi.Version;
15 import org.opendaylight.yangtools.yang.data.impl.schema.Builders;
16 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
17
18 /**
19  * A factory for creating in-memory data trees.
20  */
21 public final class InMemoryDataTreeFactory implements DataTreeFactory {
22     private static final InMemoryDataTreeFactory INSTANCE = new InMemoryDataTreeFactory();
23
24     private InMemoryDataTreeFactory() {
25         // Never instantiated externally
26     }
27
28     @Override
29     public InMemoryDataTree create() {
30         final NodeIdentifier root = new NodeIdentifier(SchemaContext.NAME);
31         final NormalizedNode<?, ?> data = Builders.containerBuilder().withNodeIdentifier(root).build();
32
33         return new InMemoryDataTree(TreeNodeFactory.createTreeNodeRecursively(data, Version.initial()), null);
34     }
35
36     /**
37      * Get an instance of this factory. This method cannot fail.
38      *
39      * @return Data tree factory instance.
40      */
41     public static final InMemoryDataTreeFactory getInstance() {
42         return INSTANCE;
43     }
44 }