Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/src/java.xml/share/classes/javax/xml/stream/XMLEventFactory.java
40948 views
1
/*
2
* Copyright (c) 2009, 2021, Oracle and/or its affiliates. All rights reserved.
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
26
package javax.xml.stream;
27
import com.sun.xml.internal.stream.events.XMLEventFactoryImpl;
28
import java.util.Iterator;
29
import javax.xml.namespace.NamespaceContext;
30
import javax.xml.namespace.QName;
31
import javax.xml.stream.events.*;
32
/**
33
* This interface defines a utility class for creating instances of
34
* XMLEvents
35
* @version 1.2
36
* @author Copyright (c) 2009 by Oracle Corporation. All Rights Reserved.
37
* @see javax.xml.stream.events.StartElement
38
* @see javax.xml.stream.events.EndElement
39
* @see javax.xml.stream.events.ProcessingInstruction
40
* @see javax.xml.stream.events.Comment
41
* @see javax.xml.stream.events.Characters
42
* @see javax.xml.stream.events.StartDocument
43
* @see javax.xml.stream.events.EndDocument
44
* @see javax.xml.stream.events.DTD
45
* @since 1.6
46
*/
47
public abstract class XMLEventFactory {
48
static final String JAXPFACTORYID = "javax.xml.stream.XMLEventFactory";
49
static final String DEFAULIMPL = "com.sun.xml.internal.stream.events.XMLEventFactoryImpl";
50
51
/**
52
* Protected constructor to prevent instantiation.
53
* Use {@link #newFactory()} instead.
54
*/
55
protected XMLEventFactory(){}
56
57
/**
58
* Creates a new instance of the {@code XMLEventFactory} builtin
59
* system-default implementation.
60
*
61
* @return A new instance of the {@code XMLEventFactory} builtin
62
* system-default implementation.
63
*
64
* @since 9
65
*/
66
public static XMLEventFactory newDefaultFactory() {
67
return new XMLEventFactoryImpl();
68
}
69
70
/**
71
* Creates a new instance of the factory in exactly the same manner as the
72
* {@link #newFactory()} method.
73
*
74
* @return an instance of the {@code XMLEventFactory}
75
* @throws FactoryConfigurationError if an instance of this factory cannot be loaded
76
*/
77
public static XMLEventFactory newInstance()
78
throws FactoryConfigurationError
79
{
80
return FactoryFinder.find(XMLEventFactory.class, DEFAULIMPL);
81
}
82
83
/**
84
* Creates a new instance of the factory. This method uses the
85
* <a href="../../../module-summary.html#LookupMechanism">JAXP Lookup Mechanism</a>
86
* to determine the {@code XMLEventFactory} implementation class to load.
87
* <p>
88
* Once an application has obtained a reference to a {@code XMLEventFactory}, it
89
* can use the factory to configure and obtain stream instances.
90
*
91
* @return an instance of the {@code XMLEventFactory}
92
* @throws FactoryConfigurationError in case of {@linkplain
93
* java.util.ServiceConfigurationError service configuration error} or if
94
* the implementation is not available or cannot be instantiated.
95
*/
96
public static XMLEventFactory newFactory()
97
throws FactoryConfigurationError
98
{
99
return FactoryFinder.find(XMLEventFactory.class, DEFAULIMPL);
100
}
101
102
/**
103
* Create a new instance of the factory
104
*
105
* @param factoryId Name of the factory to find, same as
106
* a property name
107
* @param classLoader classLoader to use
108
* @return the factory implementation
109
* @throws FactoryConfigurationError if an instance of this factory cannot be loaded
110
*
111
* @deprecated This method has been deprecated to maintain API consistency.
112
* All newInstance methods have been replaced with corresponding
113
* newFactory methods. The replacement {@link
114
* #newFactory(java.lang.String, java.lang.ClassLoader)}
115
* method defines no changes in behavior.
116
*/
117
@Deprecated(since="1.7")
118
public static XMLEventFactory newInstance(String factoryId,
119
ClassLoader classLoader)
120
throws FactoryConfigurationError {
121
//do not fallback if given classloader can't find the class, throw exception
122
return FactoryFinder.find(XMLEventFactory.class, factoryId, classLoader, null);
123
}
124
125
/**
126
* Create a new instance of the factory.
127
* If the classLoader argument is null, then the ContextClassLoader is used.
128
* <p>
129
* This method uses the following ordered lookup procedure to determine
130
* the XMLEventFactory implementation class to load:
131
* <ul>
132
* <li>
133
* Use the value of the system property identified by {@code factoryId}.
134
* </li>
135
* <li>
136
* <p>
137
* Use the configuration file "stax.properties". The file is in standard
138
* {@link java.util.Properties} format and typically located in the
139
* conf directory of the Java installation. It contains the fully qualified
140
* name of the implementation class with the key being the system property
141
* defined above.
142
*
143
* <p>
144
* The stax.properties file is read only once by the implementation
145
* and its values are then cached for future use. If the file does not exist
146
* when the first attempt is made to read from it, no further attempts are
147
* made to check for its existence. It is not possible to change the value
148
* of any property in stax.properties after it has been read for the first time.
149
*
150
* <p>
151
* Use the jaxp configuration file "jaxp.properties". The file is in the same
152
* format as stax.properties and will only be read if stax.properties does
153
* not exist.
154
* </li>
155
* <li>
156
* <p>
157
* If {@code factoryId} is "javax.xml.stream.XMLEventFactory",
158
* use the service-provider loading facility, defined by the
159
* {@link java.util.ServiceLoader} class, to attempt to {@linkplain
160
* java.util.ServiceLoader#load(java.lang.Class, java.lang.ClassLoader) locate and load}
161
* an implementation of the service using the specified {@code ClassLoader}.
162
* If {@code classLoader} is null, the {@linkplain
163
* java.util.ServiceLoader#load(java.lang.Class) default loading mechanism} will apply:
164
* That is, the service-provider loading facility will use the {@linkplain
165
* java.lang.Thread#getContextClassLoader() current thread's context class loader}
166
* to attempt to load the service. If the context class
167
* loader is null, the {@linkplain
168
* ClassLoader#getSystemClassLoader() system class loader} will be used.
169
* </li>
170
* <li>
171
* <p>
172
* Otherwise, throws a {@link FactoryConfigurationError}.
173
* </li>
174
* </ul>
175
*
176
* <p>
177
* Note that this is a new method that replaces the deprecated
178
* {@link #newInstance(java.lang.String, java.lang.ClassLoader)
179
* newInstance(String factoryId, ClassLoader classLoader)} method.
180
* No changes in behavior are defined by this replacement method relative
181
* to the deprecated method.
182
*
183
* @apiNote The parameter factoryId defined here is inconsistent with that
184
* of other JAXP factories where the first parameter is fully qualified
185
* factory class name that provides implementation of the factory.
186
*
187
* @param factoryId Name of the factory to find, same as
188
* a property name
189
* @param classLoader classLoader to use
190
* @return the factory implementation
191
* @throws FactoryConfigurationError in case of {@linkplain
192
* java.util.ServiceConfigurationError service configuration error} or if
193
* the implementation is not available or cannot be instantiated.
194
*/
195
public static XMLEventFactory newFactory(String factoryId,
196
ClassLoader classLoader)
197
throws FactoryConfigurationError {
198
//do not fallback if given classloader can't find the class, throw exception
199
return FactoryFinder.find(XMLEventFactory.class, factoryId, classLoader, null);
200
}
201
202
/**
203
* This method allows setting of the Location on each event that
204
* is created by this factory. The values are copied by value into
205
* the events created by this factory. To reset the location
206
* information set the location to null.
207
* @param location the location to set on each event created
208
*/
209
public abstract void setLocation(Location location);
210
211
/**
212
* Create a new Attribute
213
* @param prefix the prefix of this attribute, may not be null
214
* @param namespaceURI the attribute value is set to this value, may not be null
215
* @param localName the local name of the XML name of the attribute, localName cannot be null
216
* @param value the attribute value to set, may not be null
217
* @return the Attribute with specified values
218
*/
219
public abstract Attribute createAttribute(String prefix, String namespaceURI, String localName, String value);
220
221
/**
222
* Create a new Attribute
223
* @param localName the local name of the XML name of the attribute, localName cannot be null
224
* @param value the attribute value to set, may not be null
225
* @return the Attribute with specified values
226
*/
227
public abstract Attribute createAttribute(String localName, String value);
228
229
/**
230
* Create a new Attribute
231
* @param name the qualified name of the attribute, may not be null
232
* @param value the attribute value to set, may not be null
233
* @return the Attribute with specified values
234
*/
235
public abstract Attribute createAttribute(QName name, String value);
236
237
/**
238
* Create a new default Namespace
239
* @param namespaceURI the default namespace uri
240
* @return the Namespace with the specified value
241
*/
242
public abstract Namespace createNamespace(String namespaceURI);
243
244
/**
245
* Create a new Namespace
246
* @param prefix the prefix of this namespace, may not be null
247
* @param namespaceUri the attribute value is set to this value, may not be null
248
* @return the Namespace with the specified values
249
*/
250
public abstract Namespace createNamespace(String prefix, String namespaceUri);
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 name the qualified name of the attribute, may not be null
259
* @param attributes an optional unordered set of objects that
260
* implement Attribute to add to the new StartElement, may be null
261
* @param namespaces an optional unordered set of objects that
262
* implement Namespace to add to the new StartElement, may be null
263
* @return an instance of the requested StartElement
264
*/
265
public abstract StartElement createStartElement(QName name,
266
Iterator<? extends Attribute> attributes,
267
Iterator<? extends Namespace> namespaces);
268
269
/**
270
* Create a new StartElement. This defaults the NamespaceContext to
271
* an empty NamespaceContext. Querying this event for its namespaces or
272
* attributes will result in an empty iterator being returned.
273
*
274
* @param namespaceUri the uri of the QName of the new StartElement
275
* @param localName the local name of the QName of the new StartElement
276
* @param prefix the prefix of the QName of the new StartElement
277
* @return an instance of the requested StartElement
278
*/
279
public abstract StartElement createStartElement(String prefix,
280
String namespaceUri,
281
String localName);
282
/**
283
* Create a new StartElement. Namespaces can be added to this StartElement
284
* by passing in an Iterator that walks over a set of Namespace interfaces.
285
* Attributes can be added to this StartElement by passing an iterator
286
* that walks over a set of Attribute interfaces.
287
*
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
* @param attributes an unordered set of objects that implement
292
* Attribute to add to the new StartElement
293
* @param namespaces an unordered set of objects that implement
294
* Namespace to add to the new StartElement
295
* @return an instance of the requested StartElement
296
*/
297
public abstract StartElement createStartElement(String prefix,
298
String namespaceUri,
299
String localName,
300
Iterator<? extends Attribute> attributes,
301
Iterator<? extends Namespace> namespaces
302
);
303
/**
304
* Create a new StartElement. Namespaces can be added to this StartElement
305
* by passing in an Iterator that walks over a set of Namespace interfaces.
306
* Attributes can be added to this StartElement by passing an iterator
307
* that walks over a set of Attribute interfaces.
308
*
309
* @param namespaceUri the uri of the QName of the new StartElement
310
* @param localName the local name of the QName of the new StartElement
311
* @param prefix the prefix of the QName of the new StartElement
312
* @param attributes an unordered set of objects that implement
313
* Attribute to add to the new StartElement, may be null
314
* @param namespaces an unordered set of objects that implement
315
* Namespace to add to the new StartElement, may be null
316
* @param context the namespace context of this element
317
* @return an instance of the requested StartElement
318
*/
319
public abstract StartElement createStartElement(String prefix,
320
String namespaceUri,
321
String localName,
322
Iterator<? extends Attribute> attributes,
323
Iterator<? extends Namespace> namespaces,
324
NamespaceContext context
325
);
326
327
/**
328
* Create a new EndElement
329
* @param name the qualified name of the EndElement
330
* @param namespaces an optional unordered set of objects that
331
* implement Namespace that have gone out of scope, may be null
332
* @return an instance of the requested EndElement
333
*/
334
public abstract EndElement createEndElement(QName name,
335
Iterator<? extends Namespace> namespaces);
336
337
/**
338
* Create a new EndElement
339
* @param namespaceUri the uri of the QName of the new StartElement
340
* @param localName the local name of the QName of the new StartElement
341
* @param prefix the prefix of the QName of the new StartElement
342
* @return an instance of the requested EndElement
343
*/
344
public abstract EndElement createEndElement(String prefix,
345
String namespaceUri,
346
String localName);
347
/**
348
* Create a new EndElement
349
* @param namespaceUri the uri of the QName of the new StartElement
350
* @param localName the local name of the QName of the new StartElement
351
* @param prefix the prefix of the QName of the new StartElement
352
* @param namespaces an unordered set of objects that implement
353
* Namespace that have gone out of scope, may be null
354
* @return an instance of the requested EndElement
355
*/
356
public abstract EndElement createEndElement(String prefix,
357
String namespaceUri,
358
String localName,
359
Iterator<? extends Namespace> namespaces);
360
361
/**
362
* Create a Characters event, this method does not check if the content
363
* is all whitespace. To create a space event use #createSpace(String)
364
* @param content the string to create
365
* @return a Characters event
366
*/
367
public abstract Characters createCharacters(String content);
368
369
/**
370
* Create a Characters event with the CData flag set to true
371
* @param content the string to create
372
* @return a Characters event
373
*/
374
public abstract Characters createCData(String content);
375
376
/**
377
* Create a Characters event with the isSpace flag set to true
378
* @param content the content of the space to create
379
* @return a Characters event
380
*/
381
public abstract Characters createSpace(String content);
382
/**
383
* Create an ignorable space
384
* @param content the space to create
385
* @return a Characters event
386
*/
387
public abstract Characters createIgnorableSpace(String content);
388
389
/**
390
* Creates a new instance of a StartDocument event
391
* @return a StartDocument event
392
*/
393
public abstract StartDocument createStartDocument();
394
395
/**
396
* Creates a new instance of a StartDocument event
397
*
398
* @param encoding the encoding style
399
* @param version the XML version
400
* @param standalone the status of standalone may be set to "true" or "false"
401
* @return a StartDocument event
402
*/
403
public abstract StartDocument createStartDocument(String encoding,
404
String version,
405
boolean standalone);
406
407
/**
408
* Creates a new instance of a StartDocument event
409
*
410
* @param encoding the encoding style
411
* @param version the XML version
412
* @return a StartDocument event
413
*/
414
public abstract StartDocument createStartDocument(String encoding,
415
String version);
416
417
/**
418
* Creates a new instance of a StartDocument event
419
*
420
* @param encoding the encoding style
421
* @return a StartDocument event
422
*/
423
public abstract StartDocument createStartDocument(String encoding);
424
425
/**
426
* Creates a new instance of an EndDocument event
427
* @return an EndDocument event
428
*/
429
public abstract EndDocument createEndDocument();
430
431
/** Creates a new instance of a EntityReference event
432
*
433
* @param name The name of the reference
434
* @param declaration the declaration for the event
435
* @return an EntityReference event
436
*/
437
public abstract EntityReference createEntityReference(String name,
438
EntityDeclaration declaration);
439
/**
440
* Create a comment.
441
* @param text The text of the comment
442
* @return a Comment event
443
*/
444
public abstract Comment createComment(String text);
445
446
/**
447
* Create a processing instruction
448
* @param target The target of the processing instruction
449
* @param data The text of the processing instruction
450
* @return a ProcessingInstruction event
451
*/
452
public abstract ProcessingInstruction createProcessingInstruction(String target,
453
String data);
454
455
/**
456
* Create a document type definition event
457
* This string contains the entire document type declaration that matches
458
* the doctypedecl in the XML 1.0 specification
459
* @param dtd the text of the document type definition
460
* @return a DTD event
461
*/
462
public abstract DTD createDTD(String dtd);
463
}
464
465