author | mkos |
Sun, 30 Dec 2012 00:00:00 +0100 | |
changeset 22678 | ac1ea46be942 |
parent 12009 | 4abb694f273a |
permissions | -rw-r--r-- |
12009 | 1 |
/* |
22678
ac1ea46be942
8029237: Update copyright year to match last edit in jaxws repository for 2012
mkos
parents:
12009
diff
changeset
|
2 |
* Copyright (c) 2004, 2012, Oracle and/or its affiliates. All rights reserved. |
12009 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. Oracle designates this |
|
8 |
* particular file as subject to the "Classpath" exception as provided |
|
9 |
* by Oracle in the LICENSE file that accompanied this code. |
|
10 |
* |
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
24 |
* |
|
25 |
* THIS FILE WAS MODIFIED BY SUN MICROSYSTEMS, INC. |
|
26 |
*/ |
|
27 |
||
28 |
package com.sun.xml.internal.fastinfoset.stax.factory; |
|
29 |
||
30 |
import javax.xml.namespace.QName; |
|
31 |
import javax.xml.namespace.NamespaceContext; |
|
32 |
import javax.xml.stream.Location; |
|
33 |
import javax.xml.stream.XMLEventFactory; |
|
34 |
import javax.xml.stream.events.*; |
|
35 |
import java.util.Iterator; |
|
36 |
import com.sun.xml.internal.fastinfoset.stax.events.*; |
|
37 |
||
38 |
||
39 |
public class StAXEventFactory extends XMLEventFactory { |
|
40 |
Location location = null; |
|
41 |
||
42 |
/** Creates a new instance of StAXEventFactory */ |
|
43 |
public StAXEventFactory() { |
|
44 |
} |
|
45 |
/** |
|
46 |
* This method allows setting of the Location on each event that |
|
47 |
* is created by this factory. The values are copied by value into |
|
48 |
* the events created by this factory. To reset the location |
|
49 |
* information set the location to null. |
|
50 |
* @param location the location to set on each event created |
|
51 |
*/ |
|
52 |
public void setLocation(Location location) { |
|
53 |
this.location = location; |
|
54 |
} |
|
55 |
||
56 |
/** |
|
57 |
* Create a new Attribute |
|
58 |
* @param prefix the prefix of this attribute, may not be null |
|
59 |
* @param namespaceURI the attribute value is set to this value, may not be null |
|
60 |
* @param localName the local name of the XML name of the attribute, localName cannot be null |
|
61 |
* @param value the attribute value to set, may not be null |
|
62 |
* @return the Attribute with specified values |
|
63 |
*/ |
|
64 |
public Attribute createAttribute(String prefix, String namespaceURI, String localName, String value) { |
|
65 |
AttributeBase attr = new AttributeBase(prefix, namespaceURI, localName, value, null); |
|
66 |
if(location != null)attr.setLocation(location); |
|
67 |
return attr; |
|
68 |
} |
|
69 |
||
70 |
/** |
|
71 |
* Create a new Attribute |
|
72 |
* @param localName the local name of the XML name of the attribute, localName cannot be null |
|
73 |
* @param value the attribute value to set, may not be null |
|
74 |
* @return the Attribute with specified values |
|
75 |
*/ |
|
76 |
public Attribute createAttribute(String localName, String value) { |
|
77 |
AttributeBase attr = new AttributeBase(localName, value); |
|
78 |
if(location != null)attr.setLocation(location); |
|
79 |
return attr; |
|
80 |
} |
|
81 |
||
82 |
public Attribute createAttribute(QName name, String value) { |
|
83 |
AttributeBase attr = new AttributeBase(name, value); |
|
84 |
if(location != null)attr.setLocation(location); |
|
85 |
return attr; |
|
86 |
} |
|
87 |
||
88 |
/** |
|
89 |
* Create a new default Namespace |
|
90 |
* @param namespaceURI the default namespace uri |
|
91 |
* @return the Namespace with the specified value |
|
92 |
*/ |
|
93 |
public Namespace createNamespace(String namespaceURI) { |
|
94 |
NamespaceBase event = new NamespaceBase(namespaceURI); |
|
95 |
if(location != null)event.setLocation(location); |
|
96 |
return event; |
|
97 |
} |
|
98 |
||
99 |
/** |
|
100 |
* Create a new Namespace |
|
101 |
* @param prefix the prefix of this namespace, may not be null |
|
102 |
* @param namespaceURI the attribute value is set to this value, may not be null |
|
103 |
* @return the Namespace with the specified values |
|
104 |
*/ |
|
105 |
public Namespace createNamespace(String prefix, String namespaceURI) { |
|
106 |
NamespaceBase event = new NamespaceBase(prefix, namespaceURI); |
|
107 |
if(location != null)event.setLocation(location); |
|
108 |
return event; |
|
109 |
} |
|
110 |
||
111 |
/** |
|
112 |
* Create a new StartElement. |
|
113 |
* @param name the qualified name of the attribute, may not be null |
|
114 |
* @param attributes an optional unordered set of objects that |
|
115 |
* implement Attribute to add to the new StartElement, may be null |
|
116 |
* @param namespaces an optional unordered set of objects that |
|
117 |
* implement Namespace to add to the new StartElement, may be null |
|
118 |
* @return an instance of the requested StartElement |
|
119 |
*/ |
|
120 |
public StartElement createStartElement(QName name, Iterator attributes, Iterator namespaces) { |
|
121 |
return createStartElement(name.getPrefix(), name.getNamespaceURI(), name.getLocalPart(), attributes, namespaces); |
|
122 |
} |
|
123 |
||
124 |
public StartElement createStartElement(String prefix, String namespaceUri, String localName) { |
|
125 |
StartElementEvent event = new StartElementEvent(prefix, namespaceUri, localName); |
|
126 |
if(location != null)event.setLocation(location); |
|
127 |
return event; |
|
128 |
} |
|
129 |
||
130 |
public StartElement createStartElement(String prefix, String namespaceUri, String localName, Iterator attributes, Iterator namespaces) { |
|
131 |
return createStartElement(prefix, namespaceUri, localName, attributes, namespaces, null); |
|
132 |
} |
|
133 |
||
134 |
public StartElement createStartElement(String prefix, String namespaceUri, String localName, Iterator attributes, Iterator namespaces, NamespaceContext context) { |
|
135 |
StartElementEvent elem = new StartElementEvent(prefix, namespaceUri, localName); |
|
136 |
elem.addAttributes(attributes); |
|
137 |
elem.addNamespaces(namespaces); |
|
138 |
elem.setNamespaceContext(context); |
|
139 |
if(location != null)elem.setLocation(location); |
|
140 |
return elem; |
|
141 |
} |
|
142 |
||
143 |
/** |
|
144 |
* Create a new EndElement |
|
145 |
* @param name the qualified name of the EndElement |
|
146 |
* @param namespaces an optional unordered set of objects that |
|
147 |
* implement Namespace that have gone out of scope, may be null |
|
148 |
* @return an instance of the requested EndElement |
|
149 |
*/ |
|
150 |
public EndElement createEndElement(QName name, Iterator namespaces) { |
|
151 |
return createEndElement(name.getPrefix(), name.getNamespaceURI(), name.getLocalPart(), namespaces); |
|
152 |
} |
|
153 |
||
154 |
/** |
|
155 |
* Create a new EndElement |
|
156 |
* @param namespaceUri the uri of the QName of the new StartElement |
|
157 |
* @param localName the local name of the QName of the new StartElement |
|
158 |
* @param prefix the prefix of the QName of the new StartElement |
|
159 |
* @return an instance of the requested EndElement |
|
160 |
*/ |
|
161 |
public EndElement createEndElement(String prefix, String namespaceUri, String localName) { |
|
162 |
EndElementEvent event = new EndElementEvent(prefix, namespaceUri, localName); |
|
163 |
if(location != null)event.setLocation(location); |
|
164 |
return event; |
|
165 |
} |
|
166 |
||
167 |
/** |
|
168 |
* Create a new EndElement |
|
169 |
* @param namespaceUri the uri of the QName of the new StartElement |
|
170 |
* @param localName the local name of the QName of the new StartElement |
|
171 |
* @param prefix the prefix of the QName of the new StartElement |
|
172 |
* @param namespaces an unordered set of objects that implement |
|
173 |
* Namespace that have gone out of scope, may be null |
|
174 |
* @return an instance of the requested EndElement |
|
175 |
*/ |
|
176 |
public EndElement createEndElement(String prefix, String namespaceUri, String localName, Iterator namespaces) { |
|
177 |
||
178 |
EndElementEvent event = new EndElementEvent(prefix, namespaceUri, localName); |
|
179 |
if(namespaces!=null){ |
|
180 |
while(namespaces.hasNext()) |
|
181 |
event.addNamespace((Namespace)namespaces.next()); |
|
182 |
} |
|
183 |
if(location != null)event.setLocation(location); |
|
184 |
return event; |
|
185 |
} |
|
186 |
||
187 |
/** |
|
188 |
* Create a Characters event, this method does not check if the content |
|
189 |
* is all whitespace. To create a space event use #createSpace(String) |
|
190 |
* @param content the string to create |
|
191 |
* @return a Characters event |
|
192 |
*/ |
|
193 |
public Characters createCharacters(String content) { |
|
194 |
CharactersEvent charEvent = new CharactersEvent(content); |
|
195 |
if(location != null)charEvent.setLocation(location); |
|
196 |
return charEvent; |
|
197 |
} |
|
198 |
||
199 |
/** |
|
200 |
* Create a Characters event with the CData flag set to true |
|
201 |
* @param content the string to create |
|
202 |
* @return a Characters event |
|
203 |
*/ |
|
204 |
public Characters createCData(String content) { |
|
205 |
CharactersEvent charEvent = new CharactersEvent(content, true); |
|
206 |
if(location != null)charEvent.setLocation(location); |
|
207 |
return charEvent; |
|
208 |
} |
|
209 |
||
210 |
/** |
|
211 |
* Create a Characters event with the isSpace flag set to true |
|
212 |
* @param content the content of the space to create |
|
213 |
* @return a Characters event |
|
214 |
*/ |
|
215 |
public Characters createSpace(String content) { |
|
216 |
CharactersEvent event = new CharactersEvent(content); |
|
217 |
event.setSpace(true); |
|
218 |
if(location != null)event.setLocation(location); |
|
219 |
return event; |
|
220 |
} |
|
221 |
/** |
|
222 |
* Create an ignorable space |
|
223 |
* @param content the space to create |
|
224 |
* @return a Characters event |
|
225 |
*/ |
|
226 |
public Characters createIgnorableSpace(String content) { |
|
227 |
CharactersEvent event = new CharactersEvent(content, false); |
|
228 |
event.setSpace(true); |
|
229 |
event.setIgnorable(true); |
|
230 |
if(location != null)event.setLocation(location); |
|
231 |
return event; |
|
232 |
} |
|
233 |
/** |
|
234 |
* Creates a new instance of a StartDocument event |
|
235 |
* @return a StartDocument event |
|
236 |
*/ |
|
237 |
public StartDocument createStartDocument() { |
|
238 |
StartDocumentEvent event = new StartDocumentEvent(); |
|
239 |
if(location != null)event.setLocation(location); |
|
240 |
return event; |
|
241 |
} |
|
242 |
||
243 |
/** |
|
244 |
* Creates a new instance of a StartDocument event |
|
245 |
* |
|
246 |
* @param encoding the encoding style |
|
247 |
* @return a StartDocument event |
|
248 |
*/ |
|
249 |
public StartDocument createStartDocument(String encoding) { |
|
250 |
StartDocumentEvent event = new StartDocumentEvent(encoding); |
|
251 |
if(location != null)event.setLocation(location); |
|
252 |
return event; |
|
253 |
} |
|
254 |
||
255 |
/** |
|
256 |
* Creates a new instance of a StartDocument event |
|
257 |
* |
|
258 |
* @param encoding the encoding style |
|
259 |
* @param version the XML version |
|
260 |
* @return a StartDocument event |
|
261 |
*/ |
|
262 |
public StartDocument createStartDocument(String encoding, String version) { |
|
263 |
StartDocumentEvent event = new StartDocumentEvent(encoding, version); |
|
264 |
if(location != null)event.setLocation(location); |
|
265 |
return event; |
|
266 |
} |
|
267 |
||
268 |
/** |
|
269 |
* Creates a new instance of a StartDocument event |
|
270 |
* |
|
271 |
* @param encoding the encoding style |
|
272 |
* @param version the XML version |
|
273 |
* @param standalone the status of standalone may be set to "true" or "false" |
|
274 |
* @return a StartDocument event |
|
275 |
*/ |
|
276 |
public StartDocument createStartDocument(String encoding, String version, boolean standalone) { |
|
277 |
StartDocumentEvent event = new StartDocumentEvent(encoding, version); |
|
278 |
event.setStandalone(standalone); |
|
279 |
if(location != null)event.setLocation(location); |
|
280 |
return event; |
|
281 |
} |
|
282 |
||
283 |
public EndDocument createEndDocument() { |
|
284 |
EndDocumentEvent event =new EndDocumentEvent(); |
|
285 |
if(location != null)event.setLocation(location); |
|
286 |
return event; |
|
287 |
} |
|
288 |
||
289 |
/** Creates a new instance of a EntityReference event |
|
290 |
* |
|
291 |
* @param name The name of the reference |
|
292 |
* @param entityDeclaration the declaration for the event |
|
293 |
* @return an EntityReference event |
|
294 |
*/ |
|
295 |
public EntityReference createEntityReference(String name, EntityDeclaration entityDeclaration) { |
|
296 |
EntityReferenceEvent event = new EntityReferenceEvent(name, entityDeclaration); |
|
297 |
if(location != null)event.setLocation(location); |
|
298 |
return event; |
|
299 |
} |
|
300 |
||
301 |
/** |
|
302 |
* Create a comment |
|
303 |
* @param text The text of the comment |
|
304 |
* a Comment event |
|
305 |
*/ |
|
306 |
public Comment createComment(String text) { |
|
307 |
CommentEvent charEvent = new CommentEvent(text); |
|
308 |
if(location != null)charEvent.setLocation(location); |
|
309 |
return charEvent; |
|
310 |
} |
|
311 |
||
312 |
/** |
|
313 |
* Create a document type definition event |
|
314 |
* This string contains the entire document type declaration that matches |
|
315 |
* the doctypedecl in the XML 1.0 specification |
|
316 |
* @param dtd the text of the document type definition |
|
317 |
* @return a DTD event |
|
318 |
*/ |
|
319 |
public DTD createDTD(String dtd) { |
|
320 |
DTDEvent dtdEvent = new DTDEvent(dtd); |
|
321 |
if(location != null)dtdEvent.setLocation(location); |
|
322 |
return dtdEvent; |
|
323 |
} |
|
324 |
||
325 |
||
326 |
/** |
|
327 |
* Create a processing instruction |
|
328 |
* @param target The target of the processing instruction |
|
329 |
* @param data The text of the processing instruction |
|
330 |
* @return a ProcessingInstruction event |
|
331 |
*/ |
|
332 |
public ProcessingInstruction createProcessingInstruction(String target, String data) { |
|
333 |
ProcessingInstructionEvent event = new ProcessingInstructionEvent(target, data); |
|
334 |
if(location != null)event.setLocation(location); |
|
335 |
return event; |
|
336 |
} |
|
337 |
||
338 |
||
339 |
||
340 |
||
341 |
||
342 |
} |