Use DOMMountPointServiceHandler non-statically
[netconf.git] / restconf / restconf-nb-rfc8040 / src / main / java / org / opendaylight / restconf / nb / rfc8040 / jersey / providers / patch / XmlToPatchBodyReader.java
index 62cef20f5f047f5c51caa58f0a48e2df4c0903b3..8364572de4874a2e2b8ca807e07375e9805eab32 100644 (file)
@@ -17,6 +17,7 @@ import java.net.URISyntaxException;
 import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.List;
+import java.util.Locale;
 import javax.annotation.Nonnull;
 import javax.ws.rs.Consumes;
 import javax.ws.rs.WebApplicationException;
@@ -33,9 +34,12 @@ import org.opendaylight.restconf.common.patch.PatchEditOperation;
 import org.opendaylight.restconf.common.patch.PatchEntity;
 import org.opendaylight.restconf.nb.rfc8040.Rfc8040;
 import org.opendaylight.restconf.nb.rfc8040.codecs.StringModuleInstanceIdentifierCodec;
+import org.opendaylight.restconf.nb.rfc8040.handlers.DOMMountPointServiceHandler;
+import org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler;
 import org.opendaylight.restconf.nb.rfc8040.utils.RestconfConstants;
 import org.opendaylight.yangtools.util.xml.UntrustedXML;
 import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.common.Revision;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
@@ -64,6 +68,11 @@ public class XmlToPatchBodyReader extends AbstractToPatchBodyReader {
     private static final Logger LOG = LoggerFactory.getLogger(XmlToPatchBodyReader.class);
     private static final Splitter SLASH_SPLITTER = Splitter.on('/');
 
+    public XmlToPatchBodyReader(SchemaContextHandler schemaContextHandler,
+            DOMMountPointServiceHandler mountPointServiceHandler) {
+        super(schemaContextHandler, mountPointServiceHandler);
+    }
+
     @SuppressWarnings("checkstyle:IllegalCatch")
     @Override
     protected PatchContext readBody(final InstanceIdentifierContext<?> path, final InputStream entityStream)
@@ -77,7 +86,7 @@ public class XmlToPatchBodyReader extends AbstractToPatchBodyReader {
             LOG.debug("Error parsing xml input", e);
 
             throw new RestconfDocumentedException("Error parsing input: " + e.getMessage(), ErrorType.PROTOCOL,
-                    ErrorTag.MALFORMED_MESSAGE);
+                    ErrorTag.MALFORMED_MESSAGE, e);
         }
     }
 
@@ -91,7 +100,7 @@ public class XmlToPatchBodyReader extends AbstractToPatchBodyReader {
             DataSchemaNode schemaNode = (DataSchemaNode) pathContext.getSchemaNode();
             final Element element = (Element) editNodes.item(i);
             final String operation = element.getElementsByTagName("operation").item(0).getFirstChild().getNodeValue();
-            final PatchEditOperation oper = PatchEditOperation.valueOf(operation.toUpperCase());
+            final PatchEditOperation oper = PatchEditOperation.valueOf(operation.toUpperCase(Locale.ROOT));
             final String editId = element.getElementsByTagName("edit-id").item(0).getFirstChild().getNodeValue();
             final String target = element.getElementsByTagName("target").item(0).getFirstChild().getNodeValue();
             final List<Element> values = readValueNodes(element, oper);
@@ -102,8 +111,7 @@ public class XmlToPatchBodyReader extends AbstractToPatchBodyReader {
                     ? schemaNode.getQName().getNamespace().toString() : firstValueElement.getNamespaceURI();
 
             // find module according to namespace
-            final Module module = pathContext.getSchemaContext().findModuleByNamespace(
-                    URI.create(namespace)).iterator().next();
+            final Module module = pathContext.getSchemaContext().findModules(URI.create(namespace)).iterator().next();
 
             // initialize codec + set default prefix derived from module name
             final StringModuleInstanceIdentifierCodec codec = new StringModuleInstanceIdentifierCodec(
@@ -119,7 +127,8 @@ public class XmlToPatchBodyReader extends AbstractToPatchBodyReader {
             } else {
                 targetII = codec.deserialize(codec.serialize(pathContext.getInstanceIdentifier())
                         .concat(prepareNonCondXpath(schemaNode, target.replaceFirst("/", ""), firstValueElement,
-                                namespace, module.getQNameModule().getFormattedRevision())));
+                                namespace,
+                                module.getQNameModule().getRevision().map(Revision::toString).orElse(null))));
 
                 targetNode = SchemaContextUtil.findDataSchemaNode(pathContext.getSchemaContext(),
                         codec.getDataContextTree().getChild(targetII).getDataSchemaNode().getPath().getParent());