Sun's Streaming Parser Implementation
The Sun Java System Application Server (SJSAS) PE 9.0 package includes Sun Microsystem's JSR 173 (StAX) implementation, called the Sun Java Streaming XML Parser (SJSXP). The SJSXP is a high-speed, non-validating, W3C XML 1.0 and Namespace 1.0-compliant streaming XML pull parser built upon the Xerces2 codebase.
In Sun's SJSXP implementation, the Xerces2 lower layers, particularly the Scanner and related classes, have been redesigned to behave in a pull fashion. In addition to the changes the lower layers, the SJSXP includes additional StAX-related functionality and many performance-enhancing improvements. The SJSXP is implemented in
appserv-ws.jar
andjavaee.jar
, both of which are located in the<javaee.home>/lib
directory.Included with this Java EE tutorial are StAX code samples, located in the
<javaee.tutorial.home>/examples/stax
directory, that illustrate how Sun's SJSXP implementation works. These samples are described in the Sample Code section, later in this chapter.Before proceeding with the sample code, there are two important aspects of the SJSXP about which you should be aware:
These two topics are discussed below.
Reporting CDATA Events
The
javax.xml.stream.XMLStreamReader
implemented in the SJSXP does not report CDATA events. If you have an application that needs to receive such events, configure theXMLInputFactory
to set the following implementation-specific "report-cdata-event" property:XMLInputFactory factory = XMLInptuFactory.newInstance(); factory.setProperty("report-cdata-event", Boolean.TRUE);SJSXP Factories Implementation
Most applications do not need to know the factory implementation class name. Just adding the
javaee.jar
andappserv-ws.jar
files to the classpath is sufficient for most applications because these two jars supply the factory implementation classname for various SJSXP properties under theMETA-INF/services
directory--for example,javax.xml.stream.XMLInputFactory
,javax.xml.stream.XMLOutputFactory
, andjavax.xml.stream.XMLEventFactory
--which is the third step of a lookup operation when an application asks for the factory instance. See the javadoc for theXMLInputFactory.newInstance()
method for more information about the lookup mechanism.However, there may be scenarios when an application would like to know about the factory implementation class name and set the property explicitly. These scenarios could include cases where there are multiple JSR 173 implementations in the classpath and the application wants to choose one, perhaps one that has superior performance, contains a crucial bug fix, or suchlike.
If an application sets the
SystemProperty
, it is the first step in a lookup operation, and so obtaining the factory instance would be fast compared to other options; for example: