Update the API generation code and code generation sample
[controller.git] / opendaylight / sal / yang-prototype / code-generator / binding-generator-impl / src / main / java / org / opendaylight / controller / 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.controller.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.controller.binding.generator.util.Types;\r
16 import org.opendaylight.controller.sal.binding.generator.spi.TypeProvider;\r
17 import org.opendaylight.controller.sal.binding.model.api.Type;\r
18 import org.opendaylight.controller.yang.model.api.TypeDefinition;\r
19 \r
20 public 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 INT8_TYPE = Types.typeForClass(Byte.class);\r
26     public static final Type INT16_TYPE = Types.typeForClass(Short.class);\r
27     public static final Type INT32_TYPE = Types.typeForClass(Integer.class);\r
28     public static final Type INT64_TYPE = Types.typeForClass(Long.class);\r
29     public static final Type STRING_TYPE = Types.typeForClass(String.class);\r
30     public static final Type DECIMAL64_TYPE = Types.typeForClass(Double.class);\r
31     public static final Type UINT8_TYPE = Types.typeForClass(Short.class);\r
32     public static final Type UINT16_TYPE = Types.typeForClass(Integer.class);\r
33     public static final Type UINT32_TYPE = Types.typeForClass(Long.class);\r
34     public static final Type UINT64_TYPE = Types.typeForClass(BigInteger.class);\r
35 \r
36     static {\r
37         typeMap.put("boolean", BOOLEAN_TYPE);\r
38         typeMap.put("int8", INT8_TYPE);\r
39         typeMap.put("int16", INT16_TYPE);\r
40         typeMap.put("int32", INT32_TYPE);\r
41         typeMap.put("int64", INT64_TYPE);\r
42         typeMap.put("string", STRING_TYPE);\r
43         typeMap.put("decimal64", DECIMAL64_TYPE);\r
44         typeMap.put("uint8", UINT8_TYPE);\r
45         typeMap.put("uint16", UINT16_TYPE);\r
46         typeMap.put("uint32", UINT32_TYPE);\r
47         typeMap.put("uint64", UINT64_TYPE);\r
48     }\r
49 \r
50     public static final TypeProvider BASE_YANG_TYPES_PROVIDER = new TypeProvider() {\r
51 \r
52         @Override\r
53         public Type javaTypeForYangType(String type) {\r
54             return typeMap.get(type);\r
55         }\r
56 \r
57         @Override\r
58         public Type javaTypeForSchemaDefinitionType(TypeDefinition<?> type) {\r
59             if (type != null) {\r
60                 return typeMap.get(type.getQName().getLocalName());\r
61             }\r
62 \r
63             return null;\r
64         }\r
65     };\r
66 \r
67 }\r

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.