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