Introduce {Qualified,Unqualified}.of()
[yangtools.git] / common / yang-common / src / main / java / org / opendaylight / yangtools / yang / common / YangConstants.java
1 /*
2  * Copyright (c) 2015 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.common;
9
10 import java.net.URI;
11 import org.eclipse.jdt.annotation.NonNullByDefault;
12 import org.opendaylight.yangtools.yang.common.UnresolvedQName.Unqualified;
13
14 /**
15  * Constant definitions present in RFC documents related to the YANG language.
16  */
17 @NonNullByDefault
18 public final class YangConstants {
19     /**
20      * YANG File Extension, as defined in <a href="https://tools.ietf.org/html/rfc6020#section-14.1">RFC6020</a>.
21      */
22     public static final String RFC6020_YANG_FILE_EXTENSION = ".yang";
23
24     /**
25      * YANG Media Type, as defined in <a href="https://tools.ietf.org/html/rfc6020#section-14.1">RFC6020</a>.
26      */
27     public static final String RFC6020_YANG_MAC_FILE_TYPE = "TEXT";
28
29
30     /**
31      * YANG Media Type, as defined in h<a href="https://tools.ietf.org/html/rfc6020#section-14.1">RFC6020</a>.
32      */
33     public static final String RFC6020_YANG_MEDIA_TYPE = "application/yang";
34
35     /**
36      * YANG namespace, as defined in https://tools.ietf.org/html/rfc6020#section-14, in String format.
37      */
38     public static final String RFC6020_YANG_NAMESPACE_STRING = "urn:ietf:params:xml:ns:yang:1";
39
40     /**
41      * YANG namespace, as defined in https://tools.ietf.org/html/rfc6020#section-14, in URI format.
42      */
43     public static final XMLNamespace RFC6020_YANG_NAMESPACE = XMLNamespace.of(RFC6020_YANG_NAMESPACE_STRING).intern();
44
45     /**
46      * Base QNameModule for all YANG statements.
47      */
48     public static final QNameModule RFC6020_YANG_MODULE = QNameModule.create(RFC6020_YANG_NAMESPACE).intern();
49
50     /**
51      * YIN File Extension, as defined in <a href="https://tools.ietf.org/html/rfc6020#section-14.2">RFC6020</a>.
52      */
53     public static final String RFC6020_YIN_FILE_EXTENSION = ".yin";
54
55     /**
56      * YANG Media Type, as defined in <a href="https://tools.ietf.org/html/rfc6020#section-14.1">RFC6020</a>.
57      */
58     public static final String RFC6020_MAC_FILE_TYPE = "TEXT";
59
60     /**
61      * YANG Media Type, as defined in <a href="https://tools.ietf.org/html/rfc6020#section-14.2">RFC6020</a>.
62      */
63     public static final String RFC6020_YIN_MEDIA_TYPE = "application/yin+xml";
64
65     /**
66      * YIN namespace, as defined in https://tools.ietf.org/html/rfc6020#section-14, in String format.
67      */
68     public static final String RFC6020_YIN_NAMESPACE_STRING = "urn:ietf:params:xml:ns:yang:yin:1";
69
70     /**
71      * YIN namespace, as defined in https://tools.ietf.org/html/rfc6020#section-14, in URI format.
72      */
73     public static final XMLNamespace RFC6020_YIN_NAMESPACE = XMLNamespace.of(RFC6020_YIN_NAMESPACE_STRING).intern();
74
75     /**
76      * Base QNameModule for all YIN statements.
77      */
78     public static final QNameModule RFC6020_YIN_MODULE = QNameModule.create(RFC6020_YIN_NAMESPACE).intern();
79
80     /**
81      * YANG Library NETCONF Capability, as defined in https://tools.ietf.org/html/rfc7950#section-16.
82      */
83     public static final URI RFC7950_YANG_LIBRARY_CAPABILITY =
84         URI.create("urn:ietf:params:netconf:capability:yang-library:1.0");
85
86     /**
87      * Prefix for YANG-specific XPath functions.
88      */
89     public static final String YANG_XPATH_FUNCTIONS_PREFIX = "yang";
90
91     /**
92      * NETCONF protocol elements' namespace, as defined in
93      * <a href="https://datatracker.ietf.org/doc/html/rfc4741#section-3.1">RFC4741 section 3.1</a>, in String format.
94      */
95     public static final String NETCONF_NAMESPACE_STRING = "urn:ietf:params:xml:ns:netconf:base:1.0";
96
97     /**
98      * NETCONF protocol elements' namespace, as defined in
99      * <a href="https://datatracker.ietf.org/doc/html/rfc4741#section-3.1">RFC4741 section 3.1</a>, in String format.
100      */
101     public static final XMLNamespace NETCONF_NAMESPACE = XMLNamespace.of(NETCONF_NAMESPACE_STRING).intern();
102
103     /**
104      * NETCONF namespace bound to YANG through
105      * <a href="https://datatracker.ietf.org/doc/html/rfc6241#section-10.3">ietf-netconf@2011-06-01.yang</a>.
106      */
107     public static final QNameModule RFC6241_YANG_MODULE =
108         QNameModule.create(NETCONF_NAMESPACE, Revision.of("2011-06-01")).intern();
109
110     /**
111      * {@code bad-attribute}, value is the name of the attribute.
112      */
113     public static final QName BAD_ATTRIBUTE_QNAME = QName.create(RFC6241_YANG_MODULE, "bad-attribute").intern();
114     /**
115      * {@code bad-element}, value is the name of the element.
116      */
117     public static final QName BAD_ELEMENT_QNAME = QName.create(RFC6241_YANG_MODULE, "bad-element").intern();
118     /**
119      * {@code bad-namespace}, value is the name of the namespace.
120      */
121     public static final QName BAD_NAMESPACE_QNAME = QName.create(RFC6241_YANG_MODULE, "bad-namespace").intern();
122     /**
123      * {@code session-id}, value the session identifier, as modeled in {@code SessionIdOrZero}.
124      */
125     public static final QName SESSION_ID_QNAME = QName.create(RFC6241_YANG_MODULE, "session-id").intern();
126     @Deprecated(since = "RFC6241")
127     public static final QName ERR_ELEMENT_QNAME = QName.create(RFC6241_YANG_MODULE, "err-element").intern();
128     @Deprecated(since = "RFC6241")
129     public static final QName NOOP_ELEMENT_QNAME = QName.create(RFC6241_YANG_MODULE, "noop-element").intern();
130     @Deprecated(since = "RFC6241")
131     public static final QName OK_ELEMENT_QNAME = QName.create(RFC6241_YANG_MODULE, "ok-element").intern();
132     /**
133      * {@code missing-choice} as defined in
134      * <a href="https://datatracker.ietf.org/doc/html/rfc6020#section-13.7">RFC6020, section 13.7</a>.
135      */
136     public static final QName MISSING_CHOICE_QNAME = QName.create(RFC6020_YANG_MODULE, "missing-choice").intern();
137     /**
138      * {@code non-unique} as defined in
139      * <a href="https://datatracker.ietf.org/doc/html/rfc6020#section-13.1">RFC6020, section 13.1</a>.
140      */
141     public static final QName NON_UNIQUE_QNAME = QName.create(RFC6020_YANG_MODULE, "non-unique").intern();
142
143     // Dummy template UnqualifiedQName. These are never leaked, but are used for efficient instantiation via
144     // UnqualifiedQName#bindTo()
145     private static final Unqualified DUMMY_OPERATION_INPUT = Unqualified.of("input");
146     private static final Unqualified DUMMY_OPERATION_OUTPUT = Unqualified.of("output");
147
148     private YangConstants() {
149         // Hidden on purpose
150     }
151
152     /**
153      * Create a {@link QName} representing the 'input' statement of an operation (RPC or action) within specified
154      * {@link QNameModule}.
155      *
156      * @param module Desired module
157      * @return A QName representing action or RPC input.
158      * @throws NullPointerException if {@code module} is null
159      */
160     public static QName operationInputQName(final QNameModule module) {
161         return DUMMY_OPERATION_INPUT.bindTo(module);
162     }
163
164     /**
165      * Create a {@link QName} representing the 'output' statement of an operation (RPC or action) within specified
166      * {@link QNameModule}.
167      *
168      * @param module Desired module
169      * @return A QName representing action or RPC output.
170      * @throws NullPointerException if {@code module} is null
171      */
172     public static QName operationOutputQName(final QNameModule module) {
173         return DUMMY_OPERATION_OUTPUT.bindTo(module);
174     }
175 }