Fixed resolving of leafref types with relative xpath.
[yangtools.git] / code-generator / binding-generator-impl / src / main / java / org / opendaylight / yangtools / sal / binding / yang / types / BaseYangTypes.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.sal.binding.yang.types;\r
9 \r
10 import java.math.BigDecimal;\r
11 import java.math.BigInteger;\r
12 import java.util.HashMap;\r
13 import java.util.Map;\r
14 \r
15 import org.opendaylight.yangtools.binding.generator.util.Types;\r
16 import org.opendaylight.yangtools.sal.binding.generator.spi.TypeProvider;\r
17 import org.opendaylight.yangtools.sal.binding.model.api.Type;\r
18 import org.opendaylight.yangtools.yang.model.api.SchemaNode;\r
19 import org.opendaylight.yangtools.yang.model.api.TypeDefinition;\r
20 \r
21 public final class BaseYangTypes {\r
22     /**\r
23      * mapping of basic built-in YANG types (keys) to JAVA\r
24      * {@link org.opendaylight.yangtools.sal.binding.model.api.Type Type}. This\r
25      * map is filled with mapping data in static initialization block\r
26      */\r
27     private static Map<String, Type> typeMap = new HashMap<String, Type>();\r
28 \r
29     /**\r
30      * <code>Type</code> representation of <code>boolean</code> YANG type\r
31      */\r
32     public static final Type BOOLEAN_TYPE = Types.typeForClass(Boolean.class);\r
33 \r
34     /**\r
35      * <code>Type</code> representation of <code>empty</code> YANG type\r
36      */\r
37     public static final Type EMPTY_TYPE = Types.typeForClass(Boolean.class);\r
38 \r
39     /**\r
40      * <code>Type</code> representation of <code>int8</code> YANG type\r
41      */\r
42     public static final Type INT8_TYPE = Types.typeForClass(Byte.class);\r
43 \r
44     /**\r
45      * <code>Type</code> representation of <code>int16</code> YANG type\r
46      */\r
47     public static final Type INT16_TYPE = Types.typeForClass(Short.class);\r
48 \r
49     /**\r
50      * <code>Type</code> representation of <code>int32</code> YANG type\r
51      */\r
52     public static final Type INT32_TYPE = Types.typeForClass(Integer.class);\r
53 \r
54     /**\r
55      * <code>Type</code> representation of <code>int64</code> YANG type\r
56      */\r
57     public static final Type INT64_TYPE = Types.typeForClass(Long.class);\r
58 \r
59     /**\r
60      * <code>Type</code> representation of <code>string</code> YANG type\r
61      */\r
62     public static final Type STRING_TYPE = Types.typeForClass(String.class);\r
63 \r
64     /**\r
65      * <code>Type</code> representation of <code>decimal64</code> YANG type\r
66      */\r
67     public static final Type DECIMAL64_TYPE = Types.typeForClass(BigDecimal.class);\r
68 \r
69     /**\r
70      * <code>Type</code> representation of <code>uint8</code> YANG type\r
71      */\r
72     public static final Type UINT8_TYPE = Types.typeForClass(Short.class);\r
73 \r
74     /**\r
75      * <code>Type</code> representation of <code>uint16</code> YANG type\r
76      */\r
77     public static final Type UINT16_TYPE = Types.typeForClass(Integer.class);\r
78 \r
79     /**\r
80      * <code>Type</code> representation of <code>uint32</code> YANG type\r
81      */\r
82     public static final Type UINT32_TYPE = Types.typeForClass(Long.class);\r
83 \r
84     /**\r
85      * <code>Type</code> representation of <code>uint64</code> YANG type\r
86      */\r
87     public static final Type UINT64_TYPE = Types.typeForClass(BigInteger.class);\r
88 \r
89     /**\r
90      * <code>Type</code> representation of <code>binary</code> YANG type\r
91      */\r
92     public static final Type BINARY_TYPE = Types.primitiveType("byte[]");\r
93 \r
94     static {\r
95         typeMap.put("boolean", BOOLEAN_TYPE);\r
96         typeMap.put("empty", EMPTY_TYPE);\r
97         typeMap.put("int8", INT8_TYPE);\r
98         typeMap.put("int16", INT16_TYPE);\r
99         typeMap.put("int32", INT32_TYPE);\r
100         typeMap.put("int64", INT64_TYPE);\r
101         typeMap.put("string", STRING_TYPE);\r
102         typeMap.put("decimal64", DECIMAL64_TYPE);\r
103         typeMap.put("uint8", UINT8_TYPE);\r
104         typeMap.put("uint16", UINT16_TYPE);\r
105         typeMap.put("uint32", UINT32_TYPE);\r
106         typeMap.put("uint64", UINT64_TYPE);\r
107         typeMap.put("binary", BINARY_TYPE);\r
108     }\r
109 \r
110     public static final TypeProvider BASE_YANG_TYPES_PROVIDER = new TypeProvider() {\r
111         /**\r
112          * Searches <code>Type</code> value to which is YANG <code>type</code>\r
113          * mapped.\r
114          *\r
115          * @param type\r
116          *            string with YANG type name\r
117          * @return java <code>Type</code> representation of <code>type</code>\r
118          */\r
119         @Override\r
120         public Type javaTypeForYangType(String type) {\r
121             return typeMap.get(type);\r
122         }\r
123 \r
124         /**\r
125          * Searches <code>Type</code> value to which is YANG <code>type</code>\r
126          * mapped.\r
127          *\r
128          * @param type\r
129          *            type definition representation of YANG type\r
130          * @return java <code>Type</code> representation of <code>type</code>.\r
131          *          If <code>type</code> isn't found then <code>null</code> is\r
132          *          returned.\r
133          */\r
134         @Override\r
135         public Type javaTypeForSchemaDefinitionType(TypeDefinition<?> type, SchemaNode parentNode) {\r
136             if (type != null) {\r
137                 return typeMap.get(type.getQName().getLocalName());\r
138             }\r
139 \r
140             return null;\r
141         }\r
142     };\r
143 }\r