Check requested schema tree statement namespace
[yangtools.git] / parser / yang-parser-reactor / src / main / java / org / opendaylight / yangtools / yang / parser / stmt / reactor / InferredStatementContext.java
index ba888efc4b9131916ed9486c2da2d14481d1d154..011603fc1905234afd46bf4190203d4d4385b316 100644 (file)
@@ -426,7 +426,22 @@ final class InferredStatementContext<A, D extends DeclaredStatement<A>, E extend
             return null;
         }
 
-        final QName templateQName = qname.bindTo(StmtContextUtils.getRootModuleQName(prototype));
+        // Determine if the requested QName can be satisfied from the prototype: for that to happen it has to match
+        // our transformation implied by targetModule.
+        final var requestedNamespace = qname.getModule();
+        final QName templateQName;
+        if (targetModule != null) {
+            if (!targetModule.equals(requestedNamespace)) {
+                return null;
+            }
+            templateQName = qname.bindTo(StmtContextUtils.getRootModuleQName(prototype));
+        } else {
+            if (!StmtContextUtils.getRootModuleQName(prototype).equals(requestedNamespace)) {
+                return null;
+            }
+            templateQName = qname;
+        }
+
         LOG.debug("Materializing child {} from {}", qname, templateQName);
 
         final StmtContext<?, ?, ?> template;