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 com.google.common.base.Strings;
11 import com.google.common.collect.ImmutableSet;
13 import org.opendaylight.yangtools.yang.common.QName;
14 import org.opendaylight.yangtools.yang.common.YangConstants;
15 import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
18 * Utility methods and constants to work with built-in YANG types.
20 public final class BaseTypes {
25 public static final QName BINARY_QNAME = constructQName("binary");
26 public static final QName BITS_QNAME = constructQName("bits");
27 public static final QName BOOLEAN_QNAME = constructQName("boolean");
28 public static final QName DECIMAL64_QNAME = constructQName("decimal64");
29 public static final QName EMPTY_QNAME = constructQName("empty");
30 public static final QName ENUMERATION_QNAME = constructQName("enumeration");
31 public static final QName IDENTITYREF_QNAME = constructQName("identityref");
32 public static final QName INSTANCE_IDENTIFIER_QNAME = constructQName("instance-identifier");
33 public static final QName INT8_QNAME = constructQName("int8");
34 public static final QName INT16_QNAME = constructQName("int16");
35 public static final QName INT32_QNAME = constructQName("int32");
36 public static final QName INT64_QNAME = constructQName("int64");
37 public static final QName LEAFREF_QNAME = constructQName("leafref");
38 public static final QName STRING_QNAME = constructQName("string");
39 public static final QName UINT8_QNAME = constructQName("uint8");
40 public static final QName UINT16_QNAME = constructQName("uint16");
41 public static final QName UINT32_QNAME = constructQName("uint32");
42 public static final QName UINT64_QNAME = constructQName("uint64");
43 public static final QName UNION_QNAME = constructQName("union");
45 private static final Set<QName> BUILT_IN_TYPES = ImmutableSet.<QName>builder()
51 .add(ENUMERATION_QNAME)
52 .add(IDENTITYREF_QNAME)
53 .add(INSTANCE_IDENTIFIER_QNAME)
68 * Construct QName for Built-in base Yang type. The namespace for built-in
69 * base yang types is defined as: urn:ietf:params:xml:ns:yang:1
73 * @return built-in base yang type QName.
75 public static QName constructQName(final String typeName) {
76 return QName.create(YangConstants.RFC6020_YANG_MODULE, typeName).intern();
80 * Returns true if supplied type is representation of built-in YANG type as
84 * See package documentation for description of base types.
86 * @param type A type name
87 * @return true if type is built-in YANG Types.
89 public static boolean isYangBuildInType(final String type) {
90 return !Strings.isNullOrEmpty(type) && BUILT_IN_TYPES.contains(
91 QName.create(YangConstants.RFC6020_YANG_MODULE, type));
95 * Returns true if supplied type is representation of built-in YANG type as
99 * See package documentation for description of base types.
101 * @param type Type definition
102 * @return true if type is built-in YANG Types.
104 public static boolean isYangBuildInType(final TypeDefinition<?> type) {
105 return type != null && BUILT_IN_TYPES.contains(type.getQName());