Debian Codegraph @

net/sf/saxon/s9api/BuildingStreamWriterImpl.java

raw symbols SCIP
1 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2 // Copyright (c) 2018 Saxonica Limited.
3 // This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
4 // If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
5 // This Source Code Form is "Incompatible With Secondary Licenses", as defined by the Mozilla Public License, v. 2.0.
6 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
7
8 package net.sf.saxon.s9api;
9
10 import net.sf.saxon.event.Builder;
11 import net.sf.saxon.event.Receiver;
12 import net.sf.saxon.event.StreamWriterToReceiver;
13 import net.sf.saxon.trans.XPathException;
14
15 /**
16 * This class is an implementation of {@link javax.xml.stream.XMLStreamWriter}, allowing
17 * a document to be constructed by means of a series of XMLStreamWriter method calls such
18 * as writeStartElement(), writeAttribute(), writeCharacters(), and writeEndElement().
19 * <p>The detailed way in which this class is packaged was carefully designed to ensure that
20 * if the functionality is not used, the <code>DocumentBuilder</code> would still be usable under
21 * JDK 1.5 (which does not include javax.xml.stream interfaces).</p>
22 */
23
24 public class BuildingStreamWriterImpl extends StreamWriterToReceiver implements BuildingStreamWriter {
25
26 Builder builder;
27
28 public BuildingStreamWriterImpl(Receiver receiver, Builder builder) {
29 super(receiver);
30 this.builder = builder;
31 builder.open();
32 }
33
34 /*@Nullable*/
35 public XdmNode getDocumentNode() throws SaxonApiException {
36 try {
37 builder.close();
38 } catch (XPathException e) {
39 throw new SaxonApiException(e);
40 }
41 return new XdmNode(builder.getCurrentRoot());
42 }
43 }