2 * Copyright (c) 2019 PANTHEON.tech, s.r.o. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.yangtools.yang.data.codec.xml;
10 import static java.util.Objects.requireNonNull;
12 import java.io.IOException;
13 import java.net.URISyntaxException;
14 import javax.xml.stream.XMLStreamException;
15 import javax.xml.stream.XMLStreamReader;
16 import javax.xml.transform.dom.DOMSource;
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.opendaylight.yangtools.rfc8528.data.api.MountPointContext;
19 import org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeStreamWriter;
20 import org.opendaylight.yangtools.yang.data.impl.schema.AbstractMountPointChild;
21 import org.xml.sax.SAXException;
24 * Internal MountPointChild implementation, reusing data bits from {@link DOMSourceAnydata}.
27 final class DOMSourceMountPointChild extends AbstractMountPointChild {
28 private final DOMSource source;
30 DOMSourceMountPointChild(final DOMSource source) {
31 this.source = requireNonNull(source);
35 public void writeTo(final NormalizedNodeStreamWriter writer, final MountPointContext mountCtx) throws IOException {
36 final XmlParserStream xmlParser;
38 xmlParser = XmlParserStream.create(writer, mountCtx);
39 } catch (IllegalArgumentException e) {
40 throw new IOException("Failed to instantiate XML parser", e);
44 final XMLStreamReader reader = new DOMSourceXMLStreamReader(source);
45 xmlParser.parse(reader).flush();
46 } catch (XMLStreamException | URISyntaxException | SAXException e) {
47 throw new IOException("Failed to parse payload", e);