Path: blob/aarch64-shenandoah-jdk8u272-b10/jaxp/src/javax/xml/transform/stax/StAXResult.java
32288 views
/*1* Copyright (c) 2005, 2006, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package javax.xml.transform.stax;2627import javax.xml.stream.XMLEventWriter;28import javax.xml.stream.XMLStreamWriter;29import javax.xml.transform.Result;3031/**32* <p>Acts as a holder for an XML {@link Result} in the33* form of a StAX writer,i.e.34* {@link XMLStreamWriter} or {@link XMLEventWriter}.35* <code>StAXResult</code> can be used in all cases that accept36* a <code>Result</code>, e.g. {@link javax.xml.transform.Transformer},37* {@link javax.xml.validation.Validator} which accept38* <code>Result</code> as input.39*40* @author <a href="mailto:[email protected]">Neeraj Bajaj</a>41* @author <a href="mailto:[email protected]">Jeff Suttor</a>42*43* @see <a href="http://jcp.org/en/jsr/detail?id=173">44* JSR 173: Streaming API for XML</a>45* @see XMLStreamWriter46* @see XMLEventWriter47*48* @since 1.649*/50public class StAXResult implements Result {51/** If {@link javax.xml.transform.TransformerFactory#getFeature(String name)}52* returns true when passed this value as an argument,53* the Transformer supports Result output of this type.54*/55public static final String FEATURE =56"http://javax.xml.transform.stax.StAXResult/feature";5758/**59* <p><code>XMLEventWriter</code> to be used for60* <code>Result</code> output.</p>61*/62private XMLEventWriter xmlEventWriter = null;6364/**65* <p><code>XMLStreamWriter</code> to be used for66* <code>Result</code> output.</p>67*/68private XMLStreamWriter xmlStreamWriter = null;6970/** <p>System identifier for this <code>StAXResult</code>.<p> */71private String systemId = null;7273/**74* <p>Creates a new instance of a <code>StAXResult</code>75* by supplying an {@link XMLEventWriter}.</p>76*77* <p><code>XMLEventWriter</code> must be a78* non-<code>null</code> reference.</p>79*80* @param xmlEventWriter <code>XMLEventWriter</code> used to create81* this <code>StAXResult</code>.82*83* @throws IllegalArgumentException If <code>xmlEventWriter</code> ==84* <code>null</code>.85*/86public StAXResult(final XMLEventWriter xmlEventWriter) {8788if (xmlEventWriter == null) {89throw new IllegalArgumentException(90"StAXResult(XMLEventWriter) with XMLEventWriter == null");91}9293this.xmlEventWriter = xmlEventWriter;94}9596/**97* <p>Creates a new instance of a <code>StAXResult</code>98* by supplying an {@link XMLStreamWriter}.</p>99*100* <p><code>XMLStreamWriter</code> must be a101* non-<code>null</code> reference.</p>102*103* @param xmlStreamWriter <code>XMLStreamWriter</code> used to create104* this <code>StAXResult</code>.105*106* @throws IllegalArgumentException If <code>xmlStreamWriter</code> ==107* <code>null</code>.108*/109public StAXResult(final XMLStreamWriter xmlStreamWriter) {110111if (xmlStreamWriter == null) {112throw new IllegalArgumentException(113"StAXResult(XMLStreamWriter) with XMLStreamWriter == null");114}115116this.xmlStreamWriter = xmlStreamWriter;117}118119/**120* <p>Get the <code>XMLEventWriter</code> used by this121* <code>StAXResult</code>.</p>122*123* <p><code>XMLEventWriter</code> will be <code>null</code>124* if this <code>StAXResult</code> was created with a125* <code>XMLStreamWriter</code>.</p>126*127* @return <code>XMLEventWriter</code> used by this128* <code>StAXResult</code>.129*/130public XMLEventWriter getXMLEventWriter() {131132return xmlEventWriter;133}134135/**136* <p>Get the <code>XMLStreamWriter</code> used by this137* <code>StAXResult</code>.</p>138*139* <p><code>XMLStreamWriter</code> will be <code>null</code>140* if this <code>StAXResult</code> was created with a141* <code>XMLEventWriter</code>.</p>142*143* @return <code>XMLStreamWriter</code> used by this144* <code>StAXResult</code>.145*/146public XMLStreamWriter getXMLStreamWriter() {147148return xmlStreamWriter;149}150151/**152* <p>In the context of a <code>StAXResult</code>, it is not appropriate153* to explicitly set the system identifier.154* The <code>XMLEventWriter</code> or <code>XMLStreamWriter</code>155* used to construct this <code>StAXResult</code> determines the156* system identifier of the XML result.</p>157*158* <p>An {@link UnsupportedOperationException} is <strong>always</strong>159* thrown by this method.</p>160*161* @param systemId Ignored.162*163* @throws UnsupportedOperationException Is <strong>always</strong>164* thrown by this method.165*/166public void setSystemId(final String systemId) {167168throw new UnsupportedOperationException(169"StAXResult#setSystemId(systemId) cannot set the "170+ "system identifier for a StAXResult");171}172173/**174* <p>The returned system identifier is always <code>null</code>.</p>175*176* @return The returned system identifier is always <code>null</code>.177*/178public String getSystemId() {179180return null;181}182}183184185