Merge changes Id6a27004,I7baa722d
[yangtools.git] / yang / yang-model-util / src / main / java / org / opendaylight / yangtools / yang / model / util / BaseTypes.java
1 /*
2  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.yangtools.yang.model.util;
9
10 import java.net.URI;
11 import java.util.ArrayList;
12 import java.util.Collections;
13 import java.util.Date;
14 import java.util.List;
15
16 import org.opendaylight.yangtools.yang.common.QName;
17 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
18
19 public final class BaseTypes {
20
21     private BaseTypes() {
22     }
23
24     public static final URI BASE_TYPES_NAMESPACE = URI.create("urn:ietf:params:xml:ns:yang:1");
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 INT8_QNAME = constructQName("int8");
32     public static final QName INT16_QNAME = constructQName("int16");
33     public static final QName INT32_QNAME = constructQName("int32");
34     public static final QName INT64_QNAME = constructQName("int64");
35     public static final QName LEAFREF_QNAME = constructQName("leafref");
36     public static final QName STRING_QNAME = constructQName("string");
37     public static final QName UINT8_QNAME = constructQName("uint8");
38     public static final QName UINT16_QNAME = constructQName("uint16");
39     public static final QName UINT32_QNAME = constructQName("uint32");
40     public static final QName UINT64_QNAME = constructQName("uint64");
41
42     /**
43      * Construct QName for Built-in base Yang type. The namespace for built-in
44      * base yang types is defined as: urn:ietf:params:xml:ns:yang:1
45      *
46      * @param typeName
47      *            yang type name
48      * @return built-in base yang type QName.
49      */
50     public static QName constructQName(final String typeName) {
51         return new QName(BASE_TYPES_NAMESPACE, typeName);
52     }
53
54     /**
55      * Creates Schema Path from Qname.
56      *
57      * @param typeName
58      *            yang type QName
59      * @return Schema Path from Qname.
60      */
61     public static SchemaPath schemaPath(final QName typeName) {
62         List<QName> pathList = Collections.singletonList(typeName);
63         return new SchemaPath(pathList, true);
64     }
65
66     /**
67      * Creates Schema Path from List of partial paths defined as Strings, module
68      * Namespace and module latest Revision Date.
69      *
70      * @param actualPath
71      *            List of partial paths
72      * @param namespace
73      *            Module Namespace
74      * @param revision
75      *            Revision Date
76      * @return Schema Path
77      */
78     public static SchemaPath schemaPath(final List<String> actualPath, final URI namespace, final Date revision) {
79         if (actualPath == null) {
80             throw new IllegalArgumentException("The actual path List MUST be specified.");
81         }
82         final List<QName> pathList = new ArrayList<QName>();
83         for (final String path : actualPath) {
84             final QName qname = new QName(namespace, revision, path);
85             if (qname != null) {
86                 pathList.add(qname);
87             }
88         }
89         return new SchemaPath(pathList, true);
90     }
91 }