X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=yang%2Fyang-data-codec-xml%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fyangtools%2Fyang%2Fdata%2Fcodec%2Fxml%2FXmlParserStream.java;h=aa24ee6c832837e59b7f2fe8670fc7f82dfdc2ba;hb=33c07eff30a65dd0889cc08dc88ddad72039321d;hp=0baabbb64ca0ee2740b4cd6daa101ffc75808b7e;hpb=9f7f729e68fcd18e5f7e3b15450b91051fcfb99a;p=yangtools.git diff --git a/yang/yang-data-codec-xml/src/main/java/org/opendaylight/yangtools/yang/data/codec/xml/XmlParserStream.java b/yang/yang-data-codec-xml/src/main/java/org/opendaylight/yangtools/yang/data/codec/xml/XmlParserStream.java index 0baabbb64c..aa24ee6c83 100644 --- a/yang/yang-data-codec-xml/src/main/java/org/opendaylight/yangtools/yang/data/codec/xml/XmlParserStream.java +++ b/yang/yang-data-codec-xml/src/main/java/org/opendaylight/yangtools/yang/data/codec/xml/XmlParserStream.java @@ -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,7 +41,6 @@ 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; @@ -53,6 +51,7 @@ 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; @@ -71,7 +70,6 @@ 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.ContainerLike; @@ -112,7 +110,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"; @@ -256,8 +254,6 @@ public final class XmlParserStream implements Closeable, Flushable { 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 LeafSchemaNode) { @@ -433,20 +429,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: 6.0.0: 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> 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) @@ -465,14 +456,10 @@ public final class XmlParserStream implements Closeable, Flushable { break; } - if (parentSchema instanceof YangModeledAnyxmlSchemaNode) { - parentSchema = ((YangModeledAnyxmlSchemaNode) parentSchema).getSchemaOfAnyXmlData(); - } - final String elementNS = in.getNamespaceURI(); final boolean added = namesakes.add(new SimpleImmutableEntry<>(elementNS, xmlElementName)); - final URI nsUri; + final XMLNamespace nsUri; try { nsUri = rawXmlNamespace(elementNS).getNamespace(); } catch (IllegalArgumentException e) { @@ -487,7 +474,7 @@ public final class XmlParserStream implements Closeable, Flushable { if (!added && !elementList) { throw new XMLStreamException(String.format( "Duplicate element \"%s\" in namespace \"%s\" with parent \"%s\" in XML input", - xmlElementName, elementNS, parent.getSchema()), in.getLocation()); + xmlElementName, elementNS, parentSchema), in.getLocation()); } // We have a match, proceed with it @@ -504,7 +491,8 @@ public final class XmlParserStream implements Closeable, Flushable { } else if (parentSchema instanceof ListSchemaNode) { optMount = MountPointSchemaNode.streamAll((ListSchemaNode) parentSchema).findFirst(); } else { - throw new XMLStreamException("Unhandled mount-aware schema " + parentSchema); + throw new XMLStreamException("Unhandled mount-aware schema " + parentSchema, + in.getLocation()); } if (optMount.isPresent()) { @@ -530,7 +518,7 @@ public final class XmlParserStream implements Closeable, Flushable { 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())); + elementNS, parentSchema.getPath()), in.getLocation()); } LOG.debug("Skipping unknown node ns=\"{}\" localName=\"{}\" at path {}", elementNS, xmlElementName, @@ -559,8 +547,8 @@ public final class XmlParserStream implements Closeable, Flushable { return last instanceof ListSchemaNode || last instanceof LeafListSchemaNode; } - private static void addMountPointChild(final MountPointData mount, final URI namespace, final String localName, - final DOMSource source) { + 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 optName = ContainerName.forLocalName(localName); @@ -661,13 +649,13 @@ public final class XmlParserStream implements Closeable, Flushable { private Optional resolveXmlNamespace(final String xmlNamespace) { return resolvedNamespaces.computeIfAbsent(xmlNamespace, nsUri -> { - final Iterator it = codecs.getEffectiveModelContext().findModules(URI.create(nsUri)) + final Iterator 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))); } }