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