12005
|
1 |
/*
|
|
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 it
|
|
5 |
* under the terms of the GNU General Public License version 2 only, as
|
|
6 |
* published by the Free Software Foundation. Oracle designates this
|
|
7 |
* particular file as subject to the "Classpath" exception as provided
|
|
8 |
* 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 WITHOUT
|
|
11 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
12 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
13 |
* version 2 for more details (a copy is included in the LICENSE file that
|
|
14 |
* accompanied this code).
|
|
15 |
*
|
|
16 |
* You should have received a copy of the GNU General Public License version
|
|
17 |
* 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 USA
|
|
21 |
* or visit www.oracle.com if you need additional information or have any
|
|
22 |
* questions.
|
|
23 |
*/
|
|
24 |
|
|
25 |
/*
|
|
26 |
* Copyright (c) 2009 by Oracle Corporation. All Rights Reserved.
|
|
27 |
*/
|
|
28 |
|
|
29 |
package javax.xml.stream;
|
|
30 |
import javax.xml.stream.events.*;
|
|
31 |
import javax.xml.namespace.NamespaceContext;
|
|
32 |
import javax.xml.namespace.QName;
|
|
33 |
import java.util.Iterator;
|
|
34 |
/**
|
|
35 |
* This interface defines a utility class for creating instances of
|
|
36 |
* XMLEvents
|
|
37 |
* @version 1.2
|
|
38 |
* @author Copyright (c) 2009 by Oracle Corporation. All Rights Reserved.
|
|
39 |
* @see javax.xml.stream.events.StartElement
|
|
40 |
* @see javax.xml.stream.events.EndElement
|
|
41 |
* @see javax.xml.stream.events.ProcessingInstruction
|
|
42 |
* @see javax.xml.stream.events.Comment
|
|
43 |
* @see javax.xml.stream.events.Characters
|
|
44 |
* @see javax.xml.stream.events.StartDocument
|
|
45 |
* @see javax.xml.stream.events.EndDocument
|
|
46 |
* @see javax.xml.stream.events.DTD
|
|
47 |
* @since 1.6
|
|
48 |
*/
|
|
49 |
public abstract class XMLEventFactory {
|
|
50 |
protected XMLEventFactory(){}
|
|
51 |
|
|
52 |
/**
|
|
53 |
* Create a new instance of the factory
|
|
54 |
* @throws FactoryConfigurationError if an instance of this factory cannot be loaded
|
|
55 |
*/
|
|
56 |
public static XMLEventFactory newInstance()
|
|
57 |
throws FactoryConfigurationError
|
|
58 |
{
|
|
59 |
return (XMLEventFactory) FactoryFinder.find(
|
|
60 |
"javax.xml.stream.XMLEventFactory",
|
|
61 |
"com.sun.xml.internal.stream.events.XMLEventFactoryImpl");
|
|
62 |
}
|
|
63 |
|
|
64 |
/**
|
|
65 |
* Create a new instance of the factory.
|
|
66 |
* This static method creates a new factory instance.
|
|
67 |
* This method uses the following ordered lookup procedure to determine
|
|
68 |
* the XMLEventFactory implementation class to load:
|
|
69 |
* Use the javax.xml.stream.XMLEventFactory system property.
|
|
70 |
* Use the properties file "lib/stax.properties" in the JRE directory.
|
|
71 |
* This configuration file is in standard java.util.Properties format
|
|
72 |
* and contains the fully qualified name of the implementation class
|
|
73 |
* with the key being the system property defined above.
|
|
74 |
* Use the Services API (as detailed in the JAR specification), if available,
|
|
75 |
* to determine the classname. The Services API will look for a classname
|
|
76 |
* in the file META-INF/services/javax.xml.stream.XMLEventFactory in jars
|
|
77 |
* available to the runtime.
|
|
78 |
* Platform default XMLEventFactory instance.
|
|
79 |
*
|
|
80 |
* Once an application has obtained a reference to a XMLEventFactory it
|
|
81 |
* can use the factory to configure and obtain stream instances.
|
|
82 |
*
|
|
83 |
* Note that this is a new method that replaces the deprecated newInstance() method.
|
|
84 |
* No changes in behavior are defined by this replacement method relative to
|
|
85 |
* the deprecated method.
|
|
86 |
*
|
|
87 |
* @throws FactoryConfigurationError if an instance of this factory cannot be loaded
|
|
88 |
*/
|
|
89 |
public static XMLEventFactory newFactory()
|
|
90 |
throws FactoryConfigurationError
|
|
91 |
{
|
|
92 |
return (XMLEventFactory) FactoryFinder.find(
|
|
93 |
"javax.xml.stream.XMLEventFactory",
|
|
94 |
"com.sun.xml.internal.stream.events.XMLEventFactoryImpl");
|
|
95 |
}
|
|
96 |
|
|
97 |
/**
|
|
98 |
* Create a new instance of the factory
|
|
99 |
*
|
|
100 |
* @param factoryId Name of the factory to find, same as
|
|
101 |
* a property name
|
|
102 |
* @param classLoader classLoader to use
|
|
103 |
* @return the factory implementation
|
|
104 |
* @throws FactoryConfigurationError if an instance of this factory cannot be loaded
|
|
105 |
*
|
|
106 |
* @deprecated This method has been deprecated to maintain API consistency.
|
|
107 |
* All newInstance methods have been replaced with corresponding
|
|
108 |
* newFactory methods. The replacement {@link
|
|
109 |
* #newFactory(java.lang.String, java.lang.ClassLoader)}
|
|
110 |
* method defines no changes in behavior.
|
|
111 |
*/
|
|
112 |
public static XMLEventFactory newInstance(String factoryId,
|
|
113 |
ClassLoader classLoader)
|
|
114 |
throws FactoryConfigurationError {
|
|
115 |
try {
|
|
116 |
//do not fallback if given classloader can't find the class, throw exception
|
|
117 |
return (XMLEventFactory) FactoryFinder.newInstance(factoryId, classLoader, false);
|
|
118 |
} catch (FactoryFinder.ConfigurationError e) {
|
|
119 |
throw new FactoryConfigurationError(e.getException(),
|
|
120 |
e.getMessage());
|
|
121 |
}
|
|
122 |
}
|
|
123 |
|
|
124 |
/**
|
|
125 |
* Create a new instance of the factory.
|
|
126 |
* If the classLoader argument is null, then the ContextClassLoader is used.
|
|
127 |
*
|
|
128 |
* Note that this is a new method that replaces the deprecated
|
|
129 |
* newInstance(String factoryId, ClassLoader classLoader) method.
|
|
130 |
* No changes in behavior are defined by this replacement method relative
|
|
131 |
* to the deprecated method.
|
|
132 |
*
|
|
133 |
* @param factoryId Name of the factory to find, same as
|
|
134 |
* a property name
|
|
135 |
* @param classLoader classLoader to use
|
|
136 |
* @return the factory implementation
|
|
137 |
* @throws FactoryConfigurationError if an instance of this factory cannot be loaded
|
|
138 |
*/
|
|
139 |
public static XMLEventFactory newFactory(String factoryId,
|
|
140 |
ClassLoader classLoader)
|
|
141 |
throws FactoryConfigurationError {
|
|
142 |
try {
|
|
143 |
//do not fallback if given classloader can't find the class, throw exception
|
|
144 |
return (XMLEventFactory) FactoryFinder.newInstance(factoryId, classLoader, false);
|
|
145 |
} catch (FactoryFinder.ConfigurationError e) {
|
|
146 |
throw new FactoryConfigurationError(e.getException(),
|
|
147 |
e.getMessage());
|
|
148 |
}
|
|
149 |
}
|
|
150 |
|
|
151 |
/**
|
|
152 |
* This method allows setting of the Location on each event that
|
|
153 |
* is created by this factory. The values are copied by value into
|
|
154 |
* the events created by this factory. To reset the location
|
|
155 |
* information set the location to null.
|
|
156 |
* @param location the location to set on each event created
|
|
157 |
*/
|
|
158 |
public abstract void setLocation(Location location);
|
|
159 |
|
|
160 |
/**
|
|
161 |
* Create a new Attribute
|
|
162 |
* @param prefix the prefix of this attribute, may not be null
|
|
163 |
* @param namespaceURI the attribute value is set to this value, may not be null
|
|
164 |
* @param localName the local name of the XML name of the attribute, localName cannot be null
|
|
165 |
* @param value the attribute value to set, may not be null
|
|
166 |
* @return the Attribute with specified values
|
|
167 |
*/
|
|
168 |
public abstract Attribute createAttribute(String prefix, String namespaceURI, String localName, String value);
|
|
169 |
|
|
170 |
/**
|
|
171 |
* Create a new Attribute
|
|
172 |
* @param localName the local name of the XML name of the attribute, localName cannot be null
|
|
173 |
* @param value the attribute value to set, may not be null
|
|
174 |
* @return the Attribute with specified values
|
|
175 |
*/
|
|
176 |
public abstract Attribute createAttribute(String localName, String value);
|
|
177 |
|
|
178 |
/**
|
|
179 |
* Create a new Attribute
|
|
180 |
* @param name the qualified name of the attribute, may not be null
|
|
181 |
* @param value the attribute value to set, may not be null
|
|
182 |
* @return the Attribute with specified values
|
|
183 |
*/
|
|
184 |
public abstract Attribute createAttribute(QName name, String value);
|
|
185 |
|
|
186 |
/**
|
|
187 |
* Create a new default Namespace
|
|
188 |
* @param namespaceURI the default namespace uri
|
|
189 |
* @return the Namespace with the specified value
|
|
190 |
*/
|
|
191 |
public abstract Namespace createNamespace(String namespaceURI);
|
|
192 |
|
|
193 |
/**
|
|
194 |
* Create a new Namespace
|
|
195 |
* @param prefix the prefix of this namespace, may not be null
|
|
196 |
* @param namespaceUri the attribute value is set to this value, may not be null
|
|
197 |
* @return the Namespace with the specified values
|
|
198 |
*/
|
|
199 |
public abstract Namespace createNamespace(String prefix, String namespaceUri);
|
|
200 |
|
|
201 |
/**
|
|
202 |
* Create a new StartElement. Namespaces can be added to this StartElement
|
|
203 |
* by passing in an Iterator that walks over a set of Namespace interfaces.
|
|
204 |
* Attributes can be added to this StartElement by passing an iterator
|
|
205 |
* that walks over a set of Attribute interfaces.
|
|
206 |
*
|
|
207 |
* @param name the qualified name of the attribute, may not be null
|
|
208 |
* @param attributes an optional unordered set of objects that
|
|
209 |
* implement Attribute to add to the new StartElement, may be null
|
|
210 |
* @param namespaces an optional unordered set of objects that
|
|
211 |
* implement Namespace to add to the new StartElement, may be null
|
|
212 |
* @return an instance of the requested StartElement
|
|
213 |
*/
|
|
214 |
public abstract StartElement createStartElement(QName name,
|
|
215 |
Iterator attributes,
|
|
216 |
Iterator namespaces);
|
|
217 |
|
|
218 |
/**
|
|
219 |
* Create a new StartElement. This defaults the NamespaceContext to
|
|
220 |
* an empty NamespaceContext. Querying this event for its namespaces or
|
|
221 |
* attributes will result in an empty iterator being returned.
|
|
222 |
*
|
|
223 |
* @param namespaceUri the uri of the QName of the new StartElement
|
|
224 |
* @param localName the local name of the QName of the new StartElement
|
|
225 |
* @param prefix the prefix of the QName of the new StartElement
|
|
226 |
* @return an instance of the requested StartElement
|
|
227 |
*/
|
|
228 |
public abstract StartElement createStartElement(String prefix,
|
|
229 |
String namespaceUri,
|
|
230 |
String localName);
|
|
231 |
/**
|
|
232 |
* Create a new StartElement. Namespaces can be added to this StartElement
|
|
233 |
* by passing in an Iterator that walks over a set of Namespace interfaces.
|
|
234 |
* Attributes can be added to this StartElement by passing an iterator
|
|
235 |
* that walks over a set of Attribute interfaces.
|
|
236 |
*
|
|
237 |
* @param namespaceUri the uri of the QName of the new StartElement
|
|
238 |
* @param localName the local name of the QName of the new StartElement
|
|
239 |
* @param prefix the prefix of the QName of the new StartElement
|
|
240 |
* @param attributes an unordered set of objects that implement
|
|
241 |
* Attribute to add to the new StartElement
|
|
242 |
* @param namespaces an unordered set of objects that implement
|
|
243 |
* Namespace to add to the new StartElement
|
|
244 |
* @return an instance of the requested StartElement
|
|
245 |
*/
|
|
246 |
public abstract StartElement createStartElement(String prefix,
|
|
247 |
String namespaceUri,
|
|
248 |
String localName,
|
|
249 |
Iterator attributes,
|
|
250 |
Iterator namespaces
|
|
251 |
);
|
|
252 |
/**
|
|
253 |
* Create a new StartElement. Namespaces can be added to this StartElement
|
|
254 |
* by passing in an Iterator that walks over a set of Namespace interfaces.
|
|
255 |
* Attributes can be added to this StartElement by passing an iterator
|
|
256 |
* that walks over a set of Attribute interfaces.
|
|
257 |
*
|
|
258 |
* @param namespaceUri the uri of the QName of the new StartElement
|
|
259 |
* @param localName the local name of the QName of the new StartElement
|
|
260 |
* @param prefix the prefix of the QName of the new StartElement
|
|
261 |
* @param attributes an unordered set of objects that implement
|
|
262 |
* Attribute to add to the new StartElement, may be null
|
|
263 |
* @param namespaces an unordered set of objects that implement
|
|
264 |
* Namespace to add to the new StartElement, may be null
|
|
265 |
* @param context the namespace context of this element
|
|
266 |
* @return an instance of the requested StartElement
|
|
267 |
*/
|
|
268 |
public abstract StartElement createStartElement(String prefix,
|
|
269 |
String namespaceUri,
|
|
270 |
String localName,
|
|
271 |
Iterator attributes,
|
|
272 |
Iterator namespaces,
|
|
273 |
NamespaceContext context
|
|
274 |
);
|
|
275 |
|
|
276 |
/**
|
|
277 |
* Create a new EndElement
|
|
278 |
* @param name the qualified name of the EndElement
|
|
279 |
* @param namespaces an optional unordered set of objects that
|
|
280 |
* implement Namespace that have gone out of scope, may be null
|
|
281 |
* @return an instance of the requested EndElement
|
|
282 |
*/
|
|
283 |
public abstract EndElement createEndElement(QName name,
|
|
284 |
Iterator namespaces);
|
|
285 |
|
|
286 |
/**
|
|
287 |
* Create a new EndElement
|
|
288 |
* @param namespaceUri the uri of the QName of the new StartElement
|
|
289 |
* @param localName the local name of the QName of the new StartElement
|
|
290 |
* @param prefix the prefix of the QName of the new StartElement
|
|
291 |
* @return an instance of the requested EndElement
|
|
292 |
*/
|
|
293 |
public abstract EndElement createEndElement(String prefix,
|
|
294 |
String namespaceUri,
|
|
295 |
String localName);
|
|
296 |
/**
|
|
297 |
* Create a new EndElement
|
|
298 |
* @param namespaceUri the uri of the QName of the new StartElement
|
|
299 |
* @param localName the local name of the QName of the new StartElement
|
|
300 |
* @param prefix the prefix of the QName of the new StartElement
|
|
301 |
* @param namespaces an unordered set of objects that implement
|
|
302 |
* Namespace that have gone out of scope, may be null
|
|
303 |
* @return an instance of the requested EndElement
|
|
304 |
*/
|
|
305 |
public abstract EndElement createEndElement(String prefix,
|
|
306 |
String namespaceUri,
|
|
307 |
String localName,
|
|
308 |
Iterator namespaces);
|
|
309 |
|
|
310 |
/**
|
|
311 |
* Create a Characters event, this method does not check if the content
|
|
312 |
* is all whitespace. To create a space event use #createSpace(String)
|
|
313 |
* @param content the string to create
|
|
314 |
* @return a Characters event
|
|
315 |
*/
|
|
316 |
public abstract Characters createCharacters(String content);
|
|
317 |
|
|
318 |
/**
|
|
319 |
* Create a Characters event with the CData flag set to true
|
|
320 |
* @param content the string to create
|
|
321 |
* @return a Characters event
|
|
322 |
*/
|
|
323 |
public abstract Characters createCData(String content);
|
|
324 |
|
|
325 |
/**
|
|
326 |
* Create a Characters event with the isSpace flag set to true
|
|
327 |
* @param content the content of the space to create
|
|
328 |
* @return a Characters event
|
|
329 |
*/
|
|
330 |
public abstract Characters createSpace(String content);
|
|
331 |
/**
|
|
332 |
* Create an ignorable space
|
|
333 |
* @param content the space to create
|
|
334 |
* @return a Characters event
|
|
335 |
*/
|
|
336 |
public abstract Characters createIgnorableSpace(String content);
|
|
337 |
|
|
338 |
/**
|
|
339 |
* Creates a new instance of a StartDocument event
|
|
340 |
* @return a StartDocument event
|
|
341 |
*/
|
|
342 |
public abstract StartDocument createStartDocument();
|
|
343 |
|
|
344 |
/**
|
|
345 |
* Creates a new instance of a StartDocument event
|
|
346 |
*
|
|
347 |
* @param encoding the encoding style
|
|
348 |
* @param version the XML version
|
|
349 |
* @param standalone the status of standalone may be set to "true" or "false"
|
|
350 |
* @return a StartDocument event
|
|
351 |
*/
|
|
352 |
public abstract StartDocument createStartDocument(String encoding,
|
|
353 |
String version,
|
|
354 |
boolean standalone);
|
|
355 |
|
|
356 |
/**
|
|
357 |
* Creates a new instance of a StartDocument event
|
|
358 |
*
|
|
359 |
* @param encoding the encoding style
|
|
360 |
* @param version the XML version
|
|
361 |
* @return a StartDocument event
|
|
362 |
*/
|
|
363 |
public abstract StartDocument createStartDocument(String encoding,
|
|
364 |
String version);
|
|
365 |
|
|
366 |
/**
|
|
367 |
* Creates a new instance of a StartDocument event
|
|
368 |
*
|
|
369 |
* @param encoding the encoding style
|
|
370 |
* @return a StartDocument event
|
|
371 |
*/
|
|
372 |
public abstract StartDocument createStartDocument(String encoding);
|
|
373 |
|
|
374 |
/**
|
|
375 |
* Creates a new instance of an EndDocument event
|
|
376 |
* @return an EndDocument event
|
|
377 |
*/
|
|
378 |
public abstract EndDocument createEndDocument();
|
|
379 |
|
|
380 |
/** Creates a new instance of a EntityReference event
|
|
381 |
*
|
|
382 |
* @param name The name of the reference
|
|
383 |
* @param declaration the declaration for the event
|
|
384 |
* @return an EntityReference event
|
|
385 |
*/
|
|
386 |
public abstract EntityReference createEntityReference(String name,
|
|
387 |
EntityDeclaration declaration);
|
|
388 |
/**
|
|
389 |
* Create a comment
|
|
390 |
* @param text The text of the comment
|
|
391 |
* a Comment event
|
|
392 |
*/
|
|
393 |
public abstract Comment createComment(String text);
|
|
394 |
|
|
395 |
/**
|
|
396 |
* Create a processing instruction
|
|
397 |
* @param target The target of the processing instruction
|
|
398 |
* @param data The text of the processing instruction
|
|
399 |
* @return a ProcessingInstruction event
|
|
400 |
*/
|
|
401 |
public abstract ProcessingInstruction createProcessingInstruction(String target,
|
|
402 |
String data);
|
|
403 |
|
|
404 |
/**
|
|
405 |
* Create a document type definition event
|
|
406 |
* This string contains the entire document type declaration that matches
|
|
407 |
* the doctypedecl in the XML 1.0 specification
|
|
408 |
* @param dtd the text of the document type definition
|
|
409 |
* @return a DTD event
|
|
410 |
*/
|
|
411 |
public abstract DTD createDTD(String dtd);
|
|
412 |
}
|