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