Split out BaseYangTypesProvider
[mdsal.git] / binding / mdsal-binding-generator-util / src / main / java / org / opendaylight / mdsal / binding / model / util / 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.mdsal.binding.model.util;
9
10 import com.google.common.collect.ImmutableMap;
11 import java.math.BigDecimal;
12 import org.opendaylight.mdsal.binding.model.api.Type;
13 import org.opendaylight.yangtools.yang.common.Empty;
14 import org.opendaylight.yangtools.yang.common.Uint16;
15 import org.opendaylight.yangtools.yang.common.Uint32;
16 import org.opendaylight.yangtools.yang.common.Uint64;
17 import org.opendaylight.yangtools.yang.common.Uint8;
18
19 public final class BaseYangTypes {
20     /**
21      * {@code Type} representation of {@code boolean} YANG type.
22      */
23     public static final Type BOOLEAN_TYPE = Types.BOOLEAN;
24
25     /**
26      * {@code Type} representation of {@code empty} YANG type.
27      */
28     public static final Type EMPTY_TYPE = Types.typeForClass(Empty.class);
29
30     public static final Type ENUM_TYPE = Types.typeForClass(Enum.class);
31
32     /**
33      * {@code Type} representation of {@code int8} YANG type.
34      */
35     public static final Type INT8_TYPE = Types.typeForClass(Byte.class);
36
37     /**
38      * {@code Type} representation of {@code int16} YANG type.
39      */
40     public static final Type INT16_TYPE = Types.typeForClass(Short.class);
41
42     /**
43      * {@code Type} representation of {@code int32} YANG type.
44      */
45     public static final Type INT32_TYPE = Types.typeForClass(Integer.class);
46
47     /**
48      * {@code Type} representation of {@code int64} YANG type.
49      */
50     public static final Type INT64_TYPE = Types.typeForClass(Long.class);
51
52     /**
53      * {@code Type} representation of {@code string} YANG type.
54      */
55     public static final Type STRING_TYPE = Types.STRING;
56
57     /**
58      * {@code Type} representation of {@code decimal64} YANG type.
59      */
60     public static final Type DECIMAL64_TYPE = Types.typeForClass(BigDecimal.class);
61
62     /**
63      * {@code Type} representation of {@code uint8} YANG type.
64      */
65     public static final Type UINT8_TYPE = Types.typeForClass(Uint8.class);
66
67     /**
68      * {@code Type} representation of {@code uint16} YANG type.
69      */
70     public static final Type UINT16_TYPE = Types.typeForClass(Uint16.class);
71
72     /**
73      * {@code Type} representation of {@code uint32} YANG type.
74      */
75     public static final Type UINT32_TYPE = Types.typeForClass(Uint32.class);
76
77     /**
78      * {@code Type} representation of {@code uint64} YANG type.
79      */
80     public static final Type UINT64_TYPE = Types.typeForClass(Uint64.class);
81
82     /**
83      * {@code Type} representation of {@code binary} YANG type.
84      */
85     public static final Type BINARY_TYPE = Types.BYTE_ARRAY;
86
87     public static final Type INSTANCE_IDENTIFIER = Types.parameterizedTypeFor(BindingTypes.INSTANCE_IDENTIFIER);
88
89     /**
90      * mapping of basic built-in YANG types (keys) to JAVA {@link org.opendaylight.mdsal.binding.model.api.Type Type}.
91      * This map is filled with mapping data in static initialization block.
92      */
93     private static final ImmutableMap<String, Type> TYPE_MAP = ImmutableMap.<String, Type>builder()
94             .put("boolean", BOOLEAN_TYPE)
95             .put("empty", EMPTY_TYPE)
96             .put("enumeration", ENUM_TYPE)
97             .put("int8", INT8_TYPE)
98             .put("int16", INT16_TYPE)
99             .put("int32", INT32_TYPE)
100             .put("int64", INT64_TYPE)
101             .put("string", STRING_TYPE)
102             .put("decimal64", DECIMAL64_TYPE)
103             .put("uint8", UINT8_TYPE)
104             .put("uint16", UINT16_TYPE)
105             .put("uint32", UINT32_TYPE)
106             .put("uint64", UINT64_TYPE)
107             .put("binary", BINARY_TYPE)
108             .put("instance-identifier", INSTANCE_IDENTIFIER)
109             .build();
110
111     private BaseYangTypes() {
112         // Hidden on purpose
113     }
114
115     /**
116      * Searches {@code Type} value to which is YANG {@code type} mapped.
117      *
118      * @param type string with YANG type name
119      * @return Java {@code Type} representation of {@code type}, or null if the type is not mapped.
120      */
121     public static Type javaTypeForYangType(final String type) {
122         return TYPE_MAP.get(type);
123     }
124 }