Add netconf.api.NamespaceURN
[netconf.git] / protocol / netconf-api / src / main / java / org / opendaylight / netconf / api / messages / HelloMessage.java
index 57c8e33af81bdbd17c9273efe945ff7feedda4c8..4409adaaa507fd7991c854f9bef2697c293b2538 100644 (file)
@@ -10,6 +10,7 @@ package org.opendaylight.netconf.api.messages;
 import com.google.common.collect.Sets;
 import java.util.Optional;
 import java.util.Set;
+import org.opendaylight.netconf.api.NamespaceURN;
 import org.opendaylight.netconf.api.NetconfMessage;
 import org.opendaylight.netconf.api.xml.XmlElement;
 import org.opendaylight.netconf.api.xml.XmlNetconfConstants;
@@ -47,7 +48,7 @@ public final class HelloMessage extends NetconfMessage {
         if (!isHelloMessage(doc)) {
             throw new IllegalArgumentException(String.format(
                 "Hello message invalid format, should contain %s tag from namespace %s, but is: %s", HELLO_TAG,
-                XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0, XmlUtil.toString(doc)));
+                NamespaceURN.BASE, XmlUtil.toString(doc)));
         }
     }
 
@@ -58,14 +59,11 @@ public final class HelloMessage extends NetconfMessage {
 
     private static Document createHelloMessageDoc(final Iterable<String> capabilities) {
         Document doc = UntrustedXML.newDocumentBuilder().newDocument();
-        Element helloElement = doc.createElementNS(XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0,
-                HELLO_TAG);
-        Element capabilitiesElement = doc.createElementNS(XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0,
-                XmlNetconfConstants.CAPABILITIES);
+        Element helloElement = doc.createElementNS(NamespaceURN.BASE, HELLO_TAG);
+        Element capabilitiesElement = doc.createElementNS(NamespaceURN.BASE, XmlNetconfConstants.CAPABILITIES);
 
         for (String capability : Sets.newHashSet(capabilities)) {
-            Element capElement = doc.createElementNS(XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0,
-                    XmlNetconfConstants.CAPABILITY);
+            Element capElement = doc.createElementNS(NamespaceURN.BASE, XmlNetconfConstants.CAPABILITY);
             capElement.setTextContent(capability);
             capabilitiesElement.appendChild(capElement);
         }
@@ -78,8 +76,7 @@ public final class HelloMessage extends NetconfMessage {
 
     public static HelloMessage createServerHello(final Set<String> capabilities, final SessionIdType sessionId) {
         Document doc = createHelloMessageDoc(capabilities);
-        Element sessionIdElement = doc.createElementNS(XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0,
-                XmlNetconfConstants.SESSION_ID);
+        Element sessionIdElement = doc.createElementNS(NamespaceURN.BASE, XmlNetconfConstants.SESSION_ID);
         sessionIdElement.setTextContent(sessionId.getValue().toCanonicalString());
         doc.getDocumentElement().appendChild(sessionIdElement);
         return new HelloMessage(doc);
@@ -97,6 +94,6 @@ public final class HelloMessage extends NetconfMessage {
 
         final var namespace = element.namespace();
         // accept even if hello has no namespace
-        return namespace == null || XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0.equals(namespace);
+        return namespace == null || NamespaceURN.BASE.equals(namespace);
     }
 }