Reimplement SchemaContextUtil.getBaseTypeForLeafRef()
[yangtools.git] / yang / yang-data-codec-xml / src / main / java / org / opendaylight / yangtools / yang / data / codec / xml / XmlParserStream.java
index f3357683baa35186931305ab44283765e35797d1..397dc44323dbd48376f2b8902550da617b9226ff 100644 (file)
@@ -18,7 +18,6 @@ import com.google.common.collect.ImmutableMap;
 import java.io.Closeable;
 import java.io.Flushable;
 import java.io.IOException;
-import java.net.URI;
 import java.net.URISyntaxException;
 import java.util.AbstractMap.SimpleImmutableEntry;
 import java.util.Deque;
@@ -42,37 +41,50 @@ import javax.xml.transform.TransformerFactoryConfigurationError;
 import javax.xml.transform.dom.DOMResult;
 import javax.xml.transform.dom.DOMSource;
 import javax.xml.transform.stax.StAXSource;
-import org.opendaylight.yangtools.odlext.model.api.YangModeledAnyXmlSchemaNode;
 import org.opendaylight.yangtools.rfc7952.model.api.AnnotationSchemaNode;
+import org.opendaylight.yangtools.rfc8528.data.api.MountPointContext;
+import org.opendaylight.yangtools.rfc8528.data.api.MountPointContextFactory;
+import org.opendaylight.yangtools.rfc8528.data.api.MountPointIdentifier;
+import org.opendaylight.yangtools.rfc8528.data.api.YangLibraryConstants;
+import org.opendaylight.yangtools.rfc8528.data.api.YangLibraryConstants.ContainerName;
+import org.opendaylight.yangtools.rfc8528.model.api.MountPointSchemaNode;
+import org.opendaylight.yangtools.rfc8528.model.api.SchemaMountConstants;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.common.QNameModule;
+import org.opendaylight.yangtools.yang.common.XMLNamespace;
 import org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeStreamWriter;
+import org.opendaylight.yangtools.yang.data.util.AbstractMountPointDataWithSchema;
 import org.opendaylight.yangtools.yang.data.util.AbstractNodeDataWithSchema;
 import org.opendaylight.yangtools.yang.data.util.AnyXmlNodeDataWithSchema;
 import org.opendaylight.yangtools.yang.data.util.AnydataNodeDataWithSchema;
 import org.opendaylight.yangtools.yang.data.util.CompositeNodeDataWithSchema;
+import org.opendaylight.yangtools.yang.data.util.CompositeNodeDataWithSchema.ChildReusePolicy;
 import org.opendaylight.yangtools.yang.data.util.ContainerNodeDataWithSchema;
 import org.opendaylight.yangtools.yang.data.util.LeafListEntryNodeDataWithSchema;
 import org.opendaylight.yangtools.yang.data.util.LeafListNodeDataWithSchema;
 import org.opendaylight.yangtools.yang.data.util.LeafNodeDataWithSchema;
 import org.opendaylight.yangtools.yang.data.util.ListEntryNodeDataWithSchema;
 import org.opendaylight.yangtools.yang.data.util.ListNodeDataWithSchema;
+import org.opendaylight.yangtools.yang.data.util.MountPointData;
+import org.opendaylight.yangtools.yang.data.util.MultipleEntryDataWithSchema;
 import org.opendaylight.yangtools.yang.data.util.OperationAsContainer;
 import org.opendaylight.yangtools.yang.data.util.ParserStreamUtils;
 import org.opendaylight.yangtools.yang.data.util.SimpleNodeDataWithSchema;
-import org.opendaylight.yangtools.yang.data.util.YangModeledAnyXmlNodeDataWithSchema;
-import org.opendaylight.yangtools.yang.model.api.AnyDataSchemaNode;
-import org.opendaylight.yangtools.yang.model.api.AnyXmlSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.AnydataSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.AnyxmlSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.ContainerLike;
 import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
+import org.opendaylight.yangtools.yang.model.api.EffectiveStatementInference;
 import org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.Module;
 import org.opendaylight.yangtools.yang.model.api.OperationDefinition;
-import org.opendaylight.yangtools.yang.model.api.SchemaContext;
-import org.opendaylight.yangtools.yang.model.api.SchemaNode;
 import org.opendaylight.yangtools.yang.model.api.TypedDataSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
+import org.opendaylight.yangtools.yang.model.util.SchemaInferenceStack;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.w3c.dom.Document;
@@ -100,7 +112,7 @@ public final class XmlParserStream implements Closeable, Flushable {
      *             annotations.
      */
     @Deprecated
-    public static final QNameModule LEGACY_ATTRIBUTE_NAMESPACE = QNameModule.create(URI.create("")).intern();
+    public static final QNameModule LEGACY_ATTRIBUTE_NAMESPACE = QNameModule.create(XMLNamespace.of("")).intern();
 
     private static final Logger LOG = LoggerFactory.getLogger(XmlParserStream.class);
     private static final String XML_STANDARD_VERSION = "1.0";
@@ -128,16 +140,30 @@ public final class XmlParserStream implements Closeable, Flushable {
     // Cache of nsUri Strings to QNameModules, as inferred from document
     private final Map<String, QNameModule> rawNamespaces = new HashMap<>();
     private final NormalizedNodeStreamWriter writer;
+    private final SchemaInferenceStack stack;
     private final XmlCodecFactory codecs;
     private final DataSchemaNode parentNode;
     private final boolean strictParsing;
 
     private XmlParserStream(final NormalizedNodeStreamWriter writer, final XmlCodecFactory codecs,
-            final DataSchemaNode parentNode, final boolean strictParsing) {
+            final SchemaInferenceStack stack, final boolean strictParsing) {
         this.writer = requireNonNull(writer);
         this.codecs = requireNonNull(codecs);
-        this.parentNode = parentNode;
+        this.stack = requireNonNull(stack);
         this.strictParsing = strictParsing;
+
+        if (!stack.isEmpty()) {
+            final EffectiveStatement<?, ?> stmt = stack.currentStatement();
+            if (stmt instanceof DataSchemaNode) {
+                parentNode = (DataSchemaNode) stmt;
+            } else if (stmt instanceof OperationDefinition) {
+                parentNode = OperationAsContainer.of((OperationDefinition) stmt);
+            } else {
+                throw new IllegalArgumentException("Illegal parent node " + stmt);
+            }
+        } else {
+            parentNode = stack.getEffectiveModelContext();
+        }
     }
 
     /**
@@ -149,7 +175,7 @@ public final class XmlParserStream implements Closeable, Flushable {
      * @return A new stream instance
      */
     public static XmlParserStream create(final NormalizedNodeStreamWriter writer, final XmlCodecFactory codecs,
-            final SchemaNode parentNode) {
+            final EffectiveStatementInference parentNode) {
         return create(writer, codecs, parentNode, true);
     }
 
@@ -166,36 +192,78 @@ public final class XmlParserStream implements Closeable, Flushable {
      * @return A new stream instance
      */
     public static XmlParserStream create(final NormalizedNodeStreamWriter writer, final XmlCodecFactory codecs,
-            final SchemaNode parentNode, final boolean strictParsing) {
-        final DataSchemaNode parent;
-        if (parentNode instanceof DataSchemaNode) {
-            parent = (DataSchemaNode) parentNode;
-        } else if (parentNode instanceof OperationDefinition) {
-            parent = OperationAsContainer.of((OperationDefinition) parentNode);
-        } else {
-            throw new IllegalArgumentException("Illegal parent node " + parentNode);
-        }
-        return new XmlParserStream(writer, codecs, parent, strictParsing);
+            final EffectiveStatementInference parentNode, final boolean strictParsing) {
+        return new XmlParserStream(writer, codecs, SchemaInferenceStack.ofInference(parentNode), strictParsing);
+    }
+
+    /**
+     * Utility method for use when caching {@link XmlCodecFactory} is not feasible. Users with high performance
+     * requirements should use {@link #create(NormalizedNodeStreamWriter, XmlCodecFactory, EffectiveStatementInference)}
+     * instead and maintain a {@link XmlCodecFactory} to match the current {@link EffectiveModelContext}.
+     */
+    public static XmlParserStream create(final NormalizedNodeStreamWriter writer,
+            final EffectiveModelContext context) {
+        return create(writer, context, true);
+    }
+
+    /**
+     * Utility method for use when caching {@link XmlCodecFactory} is not feasible. Users with high performance
+     * requirements should use {@link #create(NormalizedNodeStreamWriter, XmlCodecFactory, EffectiveStatementInference)}
+     * instead and maintain a {@link XmlCodecFactory} to match the current {@link EffectiveModelContext}.
+     */
+    public static XmlParserStream create(final NormalizedNodeStreamWriter writer,
+            final EffectiveModelContext context, final boolean strictParsing) {
+        return create(writer, SchemaInferenceStack.of(context).toInference(), strictParsing);
+    }
+
+    /**
+     * Utility method for use when caching {@link XmlCodecFactory} is not feasible. Users with high performance
+     * requirements should use {@link #create(NormalizedNodeStreamWriter, XmlCodecFactory, EffectiveStatementInference)}
+     * instead and maintain a {@link XmlCodecFactory} to match the current {@link EffectiveModelContext}.
+     */
+    public static XmlParserStream create(final NormalizedNodeStreamWriter writer,
+            final EffectiveStatementInference parentNode) {
+        return create(writer, parentNode, true);
+    }
+
+    /**
+     * Utility method for use when caching {@link XmlCodecFactory} is not feasible. Users with high performance
+     * requirements should use {@link #create(NormalizedNodeStreamWriter, XmlCodecFactory, EffectiveStatementInference)}
+     * instead and maintain a {@link XmlCodecFactory} to match the current {@link EffectiveModelContext}.
+     */
+    public static XmlParserStream create(final NormalizedNodeStreamWriter writer,
+            final EffectiveStatementInference parentNode, final boolean strictParsing) {
+        return create(writer, XmlCodecFactory.create(parentNode.getEffectiveModelContext()), parentNode, strictParsing);
+    }
+
+    /**
+     * Utility method for use when caching {@link XmlCodecFactory} is not feasible. Users with high performance
+     * requirements should use {@link #create(NormalizedNodeStreamWriter, XmlCodecFactory, EffectiveStatementInference)}
+     * instead and maintain a {@link XmlCodecFactory} to match the current {@link MountPointContext}.
+     */
+    public static XmlParserStream create(final NormalizedNodeStreamWriter writer, final MountPointContext mountCtx) {
+        return create(writer, mountCtx, SchemaInferenceStack.of(mountCtx.getEffectiveModelContext()).toInference(),
+            true);
     }
 
     /**
      * Utility method for use when caching {@link XmlCodecFactory} is not feasible. Users with high performance
-     * requirements should use {@link #create(NormalizedNodeStreamWriter, XmlCodecFactory, SchemaNode)} instead and
-     * maintain a {@link XmlCodecFactory} to match the current {@link SchemaContext}.
+     * requirements should use {@link #create(NormalizedNodeStreamWriter, XmlCodecFactory, EffectiveStatementInference)}
+     * instead and maintain a {@link XmlCodecFactory} to match the current {@link MountPointContext}.
      */
-    public static XmlParserStream create(final NormalizedNodeStreamWriter writer, final SchemaContext schemaContext,
-            final SchemaNode parentNode) {
-        return create(writer, schemaContext, parentNode, true);
+    public static XmlParserStream create(final NormalizedNodeStreamWriter writer, final MountPointContext mountCtx,
+            final EffectiveStatementInference parentNode) {
+        return create(writer, mountCtx, parentNode, true);
     }
 
     /**
      * Utility method for use when caching {@link XmlCodecFactory} is not feasible. Users with high performance
-     * requirements should use {@link #create(NormalizedNodeStreamWriter, XmlCodecFactory, SchemaNode)} instead and
-     * maintain a {@link XmlCodecFactory} to match the current {@link SchemaContext}.
+     * requirements should use {@link #create(NormalizedNodeStreamWriter, XmlCodecFactory, EffectiveStatementInference)}
+     * instead and maintain a {@link XmlCodecFactory} to match the current {@link MountPointContext}.
      */
-    public static XmlParserStream create(final NormalizedNodeStreamWriter writer, final SchemaContext schemaContext,
-            final SchemaNode parentNode, final boolean strictParsing) {
-        return create(writer, XmlCodecFactory.create(schemaContext), parentNode, strictParsing);
+    public static XmlParserStream create(final NormalizedNodeStreamWriter writer, final MountPointContext mountCtx,
+            final EffectiveStatementInference parentNode, final boolean strictParsing) {
+        return create(writer, XmlCodecFactory.create(mountCtx), parentNode, strictParsing);
     }
 
     /**
@@ -220,20 +288,18 @@ public final class XmlParserStream implements Closeable, Flushable {
         if (reader.hasNext()) {
             reader.nextTag();
             final AbstractNodeDataWithSchema<?> nodeDataWithSchema;
-            if (parentNode instanceof ContainerSchemaNode) {
-                nodeDataWithSchema = new ContainerNodeDataWithSchema((ContainerSchemaNode) parentNode);
+            if (parentNode instanceof ContainerLike) {
+                nodeDataWithSchema = new ContainerNodeDataWithSchema((ContainerLike) parentNode);
             } else if (parentNode instanceof ListSchemaNode) {
                 nodeDataWithSchema = new ListNodeDataWithSchema((ListSchemaNode) parentNode);
-            } else if (parentNode instanceof YangModeledAnyXmlSchemaNode) {
-                nodeDataWithSchema = new YangModeledAnyXmlNodeDataWithSchema((YangModeledAnyXmlSchemaNode) parentNode);
-            } else if (parentNode instanceof AnyXmlSchemaNode) {
-                nodeDataWithSchema = new AnyXmlNodeDataWithSchema((AnyXmlSchemaNode) parentNode);
+            } else if (parentNode instanceof AnyxmlSchemaNode) {
+                nodeDataWithSchema = new AnyXmlNodeDataWithSchema((AnyxmlSchemaNode) parentNode);
             } else if (parentNode instanceof LeafSchemaNode) {
                 nodeDataWithSchema = new LeafNodeDataWithSchema((LeafSchemaNode) parentNode);
             } else if (parentNode instanceof LeafListSchemaNode) {
                 nodeDataWithSchema = new LeafListNodeDataWithSchema((LeafListSchemaNode) parentNode);
-            } else if (parentNode instanceof AnyDataSchemaNode) {
-                nodeDataWithSchema = new AnydataNodeDataWithSchema((AnyDataSchemaNode) parentNode);
+            } else if (parentNode instanceof AnydataSchemaNode) {
+                nodeDataWithSchema = new AnydataNodeDataWithSchema((AnydataSchemaNode) parentNode);
             } else {
                 throw new IllegalStateException("Unsupported schema node type " + parentNode.getClass() + ".");
             }
@@ -293,10 +359,11 @@ public final class XmlParserStream implements Closeable, Flushable {
             if (optModule.isPresent()) {
                 final QName qname = QName.create(optModule.get(), localName);
                 final Optional<AnnotationSchemaNode> optAnnotation = AnnotationSchemaNode.find(
-                    codecs.getSchemaContext(), qname);
+                    codecs.getEffectiveModelContext(), qname);
                 if (optAnnotation.isPresent()) {
                     final AnnotationSchemaNode schema = optAnnotation.get();
-                    final Object value = codecs.codecFor(schema).parseValue(in.getNamespaceContext(), attrValue);
+                    final Object value = codecs.codecFor(schema, stack)
+                        .parseValue(in.getNamespaceContext(), attrValue);
                     attributes.put(schema.getQName(), value);
                     continue;
                 }
@@ -401,18 +468,15 @@ public final class XmlParserStream implements Closeable, Flushable {
             return;
         }
 
-        if (parent instanceof YangModeledAnyXmlSchemaNode) {
-            parent.setAttributes(getElementAttributes(in));
-        }
-
         switch (in.nextTag()) {
             case XMLStreamConstants.START_ELEMENT:
-                // FIXME: why do we even need this tracker? either document it or remove it
+                // FIXME: 7.0.0: why do we even need this tracker? either document it or remove it.
+                //               it looks like it is a crude duplicate finder, which should really be handled via
+                //               ChildReusePolicy.REJECT
                 final Set<Entry<String, String>> namesakes = new HashSet<>();
                 while (in.hasNext()) {
                     final String xmlElementName = in.getLocalName();
-
-                    DataSchemaNode parentSchema = parent.getSchema();
+                    final DataSchemaNode parentSchema = parent.getSchema();
 
                     final String parentSchemaName = parentSchema.getQName().getLocalName();
                     if (parentSchemaName.equals(xmlElementName)
@@ -431,18 +495,10 @@ public final class XmlParserStream implements Closeable, Flushable {
                         break;
                     }
 
-                    if (parentSchema instanceof YangModeledAnyXmlSchemaNode) {
-                        parentSchema = ((YangModeledAnyXmlSchemaNode) parentSchema).getSchemaOfAnyXmlData();
-                    }
-
                     final String elementNS = in.getNamespaceURI();
-                    if (!namesakes.add(new SimpleImmutableEntry<>(elementNS, xmlElementName))) {
-                        throw new XMLStreamException(String.format(
-                            "Duplicate namespace \"%s\" element \"%s\" in XML input", elementNS, xmlElementName),
-                            in.getLocation());
-                    }
+                    final boolean added = namesakes.add(new SimpleImmutableEntry<>(elementNS, xmlElementName));
 
-                    final URI nsUri;
+                    final XMLNamespace nsUri;
                     try {
                         nsUri = rawXmlNamespace(elementNS).getNamespace();
                     } catch (IllegalArgumentException e) {
@@ -452,21 +508,65 @@ public final class XmlParserStream implements Closeable, Flushable {
 
                     final Deque<DataSchemaNode> childDataSchemaNodes =
                             ParserStreamUtils.findSchemaNodeByNameAndNamespace(parentSchema, xmlElementName, nsUri);
+                    if (!childDataSchemaNodes.isEmpty()) {
+                        final boolean elementList = isElementList(childDataSchemaNodes);
+                        if (!added && !elementList) {
+                            throw new XMLStreamException(String.format(
+                                "Duplicate element \"%s\" in namespace \"%s\" with parent \"%s\" in XML input",
+                                xmlElementName, elementNS, parentSchema), in.getLocation());
+                        }
 
-                    if (childDataSchemaNodes.isEmpty()) {
-                        if (!strictParsing) {
-                            LOG.debug("Skipping unknown node ns=\"{}\" localName=\"{}\" at path {}", elementNS,
-                                xmlElementName, parentSchema.getPath());
-                            skipUnknownNode(in);
-                            continue;
+                        // We have a match, proceed with it
+                        final QName qname = childDataSchemaNodes.peekLast().getQName();
+                        final AbstractNodeDataWithSchema<?> child = ((CompositeNodeDataWithSchema<?>) parent).addChild(
+                            childDataSchemaNodes, elementList ? ChildReusePolicy.REUSE : ChildReusePolicy.NOOP);
+                        stack.enterDataTree(qname);
+                        read(in, child, rootElement);
+                        stack.exit();
+                        continue;
+                    }
+
+                    if (parent instanceof AbstractMountPointDataWithSchema) {
+                        // Parent can potentially hold a mount point, let's see if there is a label present
+                        final Optional<MountPointSchemaNode> optMount;
+                        if (parentSchema instanceof ContainerSchemaNode) {
+                            optMount = MountPointSchemaNode.streamAll((ContainerSchemaNode) parentSchema).findFirst();
+                        } else if (parentSchema instanceof ListSchemaNode) {
+                            optMount = MountPointSchemaNode.streamAll((ListSchemaNode) parentSchema).findFirst();
+                        } else {
+                            throw new XMLStreamException("Unhandled mount-aware schema " + parentSchema,
+                                in.getLocation());
                         }
 
+                        if (optMount.isPresent()) {
+                            final MountPointIdentifier mountId = MountPointIdentifier.of(optMount.get().getQName());
+                            LOG.debug("Assuming node {} and namespace {} belongs to mount point {}", xmlElementName,
+                                nsUri, mountId);
+
+                            final Optional<MountPointContextFactory> optFactory = codecs.mountPointContext()
+                                    .findMountPoint(mountId);
+                            if (optFactory.isPresent()) {
+                                final MountPointData mountData = ((AbstractMountPointDataWithSchema<?>) parent)
+                                        .getMountPointData(mountId, optFactory.get());
+                                addMountPointChild(mountData, nsUri, xmlElementName,
+                                    new DOMSource(readAnyXmlValue(in).getDocumentElement()));
+                                continue;
+                            }
+
+                            LOG.debug("Mount point {} not attached", mountId);
+                        }
+                    }
+
+                    // We have not handled the node -- let's decide what to do about that
+                    if (strictParsing) {
                         throw new XMLStreamException(String.format(
-                            "Schema for node with name %s and namespace %s does not exist at %s", xmlElementName,
-                            elementNS, parentSchema.getPath(), in.getLocation()));
+                            "Schema for node with name %s and namespace %s does not exist in parent %s", xmlElementName,
+                            elementNS, parentSchema), in.getLocation());
                     }
 
-                    read(in, ((CompositeNodeDataWithSchema<?>) parent).addChild(childDataSchemaNodes), rootElement);
+                    LOG.debug("Skipping unknown node ns=\"{}\" localName=\"{}\" in parent {}", elementNS,
+                        xmlElementName, parentSchema);
+                    skipUnknownNode(in);
                 }
                 break;
             case XMLStreamConstants.END_ELEMENT:
@@ -483,6 +583,32 @@ public final class XmlParserStream implements Closeable, Flushable {
         }
     }
 
+    // Return true if schema represents a construct which uses multiple sibling elements to represent its content. The
+    // siblings MAY be interleaved as per RFC7950.
+    private static boolean isElementList(final Deque<DataSchemaNode> childDataSchemaNodes) {
+        final DataSchemaNode last = childDataSchemaNodes.getLast();
+        return last instanceof ListSchemaNode || last instanceof LeafListSchemaNode;
+    }
+
+    private static void addMountPointChild(final MountPointData mount, final XMLNamespace namespace,
+            final String localName, final DOMSource source) {
+        final DOMSourceMountPointChild child = new DOMSourceMountPointChild(source);
+        if (YangLibraryConstants.MODULE_NAMESPACE.equals(namespace)) {
+            final Optional<ContainerName> optName = ContainerName.forLocalName(localName);
+            if (optName.isPresent()) {
+                mount.setContainer(optName.get(), child);
+                return;
+            }
+
+            LOG.warn("Encountered unknown element {} from YANG Library namespace", localName);
+        } else if (SchemaMountConstants.RFC8528_MODULE.getNamespace().equals(namespace)) {
+            mount.setSchemaMounts(child);
+            return;
+        }
+
+        mount.addChild(child);
+    }
+
     private static boolean isNextEndDocument(final XMLStreamReader in) throws XMLStreamException {
         return !in.hasNext() || in.next() == XMLStreamConstants.END_DOCUMENT;
     }
@@ -530,7 +656,7 @@ public final class XmlParserStream implements Closeable, Flushable {
 
     private Object translateValueByType(final Object value, final DataSchemaNode node,
             final NamespaceContext namespaceCtx) {
-        if (node instanceof AnyXmlSchemaNode) {
+        if (node instanceof AnyxmlSchemaNode) {
             checkArgument(value instanceof Document);
             /*
              * FIXME: Figure out some YANG extension dispatch, which will reuse JSON parsing or XML parsing -
@@ -538,26 +664,19 @@ public final class XmlParserStream implements Closeable, Flushable {
              */
             return new DOMSource(((Document) value).getDocumentElement());
         }
-        if (node instanceof AnyDataSchemaNode) {
+        if (node instanceof AnydataSchemaNode) {
             checkArgument(value instanceof Document);
             return new DOMSourceAnydata(new DOMSource(((Document) value).getDocumentElement()));
         }
 
         checkArgument(node instanceof TypedDataSchemaNode);
         checkArgument(value instanceof String);
-        return codecs.codecFor((TypedDataSchemaNode) node).parseValue(namespaceCtx, (String) value);
+        return codecs.codecFor((TypedDataSchemaNode) node, stack).parseValue(namespaceCtx, (String) value);
     }
 
     private static AbstractNodeDataWithSchema<?> newEntryNode(final AbstractNodeDataWithSchema<?> parent) {
-        final AbstractNodeDataWithSchema<?> newChild;
-        if (parent instanceof ListNodeDataWithSchema) {
-            newChild = ListEntryNodeDataWithSchema.forSchema(((ListNodeDataWithSchema) parent).getSchema());
-        } else {
-            verify(parent instanceof LeafListNodeDataWithSchema, "Unexpected parent %s", parent);
-            newChild = new LeafListEntryNodeDataWithSchema(((LeafListNodeDataWithSchema) parent).getSchema());
-        }
-        ((CompositeNodeDataWithSchema<?>) parent).addChild(newChild);
-        return newChild;
+        verify(parent instanceof MultipleEntryDataWithSchema, "Unexpected parent %s", parent);
+        return ((MultipleEntryDataWithSchema<?>) parent).newChildEntry();
     }
 
     @Override
@@ -573,12 +692,13 @@ public final class XmlParserStream implements Closeable, Flushable {
 
     private Optional<QNameModule> resolveXmlNamespace(final String xmlNamespace) {
         return resolvedNamespaces.computeIfAbsent(xmlNamespace, nsUri -> {
-            final Iterator<Module> it = codecs.getSchemaContext().findModules(URI.create(nsUri)).iterator();
+            final Iterator<? extends Module> it = codecs.getEffectiveModelContext().findModules(XMLNamespace.of(nsUri))
+                    .iterator();
             return it.hasNext() ? Optional.of(it.next().getQNameModule()) : Optional.empty();
         });
     }
 
     private QNameModule rawXmlNamespace(final String xmlNamespace) {
-        return rawNamespaces.computeIfAbsent(xmlNamespace, nsUri -> QNameModule.create(URI.create(nsUri)));
+        return rawNamespaces.computeIfAbsent(xmlNamespace, nsUri -> QNameModule.create(XMLNamespace.of(nsUri)));
     }
 }