From: Robert Varga Date: Fri, 28 Apr 2023 14:48:17 +0000 (+0200) Subject: Move netconf.util.xml to netconf-client X-Git-Tag: v6.0.0~188 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=commitdiff_plain;h=b6e4c66f9cfd4f7e9854b47ad4c17d7e8c068493;p=netconf.git Move netconf.util.xml to netconf-client This package is only used internally by netconf-client, move it to its sole user and clean up HardcodedNamespaceResolver to use Map.of(). JIRA: NETCONF-1002 Change-Id: I219c849362fb4b02297fd8fa243a0ee171f00f14 Signed-off-by: Robert Varga --- diff --git a/protocol/netconf-util/src/main/java/org/opendaylight/netconf/util/xml/HardcodedNamespaceResolver.java b/protocol/netconf-client/src/main/java/org/opendaylight/netconf/client/HardcodedNamespaceResolver.java similarity index 57% rename from protocol/netconf-util/src/main/java/org/opendaylight/netconf/util/xml/HardcodedNamespaceResolver.java rename to protocol/netconf-client/src/main/java/org/opendaylight/netconf/client/HardcodedNamespaceResolver.java index ceb50b1920..b7eb4e4b34 100644 --- a/protocol/netconf-util/src/main/java/org/opendaylight/netconf/util/xml/HardcodedNamespaceResolver.java +++ b/protocol/netconf-client/src/main/java/org/opendaylight/netconf/client/HardcodedNamespaceResolver.java @@ -5,24 +5,18 @@ * terms of the Eclipse Public License v1.0 which accompanies this distribution, * and is available at http://www.eclipse.org/legal/epl-v10.html */ -package org.opendaylight.netconf.util.xml; +package org.opendaylight.netconf.client; -import com.google.common.collect.ImmutableMap; -import java.util.Collections; import java.util.Iterator; import java.util.Map; import javax.xml.namespace.NamespaceContext; // http://www.ibm.com/developerworks/library/x-nmspccontext/ -public class HardcodedNamespaceResolver implements NamespaceContext { - private final Map prefixesToNamespaces; +final class HardcodedNamespaceResolver implements NamespaceContext { + private final Map prefixesToNamespaces; - public HardcodedNamespaceResolver(final String prefix, final String namespace) { - this(ImmutableMap.of(prefix, namespace)); - } - - public HardcodedNamespaceResolver(final Map prefixesToNamespaces) { - this.prefixesToNamespaces = Collections.unmodifiableMap(prefixesToNamespaces); + HardcodedNamespaceResolver(final String prefix, final String namespace) { + prefixesToNamespaces = Map.of(prefix, namespace); } /** @@ -34,11 +28,11 @@ public class HardcodedNamespaceResolver implements NamespaceContext { */ @Override public String getNamespaceURI(final String prefix) { - if (prefixesToNamespaces.containsKey(prefix)) { - return prefixesToNamespaces.get(prefix); + final var namespace = prefixesToNamespaces.get(prefix); + if (namespace == null) { + throw new IllegalStateException("Prefix mapping not found for " + prefix); } - - throw new IllegalStateException("Prefix mapping not found for " + prefix); + return namespace; } @Override diff --git a/protocol/netconf-client/src/main/java/org/opendaylight/netconf/client/NetconfClientSessionNegotiator.java b/protocol/netconf-client/src/main/java/org/opendaylight/netconf/client/NetconfClientSessionNegotiator.java index b074ac70a9..042572c674 100644 --- a/protocol/netconf-client/src/main/java/org/opendaylight/netconf/client/NetconfClientSessionNegotiator.java +++ b/protocol/netconf-client/src/main/java/org/opendaylight/netconf/client/NetconfClientSessionNegotiator.java @@ -28,7 +28,6 @@ import org.opendaylight.netconf.api.xml.XmlUtil; import org.opendaylight.netconf.nettyutil.AbstractChannelInitializer; import org.opendaylight.netconf.nettyutil.AbstractNetconfSessionNegotiator; import org.opendaylight.netconf.nettyutil.handler.exi.NetconfStartExiMessage; -import org.opendaylight.netconf.util.xml.XMLNetconfUtil; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.w3c.dom.Document; diff --git a/protocol/netconf-util/src/main/java/org/opendaylight/netconf/util/xml/XMLNetconfUtil.java b/protocol/netconf-client/src/main/java/org/opendaylight/netconf/client/XMLNetconfUtil.java similarity index 89% rename from protocol/netconf-util/src/main/java/org/opendaylight/netconf/util/xml/XMLNetconfUtil.java rename to protocol/netconf-client/src/main/java/org/opendaylight/netconf/client/XMLNetconfUtil.java index 25493ee7d7..a819edf458 100644 --- a/protocol/netconf-util/src/main/java/org/opendaylight/netconf/util/xml/XMLNetconfUtil.java +++ b/protocol/netconf-client/src/main/java/org/opendaylight/netconf/client/XMLNetconfUtil.java @@ -5,7 +5,7 @@ * terms of the Eclipse Public License v1.0 which accompanies this distribution, * and is available at http://www.eclipse.org/legal/epl-v10.html */ -package org.opendaylight.netconf.util.xml; +package org.opendaylight.netconf.client; import javax.xml.namespace.NamespaceContext; import javax.xml.xpath.XPath; @@ -14,7 +14,7 @@ import javax.xml.xpath.XPathExpressionException; import javax.xml.xpath.XPathFactory; import org.opendaylight.netconf.api.xml.XmlNetconfConstants; -public final class XMLNetconfUtil { +final class XMLNetconfUtil { private static final XPathFactory FACTORY = XPathFactory.newInstance(); private static final NamespaceContext NS_CONTEXT = new HardcodedNamespaceResolver("netconf", XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0); @@ -23,7 +23,7 @@ public final class XMLNetconfUtil { // Hidden on purpose } - public static XPathExpression compileXPath(final String xpath) { + static XPathExpression compileXPath(final String xpath) { final XPath newXPath = FACTORY.newXPath(); newXPath.setNamespaceContext(NS_CONTEXT); try { @@ -32,5 +32,4 @@ public final class XMLNetconfUtil { throw new IllegalStateException("Error while compiling xpath expression " + xpath, e); } } - } diff --git a/protocol/netconf-util/src/test/java/org/opendaylight/netconf/util/xml/HardcodedNamespaceResolverTest.java b/protocol/netconf-client/src/test/java/org/opendaylight/netconf/client/HardcodedNamespaceResolverTest.java similarity index 96% rename from protocol/netconf-util/src/test/java/org/opendaylight/netconf/util/xml/HardcodedNamespaceResolverTest.java rename to protocol/netconf-client/src/test/java/org/opendaylight/netconf/client/HardcodedNamespaceResolverTest.java index aae32b0e73..5ee53cf0a9 100644 --- a/protocol/netconf-util/src/test/java/org/opendaylight/netconf/util/xml/HardcodedNamespaceResolverTest.java +++ b/protocol/netconf-client/src/test/java/org/opendaylight/netconf/client/HardcodedNamespaceResolverTest.java @@ -5,7 +5,7 @@ * terms of the Eclipse Public License v1.0 which accompanies this distribution, * and is available at http://www.eclipse.org/legal/epl-v10.html */ -package org.opendaylight.netconf.util.xml; +package org.opendaylight.netconf.client; import static org.hamcrest.CoreMatchers.startsWith; import static org.hamcrest.MatcherAssert.assertThat; diff --git a/protocol/netconf-util/src/test/java/org/opendaylight/netconf/util/xml/XMLNetconfUtilTest.java b/protocol/netconf-client/src/test/java/org/opendaylight/netconf/client/XMLNetconfUtilTest.java similarity index 96% rename from protocol/netconf-util/src/test/java/org/opendaylight/netconf/util/xml/XMLNetconfUtilTest.java rename to protocol/netconf-client/src/test/java/org/opendaylight/netconf/client/XMLNetconfUtilTest.java index e9e572148e..2417d1e865 100644 --- a/protocol/netconf-util/src/test/java/org/opendaylight/netconf/util/xml/XMLNetconfUtilTest.java +++ b/protocol/netconf-client/src/test/java/org/opendaylight/netconf/client/XMLNetconfUtilTest.java @@ -5,7 +5,7 @@ * terms of the Eclipse Public License v1.0 which accompanies this distribution, * and is available at http://www.eclipse.org/legal/epl-v10.html */ -package org.opendaylight.netconf.util.xml; +package org.opendaylight.netconf.client; import static org.hamcrest.CoreMatchers.startsWith; import static org.hamcrest.MatcherAssert.assertThat;