APIdia Launch Partner
Top Description Fields Constructors Methods
org.xml.sax.helpers

public final Class XMLReaderFactory

extends Object
Class Inheritance
Annotations
@Deprecated
since:9
Imports
java.io.BufferedReader, .IOException, .InputStream, .InputStreamReader, java.util.Iterator, .Objects, .ServiceConfigurationError, .ServiceLoader, jdk.xml.internal.SecuritySupport, org.xml.sax.SAXException, .XMLReader

Deprecated

since 9.

It is recommended to use javax.xml.parsers.SAXParserFactory instead.

Factory for creating an XML reader.

This class contains static methods for creating an XML reader from an explicit class name, or based on runtime defaults:

try {
  XMLReader myReader = XMLReaderFactory.createXMLReader();
} catch (SAXException e) {
  System.err.println(e.getMessage());
}

Note to Distributions bundled with parsers: You should modify the implementation of the no-arguments createXMLReader to handle cases where the external configuration mechanisms aren't set up. That method should do its best to return a parser when one is in the class path, even when nothing bound its class name to org.xml.sax.driver so those configuration mechanisms would see it.

Author
David Megginson, David Brownell
Since
1.4, SAX 2.0
Version
2.0.1 (sax2r2)

Field Summary

Modifier and TypeField and Description
private static final String

Constructor Summary

AccessConstructor and Description
private
XMLReaderFactory()

Private constructor.

Method Summary

Modifier and TypeMethod and Description
public static XMLReader

Returns:

a new XMLReader.
createXMLReader
()

Obtains a new instance of a org.xml.sax.XMLReader.

public static XMLReader

Returns:

A new XML reader.
createXMLReader
(String
a class name
className
)

Attempt to create an XML reader from a class name.

private static <T> T
findServiceProvider(final Class<T> type, final ClassLoader loader)

private static String

Returns:

the name of the provider, or null if nothing is found
jarLookup
(final ClassLoader
the ClassLoader to be used to read the service file
loader
)

Locates a provider by directly reading the jar service file.

private static XMLReader
loadClass(ClassLoader loader, String className)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

propertyback to summary
private static final String property

Constructor Detail

XMLReaderFactoryback to summary
private XMLReaderFactory()

Private constructor.

This constructor prevents the class from being instantiated.

Method Detail

createXMLReaderback to summary
public static XMLReader createXMLReader() throws SAXException

Obtains a new instance of a org.xml.sax.XMLReader. This method uses the following ordered lookup procedure to find and load the org.xml.sax.XMLReader implementation class:

  1. If the system property org.xml.sax.driver has a value, that is used as an XMLReader class name.
  2. Use the service-provider loading facility, defined by the java.util.ServiceLoader class, to attempt to locate and load an implementation of the service org.xml.sax.XMLReader by using the current thread's context class loader. If the context class loader is null, the system class loader will be used.
  3. Deprecated. Look for a class name in the META-INF/services/org.xml.sax.driver file in a jar file available to the runtime.
  4. Otherwise, the system-default implementation is returned.

API Note

The process that looks for a class name in the META-INF/services/org.xml.sax.driver file in a jar file does not conform to the specification of the service-provider loading facility as defined in java.util.ServiceLoader and therefore does not support modularization. It is deprecated as of Java SE 9 and subject to removal in a future release.

Returns:XMLReader

a new XMLReader.

Exceptions
SAXException:
If no default XMLReader class can be identified and instantiated.
See Also
createXMLReader(java.lang.String)
createXMLReaderback to summary
public static XMLReader createXMLReader(String className) throws SAXException

Attempt to create an XML reader from a class name.

Given a class name, this method attempts to load and instantiate the class as an XML reader.

Note that this method will not be usable in environments where the caller (perhaps an applet) is not permitted to load classes dynamically.

Parameters
className:String

a class name

Returns:XMLReader

A new XML reader.

Exceptions
SAXException:
If the class cannot be loaded, instantiated, and cast to XMLReader.
See Also
createXMLReader()
findServiceProviderback to summary
private static <T> T findServiceProvider(final Class<T> type, final ClassLoader loader) throws SAXException
jarLookupback to summary
private static String jarLookup(final ClassLoader loader)

Locates a provider by directly reading the jar service file.

Parameters
loader:ClassLoader

the ClassLoader to be used to read the service file

Returns:String

the name of the provider, or null if nothing is found

loadClassback to summary
private static XMLReader loadClass(ClassLoader loader, String className) throws SAXException