Move netconf.util.xml to netconf-client 41/105741/4
authorRobert Varga <robert.varga@pantheon.tech>
Fri, 28 Apr 2023 14:48:17 +0000 (16:48 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Fri, 28 Apr 2023 15:07:27 +0000 (17:07 +0200)
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 <robert.varga@pantheon.tech>
protocol/netconf-client/src/main/java/org/opendaylight/netconf/client/HardcodedNamespaceResolver.java [moved from protocol/netconf-util/src/main/java/org/opendaylight/netconf/util/xml/HardcodedNamespaceResolver.java with 57% similarity]
protocol/netconf-client/src/main/java/org/opendaylight/netconf/client/NetconfClientSessionNegotiator.java
protocol/netconf-client/src/main/java/org/opendaylight/netconf/client/XMLNetconfUtil.java [moved from protocol/netconf-util/src/main/java/org/opendaylight/netconf/util/xml/XMLNetconfUtil.java with 89% similarity]
protocol/netconf-client/src/test/java/org/opendaylight/netconf/client/HardcodedNamespaceResolverTest.java [moved from protocol/netconf-util/src/test/java/org/opendaylight/netconf/util/xml/HardcodedNamespaceResolverTest.java with 96% similarity]
protocol/netconf-client/src/test/java/org/opendaylight/netconf/client/XMLNetconfUtilTest.java [moved from protocol/netconf-util/src/test/java/org/opendaylight/netconf/util/xml/XMLNetconfUtilTest.java with 96% similarity]

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 ceb50b1920cf09ba49fb30e9ad2441f745bd8387..b7eb4e4b34123a456834864e5d63725e7abe35e9 100644 (file)
@@ -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<String/* prefix */, String/* namespace */> prefixesToNamespaces;
+final class HardcodedNamespaceResolver implements NamespaceContext {
+    private final Map<String, String> prefixesToNamespaces;
 
-    public HardcodedNamespaceResolver(final String prefix, final String namespace) {
-        this(ImmutableMap.of(prefix, namespace));
-    }
-
-    public HardcodedNamespaceResolver(final Map<String, String> 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
index b074ac70a90f5797141142a22a2f48c4eadb04af..042572c6747574cedd7c45ad442de87efbc40d7f 100644 (file)
@@ -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;
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 25493ee7d7bc7473776151f0756ca871c888c98d..a819edf4582cb6120e35afaccfd0c505465874c1 100644 (file)
@@ -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);
         }
     }
-
 }
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 aae32b0e732d29c6f20ce4bd2220f3b9d4f1306b..5ee53cf0a99df5f52db349028e220f8315bec8d7 100644 (file)
@@ -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;
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 e9e572148e44189a3e4695c636c405e28d03cdd2..2417d1e8654e6b20779fb73f52f7cef37ac20578 100644 (file)
@@ -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;