Fix CanonicalValueViolation.getMessage()
[yangtools.git] / yang / yang-common / src / main / java / org / opendaylight / yangtools / yang / common / YangConstants.java
index 27a720e908668e375d825e017d2cbffac7d333e4..2445c2ae2014e71a5a44b43f270ddfbbfd3aa266 100644 (file)
@@ -8,31 +8,38 @@
 package org.opendaylight.yangtools.yang.common;
 
 import java.net.URI;
+import org.eclipse.jdt.annotation.NonNullByDefault;
 
 /**
  * Constant definitions present in RFC documents related to the YANG language.
  */
+@NonNullByDefault
 public final class YangConstants {
     /**
-     * YANG File Extension, as defined in https://tools.ietf.org/html/rfc6020#section-14.1.
+     * YANG File Extension, as defined in <a href="https://tools.ietf.org/html/rfc6020#section-14.1">RFC6020</a>.
      */
     public static final String RFC6020_YANG_FILE_EXTENSION = ".yang";
 
     /**
-     * YANG Media Type, as defined in https://tools.ietf.org/html/rfc6020#section-14.1.
+     * YANG Media Type, as defined in <a href="https://tools.ietf.org/html/rfc6020#section-14.1">RFC6020</a>.
      */
     public static final String RFC6020_YANG_MAC_FILE_TYPE = "TEXT";
 
 
     /**
-     * YANG Media Type, as defined in https://tools.ietf.org/html/rfc6020#section-14.1.
+     * YANG Media Type, as defined in h<a href="https://tools.ietf.org/html/rfc6020#section-14.1">RFC6020</a>.
      */
     public static final String RFC6020_YANG_MEDIA_TYPE = "application/yang";
 
     /**
-     * YANG namespace, as defined in https://tools.ietf.org/html/rfc6020#section-14.
+     * YANG namespace, as defined in https://tools.ietf.org/html/rfc6020#section-14, in String format.
      */
-    public static final URI RFC6020_YANG_NAMESPACE = URI.create("urn:ietf:params:xml:ns:yang:1");
+    public static final String RFC6020_YANG_NAMESPACE_STRING = "urn:ietf:params:xml:ns:yang:1";
+
+    /**
+     * YANG namespace, as defined in https://tools.ietf.org/html/rfc6020#section-14, in URI format.
+     */
+    public static final URI RFC6020_YANG_NAMESPACE = URI.create(RFC6020_YANG_NAMESPACE_STRING);
 
     /**
      * Base QNameModule for all YANG statements.
@@ -40,24 +47,29 @@ public final class YangConstants {
     public static final QNameModule RFC6020_YANG_MODULE = QNameModule.create(RFC6020_YANG_NAMESPACE).intern();
 
     /**
-     * YIN File Extension, as defined in https://tools.ietf.org/html/rfc6020#section-14.2.
+     * YIN File Extension, as defined in <a href="https://tools.ietf.org/html/rfc6020#section-14.2">RFC6020</a>.
      */
     public static final String RFC6020_YIN_FILE_EXTENSION = ".yin";
 
     /**
-     * YANG Media Type, as defined in https://tools.ietf.org/html/rfc6020#section-14.1.
+     * YANG Media Type, as defined in <a href="https://tools.ietf.org/html/rfc6020#section-14.1">RFC6020</a>.
      */
     public static final String RFC6020_MAC_FILE_TYPE = "TEXT";
 
     /**
-     * YANG Media Type, as defined in https://tools.ietf.org/html/rfc6020#section-14.1.
+     * YANG Media Type, as defined in <a href="https://tools.ietf.org/html/rfc6020#section-14.2">RFC6020</a>.
+     */
+    public static final String RFC6020_YIN_MEDIA_TYPE = "application/yin+xml";
+
+    /**
+     * YIN namespace, as defined in https://tools.ietf.org/html/rfc6020#section-14, in String format.
      */
-    public static final String RFC6020_YIN_MEDIA_TYPE = "application/xml+yin";
+    public static final String RFC6020_YIN_NAMESPACE_STRING = "urn:ietf:params:xml:ns:yang:yin:1";
 
     /**
-     * YIN namespace, as defined in https://tools.ietf.org/html/rfc6020#section-14.
+     * YIN namespace, as defined in https://tools.ietf.org/html/rfc6020#section-14, in URI format.
      */
-    public static final URI RFC6020_YIN_NAMESPACE = URI.create("urn:ietf:params:xml:ns:yang:yin:1");
+    public static final URI RFC6020_YIN_NAMESPACE = URI.create(RFC6020_YIN_NAMESPACE_STRING);
 
     /**
      * Base QNameModule for all YIN statements.
@@ -75,7 +87,36 @@ public final class YangConstants {
      */
     public static final String YANG_XPATH_FUNCTIONS_PREFIX = "yang";
 
+    // Dummy template UnqualifiedQName. These are never leaked, but are used for efficient instantiation via
+    // UnqualifiedQName#bindTo()
+    private static final UnqualifiedQName DUMMY_OPERATION_INPUT = UnqualifiedQName.of("input");
+    private static final UnqualifiedQName DUMMY_OPERATION_OUTPUT = UnqualifiedQName.of("output");
+
     private YangConstants() {
-        throw new UnsupportedOperationException("Utility class");
+        // Hidden on purpose
+    }
+
+    /**
+     * Create a {@link QName} representing the 'input' statement of an operation (RPC or action) within specified
+     * {@link QNameModule}.
+     *
+     * @param module Desired module
+     * @return A QName representing action or RPC input.
+     * @throws NullPointerException if {@code module} is null
+     */
+    public static QName operationInputQName(final QNameModule module) {
+        return DUMMY_OPERATION_INPUT.bindTo(module);
+    }
+
+    /**
+     * Create a {@link QName} representing the 'output' statement of an operation (RPC or action) within specified
+     * {@link QNameModule}.
+     *
+     * @param module Desired module
+     * @return A QName representing action or RPC output.
+     * @throws NullPointerException if {@code module} is null
+     */
+    public static QName operationOutputQName(final QNameModule module) {
+        return DUMMY_OPERATION_OUTPUT.bindTo(module);
     }
 }