Remove NetconfUtil.newWriter() 36/105736/3
authorRobert Varga <robert.varga@pantheon.tech>
Fri, 28 Apr 2023 13:35:46 +0000 (15:35 +0200)
committerIvan Hrasko <ivan.hrasko@pantheon.tech>
Mon, 22 May 2023 06:40:58 +0000 (06:40 +0000)
This is a internal utility method which is no longer needed, as YANG
tools correctly handles null path.

Change-Id: Id7e7754f33fe76eb2a68eb0a78cbe54b67594f6d
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
plugins/netconf-common-mdsal/src/main/java/org/opendaylight/netconf/common/mdsal/NormalizedDataUtil.java

index 072d1b096f8b3af0c7e883364cd2aa65760a2294..d302a93ec01dc95bf90f35661918a18aee2d080b 100644 (file)
@@ -19,7 +19,6 @@ import javax.xml.stream.XMLStreamException;
 import javax.xml.stream.XMLStreamWriter;
 import javax.xml.transform.dom.DOMResult;
 import javax.xml.transform.dom.DOMSource;
-import org.eclipse.jdt.annotation.NonNull;
 import org.eclipse.jdt.annotation.Nullable;
 import org.opendaylight.netconf.api.xml.XmlUtil;
 import org.opendaylight.yangtools.rfc7952.data.api.NormalizedMetadata;
@@ -130,7 +129,7 @@ public final class NormalizedDataUtil {
     public static void writeNormalizedNode(final NormalizedNode normalized, final DOMResult result,
             final EffectiveModelContext context, final @Nullable Absolute path) throws IOException, XMLStreamException {
         final XMLStreamWriter xmlWriter = XML_FACTORY.createXMLStreamWriter(result);
-        try (var streamWriter = newWriter(xmlWriter, context, path);
+        try (var streamWriter = XMLStreamNormalizedNodeStreamWriter.create(xmlWriter, context, path);
              var writer = NormalizedNodeWriter.forStreamWriter(streamWriter)) {
             writer.write(normalized);
             writer.flush();
@@ -160,7 +159,7 @@ public final class NormalizedDataUtil {
 
         final XMLStreamWriter xmlWriter = XML_FACTORY.createXMLStreamWriter(result);
         XML_NAMESPACE_SETTER.initializeNamespace(xmlWriter);
-        try (var streamWriter = newWriter(xmlWriter, context, path);
+        try (var streamWriter = XMLStreamNormalizedNodeStreamWriter.create(xmlWriter, context, path);
              var writer = NormalizedMetadataWriter.forStreamWriter(streamWriter)) {
             writer.write(normalized, metadata);
             writer.flush();
@@ -183,7 +182,7 @@ public final class NormalizedDataUtil {
             final EffectiveModelContext context, final @Nullable Absolute path) throws IOException, XMLStreamException {
         final XMLStreamWriter xmlWriter = XML_FACTORY.createXMLStreamWriter(result);
         XML_NAMESPACE_SETTER.initializeNamespace(xmlWriter);
-        try (var streamWriter = newWriter(xmlWriter, context, path);
+        try (var streamWriter = XMLStreamNormalizedNodeStreamWriter.create(xmlWriter, context, path);
              var writer = new EmptyListXmlWriter(streamWriter, xmlWriter)) {
             final Iterator<PathArgument> it = query.getPathArguments().iterator();
             final PathArgument first = it.next();
@@ -215,7 +214,7 @@ public final class NormalizedDataUtil {
 
         final XMLStreamWriter xmlWriter = XML_FACTORY.createXMLStreamWriter(result);
         XML_NAMESPACE_SETTER.initializeNamespace(xmlWriter);
-        try (var streamWriter = newWriter(xmlWriter, context, path);
+        try (var streamWriter = XMLStreamNormalizedNodeStreamWriter.create(xmlWriter, context, path);
              var writer = new EmptyListXmlMetadataWriter(streamWriter, xmlWriter,
                  streamWriter.getExtensions().getInstance(StreamWriterMetadataExtension.class), metadata)) {
             final Iterator<PathArgument> it = query.getPathArguments().iterator();
@@ -244,7 +243,7 @@ public final class NormalizedDataUtil {
         }
 
         final XMLStreamWriter xmlWriter = XML_FACTORY.createXMLStreamWriter(result);
-        try (var streamWriter = newWriter(xmlWriter, context, path);
+        try (var streamWriter = XMLStreamNormalizedNodeStreamWriter.create(xmlWriter, context, path);
              var writer = new EmptyListXmlWriter(streamWriter, xmlWriter)) {
             final Iterator<PathArgument> it = query.getPathArguments().iterator();
             final PathArgument first = it.next();
@@ -280,7 +279,7 @@ public final class NormalizedDataUtil {
 
         final XMLStreamWriter xmlWriter = XML_FACTORY.createXMLStreamWriter(result);
         try {
-            try (var streamWriter = newWriter(xmlWriter, context, path);
+            try (var streamWriter = XMLStreamNormalizedNodeStreamWriter.create(xmlWriter, context, path);
                  var writer = new EmptyListXmlWriter(streamWriter, xmlWriter)) {
                 final PathArgument first = rootNode.element();
                 StreamingContext.fromSchemaAndQNameChecked(context, first.getNodeType())
@@ -399,11 +398,4 @@ public final class NormalizedDataUtil {
             final DOMSource value) throws XMLStreamException, URISyntaxException, IOException, SAXException {
         return transformDOMSourceToNormalizedNode(new EmptyMountPointContext(schemaContext), value);
     }
-
-    // FIXME: this should not be needed once we have yangtools-10.0.1.
-    private static @NonNull NormalizedNodeStreamWriter newWriter(final XMLStreamWriter writer,
-            final EffectiveModelContext context, final @Nullable Absolute path) {
-        return path == null ? XMLStreamNormalizedNodeStreamWriter.create(writer, context)
-            : XMLStreamNormalizedNodeStreamWriter.create(writer, context, path);
-    }
 }