374ad8bf9251463b0dc9e86896a105b4f64f20e0
[controller.git] / opendaylight / sal / yang-prototype / code-generator / binding-generator-impl / src / main / java / org / opendaylight / controller / sal / binding / yang / types / BaseYangTypes.java
1 /*
2  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.controller.sal.binding.yang.types;
9
10 import java.math.BigInteger;
11 import java.util.HashMap;
12 import java.util.Map;
13
14 import org.opendaylight.controller.binding.generator.util.Types;
15 import org.opendaylight.controller.sal.binding.generator.spi.TypeProvider;
16 import org.opendaylight.controller.sal.binding.model.api.Type;
17 import org.opendaylight.controller.yang.model.api.TypeDefinition;
18
19 public class BaseYangTypes {
20
21     private static Map<String, Type> typeMap = new HashMap<String, Type>();
22
23     public static final Type BOOLEAN_TYPE = Types.typeForClass(Boolean.class);
24     public static final Type EMPTY_TYPE = Types.typeForClass(Boolean.class);
25     public static final Type INT8_TYPE = Types.typeForClass(Byte.class);
26     public static final Type INT16_TYPE = Types.typeForClass(Short.class);
27     public static final Type INT32_TYPE = Types.typeForClass(Integer.class);
28     public static final Type INT64_TYPE = Types.typeForClass(Long.class);
29     public static final Type STRING_TYPE = Types.typeForClass(String.class);
30     public static final Type DECIMAL64_TYPE = Types.typeForClass(Double.class);
31     public static final Type UINT8_TYPE = Types.typeForClass(Short.class);
32     public static final Type UINT16_TYPE = Types.typeForClass(Integer.class);
33     public static final Type UINT32_TYPE = Types.typeForClass(Long.class);
34     public static final Type UINT64_TYPE = Types.typeForClass(BigInteger.class);
35
36     static {
37         typeMap.put("boolean", BOOLEAN_TYPE);
38         typeMap.put("empty", EMPTY_TYPE);
39         typeMap.put("int8", INT8_TYPE);
40         typeMap.put("int16", INT16_TYPE);
41         typeMap.put("int32", INT32_TYPE);
42         typeMap.put("int64", INT64_TYPE);
43         typeMap.put("string", STRING_TYPE);
44         typeMap.put("decimal64", DECIMAL64_TYPE);
45         typeMap.put("uint8", UINT8_TYPE);
46         typeMap.put("uint16", UINT16_TYPE);
47         typeMap.put("uint32", UINT32_TYPE);
48         typeMap.put("uint64", UINT64_TYPE);
49     }
50
51     public static final TypeProvider BASE_YANG_TYPES_PROVIDER = new TypeProvider() {
52
53         @Override
54         public Type javaTypeForYangType(String type) {
55             return typeMap.get(type);
56         }
57
58         @Override
59         public Type javaTypeForSchemaDefinitionType(TypeDefinition<?> type) {
60             if (type != null) {
61                 return typeMap.get(type.getQName().getLocalName());
62             }
63
64             return null;
65         }
66     };
67 }