Bump MRI upstreams
[netconf.git] / netconf / mdsal-netconf-connector / src / main / java / org / opendaylight / netconf / mdsal / connector / ops / AbstractEdit.java
index 23e9cc2fe396773078da8c9f9847fa5319d3e5ec..5611ef88bc8badee4730abae67ce09ac8a1597d0 100644 (file)
@@ -8,30 +8,33 @@
 package org.opendaylight.netconf.mdsal.connector.ops;
 
 import com.google.common.collect.ImmutableMap;
-import java.net.URI;
+import java.io.IOException;
 import java.net.URISyntaxException;
 import java.util.Iterator;
-import java.util.Map;
 import java.util.Optional;
+import javax.xml.stream.XMLStreamException;
 import javax.xml.transform.dom.DOMSource;
 import org.opendaylight.netconf.api.DocumentedException;
-import org.opendaylight.netconf.api.DocumentedException.ErrorSeverity;
-import org.opendaylight.netconf.api.DocumentedException.ErrorTag;
-import org.opendaylight.netconf.api.DocumentedException.ErrorType;
 import org.opendaylight.netconf.api.NetconfDocumentedException;
 import org.opendaylight.netconf.api.xml.XmlElement;
 import org.opendaylight.netconf.mdsal.connector.CurrentSchemaContext;
+import org.opendaylight.yangtools.yang.common.ErrorSeverity;
+import org.opendaylight.yangtools.yang.common.ErrorTag;
+import org.opendaylight.yangtools.yang.common.ErrorType;
 import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.common.XMLNamespace;
 import org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeStreamWriter;
 import org.opendaylight.yangtools.yang.data.codec.xml.XmlParserStream;
 import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.Module;
+import org.opendaylight.yangtools.yang.model.util.SchemaInferenceStack;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.w3c.dom.Element;
 import org.w3c.dom.NodeList;
+import org.xml.sax.SAXException;
 
 abstract class AbstractEdit extends AbstractConfigOperation {
     private static final Logger LOG = LoggerFactory.getLogger(AbstractEdit.class);
@@ -44,9 +47,8 @@ abstract class AbstractEdit extends AbstractConfigOperation {
         this.schemaContext = schemaContext;
     }
 
-    @SuppressWarnings("checkstyle:IllegalCatch")
     protected void parseIntoNormalizedNode(final DataSchemaNode schemaNode, final XmlElement element,
-                                         final NormalizedNodeStreamWriter writer) throws DocumentedException {
+                                           final NormalizedNodeStreamWriter writer) throws DocumentedException {
         if (!(schemaNode instanceof ContainerSchemaNode) && !(schemaNode instanceof ListSchemaNode)) {
             // This should never happen since any edit operation on any other node type
             // should not be possible nor makes sense
@@ -54,23 +56,24 @@ abstract class AbstractEdit extends AbstractConfigOperation {
             throw new UnsupportedOperationException("implement exception if parse fails");
         }
 
-        final XmlParserStream xmlParser = XmlParserStream.create(writer, schemaContext.getCurrentContext(), schemaNode);
+        final XmlParserStream xmlParser = XmlParserStream.create(writer, SchemaInferenceStack.ofInstantiatedPath(
+            schemaContext.getCurrentContext(), schemaNode.getPath()).toInference());
         try {
             xmlParser.traverse(new DOMSource(element.getDomElement()));
-        } catch (final Exception ex) {
-            throw new NetconfDocumentedException("Error parsing input: " + ex.getMessage(), ex, ErrorType.PROTOCOL,
-                ErrorTag.MALFORMED_MESSAGE, ErrorSeverity.ERROR);
+        } catch (final XMLStreamException | URISyntaxException | IOException | SAXException ex) {
+            throw new NetconfDocumentedException("Error parsing input: " + ex.getMessage(), ex,
+                ErrorType.PROTOCOL, ErrorTag.MALFORMED_MESSAGE, ErrorSeverity.ERROR);
         }
     }
 
     protected DataSchemaNode getSchemaNodeFromNamespace(final String namespace, final XmlElement element)
         throws DocumentedException {
-        final Iterator<Module> it;
+        final Iterator<? extends Module> it;
         try {
             // Returns module with newest revision since findModuleByNamespace returns a set of modules and we only
             // need the newest one
-            it = schemaContext.getCurrentContext().findModules(new URI(namespace)).iterator();
-        } catch (final URISyntaxException e) {
+            it = schemaContext.getCurrentContext().findModules(XMLNamespace.of(namespace)).iterator();
+        } catch (final IllegalArgumentException e) {
             throw new NetconfDocumentedException("Unable to create URI for namespace : " + namespace, e,
                 ErrorType.APPLICATION, ErrorTag.INVALID_VALUE, ErrorSeverity.ERROR);
         }
@@ -85,13 +88,10 @@ abstract class AbstractEdit extends AbstractConfigOperation {
         final String elementName = element.getName();
         final Optional<DataSchemaNode> schemaNode = module.findDataChildByName(QName.create(module.getQNameModule(),
                     element.getName()));
-        if (!schemaNode.isPresent()) {
+        if (schemaNode.isEmpty()) {
             throw new DocumentedException(
-                "Unable to find node " + elementName + " with namespace: " + namespace + "in module: "
-                    + module.toString(),
-                ErrorType.APPLICATION,
-                ErrorTag.UNKNOWN_NAMESPACE,
-                ErrorSeverity.ERROR);
+                "Unable to find node " + elementName + " with namespace: " + namespace + " in module: " + module,
+                ErrorType.APPLICATION, ErrorTag.UNKNOWN_NAMESPACE, ErrorSeverity.ERROR);
         }
 
         return schemaNode.get();
@@ -102,10 +102,8 @@ abstract class AbstractEdit extends AbstractConfigOperation {
         final NodeList elementsByTagName = getElementsByTagName(operationElement, TARGET_KEY);
         // Direct lookup instead of using XmlElement class due to performance
         if (elementsByTagName.getLength() == 0) {
-            final Map<String, String> errorInfo = ImmutableMap.of("bad-attribute", TARGET_KEY, "bad-element",
-                operationName);
             throw new DocumentedException("Missing target element", ErrorType.PROTOCOL, ErrorTag.MISSING_ATTRIBUTE,
-                ErrorSeverity.ERROR, errorInfo);
+                ErrorSeverity.ERROR, ImmutableMap.of("bad-attribute", TARGET_KEY, "bad-element", operationName));
         } else if (elementsByTagName.getLength() > 1) {
             throw new DocumentedException("Multiple target elements", ErrorType.RPC, ErrorTag.UNKNOWN_ATTRIBUTE,
                 ErrorSeverity.ERROR);