2 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
\r
4 * This program and the accompanying materials are made available under the
\r
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
\r
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
\r
8 package org.opendaylight.controller.yang.model.util;
\r
10 import java.net.URI;
\r
11 import java.util.Date;
\r
12 import java.util.HashSet;
\r
13 import java.util.List;
\r
14 import java.util.Set;
\r
16 import org.opendaylight.controller.yang.model.api.TypeDefinition;
\r
18 public class YangTypesConverter {
\r
19 private static final Set<String> baseYangTypes = new HashSet<String>();
\r
22 baseYangTypes.add("binary");
\r
23 baseYangTypes.add("bits");
\r
24 baseYangTypes.add("boolean");
\r
25 baseYangTypes.add("decimal64");
\r
26 baseYangTypes.add("empty");
\r
27 baseYangTypes.add("enumeration");
\r
28 baseYangTypes.add("identityref");
\r
29 baseYangTypes.add("instance-identifier");
\r
30 baseYangTypes.add("int8");
\r
31 baseYangTypes.add("int16");
\r
32 baseYangTypes.add("int32");
\r
33 baseYangTypes.add("int64");
\r
34 baseYangTypes.add("leafref");
\r
35 baseYangTypes.add("string");
\r
36 baseYangTypes.add("uint8");
\r
37 baseYangTypes.add("uint16");
\r
38 baseYangTypes.add("uint32");
\r
39 baseYangTypes.add("uint64");
\r
40 baseYangTypes.add("union");
\r
43 public static boolean isBaseYangType(String type) {
\r
44 return baseYangTypes.contains(type);
\r
47 public static TypeDefinition<?> javaTypeForBaseYangType(
\r
48 List<String> actualPath, URI namespace, Date revision,
\r
50 TypeDefinition<?> type = null;
\r
52 if (typeName.startsWith("int")) {
\r
53 if (typeName.equals("int8")) {
\r
54 type = new Int8(actualPath, namespace, revision);
\r
55 } else if (typeName.equals("int16")) {
\r
56 type = new Int16(actualPath, namespace, revision);
\r
57 } else if (typeName.equals("int32")) {
\r
58 type = new Int32(actualPath, namespace, revision);
\r
59 } else if (typeName.equals("int64")) {
\r
60 type = new Int64(actualPath, namespace, revision);
\r
62 } else if (typeName.startsWith("uint")) {
\r
63 if (typeName.equals("uint8")) {
\r
64 type = new Uint8(actualPath, namespace, revision);
\r
65 } else if (typeName.equals("uint16")) {
\r
66 type = new Uint16(actualPath, namespace, revision);
\r
67 } else if (typeName.equals("uint32")) {
\r
68 type = new Uint32(actualPath, namespace, revision);
\r
69 } else if (typeName.equals("uint64")) {
\r
70 type = new Uint64(actualPath, namespace, revision);
\r
72 } else if ("string".equals(typeName)) {
\r
73 type = new StringType(actualPath, namespace, revision);
\r
74 } else if("binary".equals(typeName)) {
\r
75 type = new BinaryType(actualPath, namespace, revision);
\r
76 } else if("bits".equals(typeName)) {
\r
77 type = new BitsType(actualPath, namespace, revision);
\r
78 } else if("boolean".equals(typeName)) {
\r
79 type = new BooleanType(actualPath, namespace, revision);
\r
80 } else if("empty".equals(typeName)) {
\r
81 type = new EmptyType(actualPath, namespace, revision);
\r
82 } else if("instance-identifier".equals(typeName)) {
\r
83 type = new InstanceIdentifier(actualPath, namespace, revision, null, true);
\r