From 20216a64f35c0b0ea7a1911df5fbed90e1f045b5 Mon Sep 17 00:00:00 2001 From: Robert Varga Date: Mon, 19 Feb 2018 16:22:54 +0100 Subject: [PATCH] Add YANG/YIN namespace string literals 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 --- .../yangtools/yang/common/YangConstants.java | 18 ++++++++++++++---- .../parser/rfc7950/stmt/ArgumentUtils.java | 4 ++-- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/yang/yang-common/src/main/java/org/opendaylight/yangtools/yang/common/YangConstants.java b/yang/yang-common/src/main/java/org/opendaylight/yangtools/yang/common/YangConstants.java index 27a720e908..3c4f68b3c7 100644 --- a/yang/yang-common/src/main/java/org/opendaylight/yangtools/yang/common/YangConstants.java +++ b/yang/yang-common/src/main/java/org/opendaylight/yangtools/yang/common/YangConstants.java @@ -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. diff --git a/yang/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/stmt/ArgumentUtils.java b/yang/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/stmt/ArgumentUtils.java index 7a2b0c8436..e4cbe0dda5 100644 --- a/yang/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/stmt/ArgumentUtils.java +++ b/yang/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/stmt/ArgumentUtils.java @@ -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 { -- 2.36.6