Added instance identifier support.
[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.TypeDefinition;\r
19 \r
20 public final class BaseYangTypes {\r
21 \r
22     private static Map<String, Type> typeMap = new HashMap<String, Type>();\r
23 \r
24     public static final Type BOOLEAN_TYPE = Types.typeForClass(Boolean.class);\r
25     public static final Type EMPTY_TYPE = Types.typeForClass(Boolean.class);\r
26     public static final Type INT8_TYPE = Types.typeForClass(Byte.class);\r
27     public static final Type INT16_TYPE = Types.typeForClass(Short.class);\r
28     public static final Type INT32_TYPE = Types.typeForClass(Integer.class);\r
29     public static final Type INT64_TYPE = Types.typeForClass(Long.class);\r
30     public static final Type STRING_TYPE = Types.typeForClass(String.class);\r
31     public static final Type DECIMAL64_TYPE = Types.typeForClass(BigDecimal.class);\r
32     public static final Type UINT8_TYPE = Types.typeForClass(Short.class);\r
33     public static final Type UINT16_TYPE = Types.typeForClass(Integer.class);\r
34     public static final Type UINT32_TYPE = Types.typeForClass(Long.class);\r
35     public static final Type UINT64_TYPE = Types.typeForClass(BigInteger.class);\r
36     public static final Type BINARY_TYPE = Types.primitiveType("byte[]");\r
37 \r
38     static {\r
39         typeMap.put("boolean", BOOLEAN_TYPE);\r
40         typeMap.put("empty", EMPTY_TYPE);\r
41         typeMap.put("int8", INT8_TYPE);\r
42         typeMap.put("int16", INT16_TYPE);\r
43         typeMap.put("int32", INT32_TYPE);\r
44         typeMap.put("int64", INT64_TYPE);\r
45         typeMap.put("string", STRING_TYPE);\r
46         typeMap.put("decimal64", DECIMAL64_TYPE);\r
47         typeMap.put("uint8", UINT8_TYPE);\r
48         typeMap.put("uint16", UINT16_TYPE);\r
49         typeMap.put("uint32", UINT32_TYPE);\r
50         typeMap.put("uint64", UINT64_TYPE);\r
51         typeMap.put("binary", BINARY_TYPE);\r
52     }\r
53 \r
54     public static final TypeProvider BASE_YANG_TYPES_PROVIDER = new TypeProvider() {\r
55 \r
56         @Override\r
57         public Type javaTypeForYangType(String type) {\r
58             return typeMap.get(type);\r
59         }\r
60 \r
61         @Override\r
62         public Type javaTypeForSchemaDefinitionType(TypeDefinition<?> type) {\r
63             if (type != null) {\r
64                 return typeMap.get(type.getQName().getLocalName());\r
65             }\r
66 \r
67             return null;\r
68         }\r
69     };\r
70 }\r