KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > javax > xml > transform > stax > StAXResult


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the "License"). You may not use this file except
5  * in compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://jaxp.dev.java.net/CDDLv1.0.html.
9  * See the License for the specific language governing
10  * permissions and limitations under the License.
11  *
12  * When distributing Covered Code, include this CDDL
13  * HEADER in each file and include the License file at
14  * https://jaxp.dev.java.net/CDDLv1.0.html
15  * If applicable add the following below this CDDL HEADER
16  * with the fields enclosed by brackets "[]" replaced with
17  * your own identifying information: Portions Copyright
18  * [year] [name of copyright owner]
19  */

20
21 /*
22  * $Id: StAXResult.java,v 1.4 2006/04/24 13:42:26 ndw Exp $
23  * @(#)StAXResult.java 1.11 06/07/13
24  *
25  * Copyright 2005 Sun Microsystems, Inc. All Rights Reserved.
26  */

27
28 package javax.xml.transform.stax;
29
30 import javax.xml.stream.XMLEventWriter;
31 import javax.xml.stream.XMLStreamWriter;
32 import javax.xml.transform.Result JavaDoc;
33
34 /**
35  * <p>Acts as a holder for an XML {@link Result} in the
36  * form of a StAX writer,i.e.
37  * {@link XMLStreamWriter} or {@link XMLEventWriter}.
38  * <code>StAXResult</code> can be used in all cases that accept
39  * a <code>Result</code>, e.g. {@link javax.xml.transform.Transformer},
40  * {@link javax.xml.validation.Validator} which accept
41  * <code>Result</code> as input.
42  *
43  * @author <a HREF="mailto:Neeraj.Bajaj@Sun.com">Neeraj Bajaj</a>
44  * @author <a HREF="mailto:Jeff.Suttor@Sun.com">Jeff Suttor</a>
45  * @version $Revision: 1.4 $, $Date: 2006/04/24 13:42:26 $
46  *
47  * @see <a HREF="http://jcp.org/en/jsr/detail?id=173">
48  * JSR 173: Streaming API for XML</a>
49  * @see XMLStreamWriter
50  * @see XMLEventWriter
51  *
52  * @since 1.6
53  */

54 public class StAXResult implements Result JavaDoc {
55     /** If {@link javax.xml.transform.TransformerFactory#getFeature(String name)}
56      * returns true when passed this value as an argument,
57      * the Transformer supports Result output of this type.
58      */

59     public static final String JavaDoc FEATURE =
60         "http://javax.xml.transform.stax.StAXResult/feature";
61
62     /**
63      * <p><code>XMLEventWriter</code> to be used for
64      * <code>Result</code> output.</p>
65      */

66     private XMLEventWriter xmlEventWriter = null;
67
68     /**
69      * <p><code>XMLStreamWriter</code> to be used for
70      * <code>Result</code> output.</p>
71      */

72     private XMLStreamWriter xmlStreamWriter = null;
73
74     /** <p>System identifier for this <code>StAXResult</code>.<p> */
75     private String JavaDoc systemId = null;
76
77     /**
78      * <p>Creates a new instance of a <code>StAXResult</code>
79      * by supplying an {@link XMLEventWriter}.</p>
80      *
81      * <p><code>XMLEventWriter</code> must be a
82      * non-<code>null</code> reference.</p>
83      *
84      * @param xmlEventWriter <code>XMLEventWriter</code> used to create
85      * this <code>StAXResult</code>.
86      *
87      * @throws IllegalArgumentException If <code>xmlEventWriter</code> ==
88      * <code>null</code>.
89      */

90     public StAXResult(final XMLEventWriter xmlEventWriter) {
91
92         if (xmlEventWriter == null) {
93             throw new IllegalArgumentException JavaDoc(
94                     "StAXResult(XMLEventWriter) with XMLEventWriter == null");
95         }
96
97         this.xmlEventWriter = xmlEventWriter;
98     }
99
100     /**
101      * <p>Creates a new instance of a <code>StAXResult</code>
102      * by supplying an {@link XMLStreamWriter}.</p>
103      *
104      * <p><code>XMLStreamWriter</code> must be a
105      * non-<code>null</code> reference.</p>
106      *
107      * @param xmlStreamWriter <code>XMLStreamWriter</code> used to create
108      * this <code>StAXResult</code>.
109      *
110      * @throws IllegalArgumentException If <code>xmlStreamWriter</code> ==
111      * <code>null</code>.
112      */

113     public StAXResult(final XMLStreamWriter xmlStreamWriter) {
114
115         if (xmlStreamWriter == null) {
116             throw new IllegalArgumentException JavaDoc(
117                     "StAXResult(XMLStreamWriter) with XMLStreamWriter == null");
118         }
119
120         this.xmlStreamWriter = xmlStreamWriter;
121     }
122
123     /**
124      * <p>Get the <code>XMLEventWriter</code> used by this
125      * <code>StAXResult</code>.</p>
126      *
127      * <p><code>XMLEventWriter</code> will be <code>null</code>
128      * if this <code>StAXResult</code> was created with a
129      * <code>XMLStreamWriter</code>.</p>
130      *
131      * @return <code>XMLEventWriter</code> used by this
132      * <code>StAXResult</code>.
133      */

134     public XMLEventWriter getXMLEventWriter() {
135
136         return xmlEventWriter;
137     }
138
139     /**
140      * <p>Get the <code>XMLStreamWriter</code> used by this
141      * <code>StAXResult</code>.</p>
142      *
143      * <p><code>XMLStreamWriter</code> will be <code>null</code>
144      * if this <code>StAXResult</code> was created with a
145      * <code>XMLEventWriter</code>.</p>
146      *
147      * @return <code>XMLStreamWriter</code> used by this
148      * <code>StAXResult</code>.
149      */

150     public XMLStreamWriter getXMLStreamWriter() {
151
152         return xmlStreamWriter;
153     }
154
155     /**
156      * <p>In the context of a <code>StAXResult</code>, it is not appropriate
157      * to explicitly set the system identifier.
158      * The <code>XMLEventWriter</code> or <code>XMLStreamWriter</code>
159      * used to construct this <code>StAXResult</code> determines the
160      * system identifier of the XML result.</p>
161      *
162      * <p>An {@link UnsupportedOperationException} is <strong>always</strong>
163      * thrown by this method.</p>
164      *
165      * @param systemId Ignored.
166      *
167      * @throws UnsupportedOperationException Is <strong>always</strong>
168      * thrown by this method.
169      */

170     public void setSystemId(final String JavaDoc systemId) {
171
172         throw new UnsupportedOperationException JavaDoc(
173                 "StAXResult#setSystemId(systemId) cannot set the "
174                 + "system identifier for a StAXResult");
175     }
176
177     /**
178      * <p>The returned system identifier is always <code>null</code>.</p>
179      *
180      * @return The returned system identifier is always <code>null</code>.
181      */

182     public String JavaDoc getSystemId() {
183
184         return null;
185     }
186 }
187
Popular Tags