2 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.mdsal.binding.model.util;
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;
19 public final class BaseYangTypes {
21 * {@code Type} representation of {@code boolean} YANG type.
23 public static final Type BOOLEAN_TYPE = Types.BOOLEAN;
26 * {@code Type} representation of {@code empty} YANG type.
28 public static final Type EMPTY_TYPE = Types.typeForClass(Empty.class);
30 public static final Type ENUM_TYPE = Types.typeForClass(Enum.class);
33 * {@code Type} representation of {@code int8} YANG type.
35 public static final Type INT8_TYPE = Types.typeForClass(Byte.class);
38 * {@code Type} representation of {@code int16} YANG type.
40 public static final Type INT16_TYPE = Types.typeForClass(Short.class);
43 * {@code Type} representation of {@code int32} YANG type.
45 public static final Type INT32_TYPE = Types.typeForClass(Integer.class);
48 * {@code Type} representation of {@code int64} YANG type.
50 public static final Type INT64_TYPE = Types.typeForClass(Long.class);
53 * {@code Type} representation of {@code string} YANG type.
55 public static final Type STRING_TYPE = Types.STRING;
58 * {@code Type} representation of {@code decimal64} YANG type.
60 public static final Type DECIMAL64_TYPE = Types.typeForClass(BigDecimal.class);
63 * {@code Type} representation of {@code uint8} YANG type.
65 public static final Type UINT8_TYPE = Types.typeForClass(Uint8.class);
68 * {@code Type} representation of {@code uint16} YANG type.
70 public static final Type UINT16_TYPE = Types.typeForClass(Uint16.class);
73 * {@code Type} representation of {@code uint32} YANG type.
75 public static final Type UINT32_TYPE = Types.typeForClass(Uint32.class);
78 * {@code Type} representation of {@code uint64} YANG type.
80 public static final Type UINT64_TYPE = Types.typeForClass(Uint64.class);
83 * {@code Type} representation of {@code binary} YANG type.
85 public static final Type BINARY_TYPE = Types.BYTE_ARRAY;
87 public static final Type INSTANCE_IDENTIFIER = Types.parameterizedTypeFor(BindingTypes.INSTANCE_IDENTIFIER);
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.
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)
111 private BaseYangTypes() {
116 * Searches {@code Type} value to which is YANG {@code type} mapped.
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.
121 public static Type javaTypeForYangType(final String type) {
122 return TYPE_MAP.get(type);