Fixed bug in uses statement resolving.
[yangtools.git] / yang / yang-model-util / src / main / java / org / opendaylight / yangtools / yang / model / util / YangTypesConverter.java
1 /*\r
2  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.\r
3  *\r
4  * This program and the accompanying materials are made available under the\r
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
6  * and is available at http://www.eclipse.org/legal/epl-v10.html\r
7  */\r
8 package org.opendaylight.yangtools.yang.model.util;\r
9 \r
10 import java.util.HashSet;\r
11 import java.util.Set;\r
12 \r
13 import org.opendaylight.yangtools.yang.model.api.SchemaPath;\r
14 import org.opendaylight.yangtools.yang.model.api.TypeDefinition;\r
15 \r
16 public final class YangTypesConverter {\r
17     private static final Set<String> baseYangTypes = new HashSet<String>();\r
18 \r
19     static {\r
20         baseYangTypes.add("binary");\r
21         baseYangTypes.add("bits");\r
22         baseYangTypes.add("boolean");\r
23         baseYangTypes.add("decimal64");\r
24         baseYangTypes.add("empty");\r
25         baseYangTypes.add("enumeration");\r
26         baseYangTypes.add("identityref");\r
27         baseYangTypes.add("instance-identifier");\r
28         baseYangTypes.add("int8");\r
29         baseYangTypes.add("int16");\r
30         baseYangTypes.add("int32");\r
31         baseYangTypes.add("int64");\r
32         baseYangTypes.add("leafref");\r
33         baseYangTypes.add("string");\r
34         baseYangTypes.add("uint8");\r
35         baseYangTypes.add("uint16");\r
36         baseYangTypes.add("uint32");\r
37         baseYangTypes.add("uint64");\r
38         baseYangTypes.add("union");\r
39     }\r
40 \r
41     public static boolean isBaseYangType(String type) {\r
42         return baseYangTypes.contains(type);\r
43     }\r
44 \r
45     public static TypeDefinition<?> javaTypeForBaseYangType(SchemaPath path, String typeName) {\r
46         TypeDefinition<?> type = null;\r
47 \r
48         if (typeName.startsWith("int")) {\r
49             if ("int8".equals(typeName)) {\r
50                 type = new Int8(path);\r
51             } else if ("int16".equals(typeName)) {\r
52                 type = new Int16(path);\r
53             } else if ("int32".equals(typeName)) {\r
54                 type = new Int32(path);\r
55             } else if ("int64".equals(typeName)) {\r
56                 type = new Int64(path);\r
57             }\r
58         } else if (typeName.startsWith("uint")) {\r
59             if ("uint8".equals(typeName)) {\r
60                 type = new Uint8(path);\r
61             } else if ("uint16".equals(typeName)) {\r
62                 type = new Uint16(path);\r
63             } else if ("uint32".equals(typeName)) {\r
64                 type = new Uint32(path);\r
65             } else if ("uint64".equals(typeName)) {\r
66                 type = new Uint64(path);\r
67             }\r
68         } else if ("string".equals(typeName)) {\r
69             type = new StringType(path);\r
70         } else if("binary".equals(typeName)) {\r
71             type = new BinaryType(path);\r
72         } else if("boolean".equals(typeName)) {\r
73             type = new BooleanType(path);\r
74         } else if("empty".equals(typeName)) {\r
75             type = new EmptyType(path);\r
76         } else if("instance-identifier".equals(typeName)) {\r
77             type = new InstanceIdentifier(path, null, true);\r
78         }\r
79 \r
80         return type;\r
81     }\r
82 \r
83 }\r