4688f58aa6587c1a8a590bb9eb6a9fbda9373757
[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
26     /**
27      * Construct QName for Built-in base Yang type. The namespace for built-in
28      * base yang types is defined as: urn:ietf:params:xml:ns:yang:1
29      * 
30      * @param typeName
31      *            yang type name
32      * @return built-in base yang type QName.
33      */
34     public static QName constructQName(final String typeName) {
35         return new QName(BASE_TYPES_NAMESPACE, typeName);
36     }
37
38     /**
39      * Creates Schema Path from Qname.
40      * 
41      * @param typeName
42      *            yang type QName
43      * @return Schema Path from Qname.
44      */
45     public static SchemaPath schemaPath(final QName typeName) {
46         List<QName> pathList = Collections.singletonList(typeName);
47         return new SchemaPath(pathList, true);
48     }
49
50     /**
51      * Creates Schema Path from List of partial paths defined as Strings, module
52      * Namespace and module latest Revision Date.
53      * 
54      * @param actualPath
55      *            List of partial paths
56      * @param namespace
57      *            Module Namespace
58      * @param revision
59      *            Revision Date
60      * @return Schema Path
61      */
62     public static SchemaPath schemaPath(final List<String> actualPath, final URI namespace, final Date revision) {
63         if (actualPath == null) {
64             throw new IllegalArgumentException("The actual path List MUST be specified.");
65         }
66         final List<QName> pathList = new ArrayList<QName>();
67         for (final String path : actualPath) {
68             final QName qname = new QName(namespace, revision, path);
69             if (qname != null) {
70                 pathList.add(qname);
71             }
72         }
73         return new SchemaPath(pathList, true);
74     }
75 }