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.yangtools.yang.model.util;
10 import java.util.HashSet;
13 import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
15 public final class YangTypesConverter {
16 private static final Set<String> BASE_YANG_TYPES = new HashSet<String>();
19 * It isn't desirable to create the instances of this class
21 private YangTypesConverter() {
25 BASE_YANG_TYPES.add("binary");
26 BASE_YANG_TYPES.add("bits");
27 BASE_YANG_TYPES.add("boolean");
28 BASE_YANG_TYPES.add("decimal64");
29 BASE_YANG_TYPES.add("empty");
30 BASE_YANG_TYPES.add("enumeration");
31 BASE_YANG_TYPES.add("identityref");
32 BASE_YANG_TYPES.add("instance-identifier");
33 BASE_YANG_TYPES.add("int8");
34 BASE_YANG_TYPES.add("int16");
35 BASE_YANG_TYPES.add("int32");
36 BASE_YANG_TYPES.add("int64");
37 BASE_YANG_TYPES.add("leafref");
38 BASE_YANG_TYPES.add("string");
39 BASE_YANG_TYPES.add("uint8");
40 BASE_YANG_TYPES.add("uint16");
41 BASE_YANG_TYPES.add("uint32");
42 BASE_YANG_TYPES.add("uint64");
43 BASE_YANG_TYPES.add("union");
46 public static boolean isBaseYangType(String type) {
47 return BASE_YANG_TYPES.contains(type);
50 public static TypeDefinition<?> javaTypeForBaseYangType(String typeName) {
51 TypeDefinition<?> type = null;
53 if (typeName.startsWith("int")) {
54 if ("int8".equals(typeName)) {
55 type = Int8.getInstance();
56 } else if ("int16".equals(typeName)) {
57 type = Int16.getInstance();
58 } else if ("int32".equals(typeName)) {
59 type = Int32.getInstance();
60 } else if ("int64".equals(typeName)) {
61 type = Int64.getInstance();
63 } else if (typeName.startsWith("uint")) {
64 if ("uint8".equals(typeName)) {
65 type = Uint8.getInstance();
66 } else if ("uint16".equals(typeName)) {
67 type = Uint16.getInstance();
68 } else if ("uint32".equals(typeName)) {
69 type = Uint32.getInstance();
70 } else if ("uint64".equals(typeName)) {
71 type = Uint64.getInstance();
73 } else if ("string".equals(typeName)) {
74 type = StringType.getIntance();
75 } else if ("binary".equals(typeName)) {
76 type = BinaryType.getInstance();
77 } else if ("boolean".equals(typeName)) {
78 type = BooleanType.getInstance();
79 } else if ("empty".equals(typeName)) {
80 type = EmptyType.getInstance();
81 } else if ("instance-identifier".equals(typeName)) {
83 type = new InstanceIdentifier(null, true);