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
22 public final class BaseTypes {
27 public static final QName BINARY_QNAME = constructQName("binary");
28 public static final QName BITS_QNAME = constructQName("bits");
29 public static final QName BOOLEAN_QNAME = constructQName("boolean");
30 public static final QName DECIMAL64_QNAME = constructQName("decimal64");
31 public static final QName EMPTY_QNAME = constructQName("empty");
32 public static final QName ENUMERATION_QNAME = constructQName("enumeration");
33 public static final QName IDENTITYREF_QNAME = constructQName("identityref");
34 public static final QName INSTANCE_IDENTIFIER_QNAME = constructQName("instance-identifier");
35 public static final QName INT8_QNAME = constructQName("int8");
36 public static final QName INT16_QNAME = constructQName("int16");
37 public static final QName INT32_QNAME = constructQName("int32");
38 public static final QName INT64_QNAME = constructQName("int64");
39 public static final QName LEAFREF_QNAME = constructQName("leafref");
40 public static final QName STRING_QNAME = constructQName("string");
41 public static final QName UINT8_QNAME = constructQName("uint8");
42 public static final QName UINT16_QNAME = constructQName("uint16");
43 public static final QName UINT32_QNAME = constructQName("uint32");
44 public static final QName UINT64_QNAME = constructQName("uint64");
45 public static final QName UNION_QNAME = constructQName("union");
47 private static final Set<QName> BUILT_IN_TYPES = ImmutableSet.<QName>builder()
53 .add(ENUMERATION_QNAME)
54 .add(IDENTITYREF_QNAME)
55 .add(INSTANCE_IDENTIFIER_QNAME)
70 * Construct QName for Built-in base Yang type. The namespace for built-in
71 * base yang types is defined as: urn:ietf:params:xml:ns:yang:1
75 * @return built-in base yang type QName.
77 public static QName constructQName(final String typeName) {
78 return QName.create(YangConstants.RFC6020_YANG_MODULE, typeName).intern();
82 * Returns true if supplied type is representation of built-in YANG type as
85 * See package documentation for description of base types.
88 * @return true if type is built-in YANG Types.
90 public static boolean isYangBuildInType(final String type) {
91 return !Strings.isNullOrEmpty(type) && BUILT_IN_TYPES.contains(
92 QName.create(YangConstants.RFC6020_YANG_MODULE, type));
96 * Returns true if supplied type is representation of built-in YANG type as
99 * See package documentation for description of base types.
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());