186
Performance Considerations
cessing model so that it can efficiently process large XML documents. When
Xpath expressions are matched during parsing, registered handlers can be called
back, thus allowing you to immediately process and dispose of parts of the docu
ment without waiting for the entire document to be parsed and loaded into
memory.
When receiving documents through a service endpoint (either a JAX RPC or
EJB service endpoint) documents are parsed as abstract
Source
objects. As
already noted, do not assume a specific implementation
StreamSource
,
SAXSource
, or
DOMSource
for an incoming document. Instead, you should ensure
that the optimal API is used to bridge between the specific
Source
implementation
passed to the endpoint and the intended processing model. Keep in mind that the
JAXP XSLT API does not guarantee that identity transformations are applied in
the most effective way. For example, when applying an identity transformation
from a DOM tree to a DOM tree, the most effective way is to return the source
tree as the result tree without further processing; however, this behavior is not
enforced by the JAXP specification.
A developer may also want to implement stream processing for the applica
tion so that it can receive the processing requirements as part of the SOAP request
and start processing the document before it is completely received. Document
processing in this manner improves overall performance and is useful when
passing very large documents. Extreme caution should be taken if doing this,
since there is no guarantee that the underlying JAX RPC implementation will not
wait to receive the complete document before passing the
Source
object to the
endpoint and that it will effectively pass a
Source
object that allows for stream
processing, such as
StreamSource
or
SAXSource
. The same holds true when imple
menting stream processing for outgoing documents. While you can pass a
Source
object that allows for stream processing, there is no guarantee on how the underly
ing JAX RPC implementation will actually handle it.
4.5.3 Choose Effective Parser and Style Sheet Implementations
Each parser and style sheet engine implementation is different. For example, one
might emphasize functionality, while another performance. A developer might want
to use different implementations depending on the task to be accomplished. Con
sider using JAXP, which not only supports many parsers and style sheet engines, but
also has a pluggability feature that allows a developer to swap between implementa
tions and select the most effective implementation for an application's requirements.
New Page 1