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