Merge "Bug 3051: Fixed pattern checks in generated DTOs"
[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.schema.NormalizedNode;
11 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeFactory;
12 import org.opendaylight.yangtools.yang.data.api.schema.tree.TipProducingDataTree;
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.ImmutableNodes;
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     private final NormalizedNode<?, ?> root = ImmutableNodes.containerNode(SchemaContext.NAME);
24
25     private InMemoryDataTreeFactory() {
26         // Never instantiated externally
27     }
28
29     @Override
30     public TipProducingDataTree create() {
31         return new InMemoryDataTree(TreeNodeFactory.createTreeNode(root, Version.initial()), null);
32     }
33
34     /**
35      * Get an instance of this factory. This method cannot fail.
36      *
37      * @return Data tree factory instance.
38      */
39     public static InMemoryDataTreeFactory getInstance() {
40         return INSTANCE;
41     }
42 }