Add YANG/YIN namespace string literals 16/68416/2
authorRobert Varga <robert.varga@pantheon.tech>
Mon, 19 Feb 2018 15:22:54 +0000 (16:22 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Mon, 19 Feb 2018 17:38:34 +0000 (18:38 +0100)
Interacting with Java XML machinery requires the use of Strings
for namespaces. It is useful to implement javax.xml.NamespaceContext
with switch() statement, which unfortunately can only work on explicit
string literals. Expose these literals, improving the ergonomics.

Change-Id: I534d2a6e13960ba7587bfe77ed581e8593e65a17
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
yang/yang-common/src/main/java/org/opendaylight/yangtools/yang/common/YangConstants.java
yang/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/stmt/ArgumentUtils.java

index 27a720e908668e375d825e017d2cbffac7d333e4..3c4f68b3c72661749b19a92e5529a4796a9017d8 100644 (file)
@@ -30,9 +30,14 @@ public final class YangConstants {
     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.
@@ -55,9 +60,14 @@ public final class YangConstants {
     public static final String RFC6020_YIN_MEDIA_TYPE = "application/xml+yin";
 
     /**
-     * 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 String format.
+     */
+    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, 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.
index 7a2b0c843627b5fead0f341c73b379021162a343..e4cbe0dda583c18ebedaf7e317e98790f08f8cff 100644 (file)
@@ -7,7 +7,7 @@
  */
 package org.opendaylight.yangtools.yang.parser.rfc7950.stmt;
 
-import static org.opendaylight.yangtools.yang.common.YangConstants.RFC6020_YANG_NAMESPACE;
+import static org.opendaylight.yangtools.yang.common.YangConstants.RFC6020_YANG_NAMESPACE_STRING;
 import static org.opendaylight.yangtools.yang.common.YangConstants.YANG_XPATH_FUNCTIONS_PREFIX;
 
 import com.google.common.annotations.Beta;
@@ -105,7 +105,7 @@ public final class ArgumentUtils {
     public static RevisionAwareXPath parseXPath(final StmtContext<?, ?, ?> ctx, final String path) {
         final XPath xPath = XPATH_FACTORY.get().newXPath();
         xPath.setNamespaceContext(StmtNamespaceContext.create(ctx,
-                ImmutableBiMap.of(RFC6020_YANG_NAMESPACE.toString(), YANG_XPATH_FUNCTIONS_PREFIX)));
+                ImmutableBiMap.of(RFC6020_YANG_NAMESPACE_STRING, YANG_XPATH_FUNCTIONS_PREFIX)));
 
         final String trimmed = trimSingleLastSlashFromXPath(path);
         try {