|
JADE v6.1 | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.dautelle.xml.sax.RealtimeParser
This class provides a real-time SAX2-like XML parser; this parser is extremely fast and does not create temporary objects (no garbage generated and no GC interruption).
This parser is light (less than 15Kbytes compressed) and maintains a very small memory footprint while parsing (e.g. less than 16Kbytes while parsing 32Mbytes files). Typical applications include SOAP messaging, embedded/realtime systems, web servers (possibly thousands instances running concurrently), etc.
Namespaces (SAX2 feature), comments, predefined entities
(&, <, >, ', "
)
numeric character references (e.g.
for
linefeed) and CDATA
are recognized. Processing instructions,
comments and entities declarations are ignored.
The CharSequence
generated by this parser have
the following characteristics:
CharSequence
created while parsing an XML element are
reused only after the element is out-of-scope. In other words,
when the endElement
method is called, all
attributes specified by startElement
are still
intact.CharSequence
(e.g. String
).String
and can be
used to retrieve data from a Map
(e.g.
FastMap
) for which
the keys are String
instances.CharSequence
, they can be parsed
to primitive types (e.g. int, double) using the utility class
TypeFormat
. Finally, this parser does not break up character data during call back
(the whole character data between markups is always being returned).
During parsing, no memory allocation is ever performed unless the
data buffer capacity (see property
"http://jade.dautelle/sax/properties/capacity"
) is too
small to hold the whole character data. In which case, the internal data
buffer is automatically re-sized.
Note: This parser is a SAX2-like parser with the
java.lang.String
type replaced by the more generic
java.lang.CharSequence
in ContentHandler
,
Attributes
interfaces and DefaultHandler
base classes.
If a standard SAX2 or JAXP parser is required, you may consider using
the wrapping class XMLReaderImpl
. Fast but not as fast as
java.lang.String
instances are dynamically allocated
while parsing.
Constructor Summary | |
RealtimeParser()
Default constructor. |
Method Summary | |
ContentHandler |
getContentHandler()
Returns the current real-time content handler. |
org.xml.sax.DTDHandler |
getDTDHandler()
Returns the current DTD handler. |
org.xml.sax.EntityResolver |
getEntityResolver()
Returns the current entity resolver. |
org.xml.sax.ErrorHandler |
getErrorHandler()
Returns the current error handler. |
boolean |
getFeature(java.lang.String name)
Looks up the value of a feature. |
java.lang.Object |
getProperty(java.lang.String name)
Look up the value of a property. |
void |
parse(org.xml.sax.InputSource input)
Parses an XML document; this method does not allocate any object and is extremely fast. |
void |
parse(java.lang.String systemId)
Parses an XML document from a system identifier (URI). |
void |
setContentHandler(ContentHandler handler)
Allows an application to register a real-time content event handler. |
void |
setDTDHandler(org.xml.sax.DTDHandler handler)
Allows an application to register a DTD handler (ignored by this parser). |
void |
setEntityResolver(org.xml.sax.EntityResolver resolver)
Allows an application to register an entity resolver (ignored by this parser). |
void |
setErrorHandler(org.xml.sax.ErrorHandler handler)
Allows an application to register an error event handler. |
void |
setFeature(java.lang.String name,
boolean value)
Sets the state of a feature. |
void |
setProperty(java.lang.String name,
java.lang.Object value)
Sets the value of a property. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public RealtimeParser()
Method Detail |
public void setContentHandler(ContentHandler handler)
If the application does not register a content handler, all content events reported by the SAX parser will be silently ignored.
Applications may register a new or different handler in the middle of a parse, and the SAX parser must begin using the new handler immediately.
handler
- the real-time content handler.
java.lang.NullPointerException
- if the handler argument is null.getContentHandler()
public ContentHandler getContentHandler()
null
if none has been registered.setContentHandler(com.dautelle.xml.sax.ContentHandler)
public void setErrorHandler(org.xml.sax.ErrorHandler handler)
If the application does not register an error handler, all error events reported by the SAX parser will be silently ignored; however, normal processing may not continue. It is highly recommended that all SAX applications implement an error handler to avoid unexpected bugs.
Applications may register a new or different handler in the middle of a parse, and the SAX parser must begin using the new handler immediately.
handler
- the error handler.
java.lang.NullPointerException
- if the handler argument is null.getErrorHandler()
public org.xml.sax.ErrorHandler getErrorHandler()
null
if none
has been registered.setErrorHandler(org.xml.sax.ErrorHandler)
public void parse(java.lang.String systemId) throws java.io.IOException, org.xml.sax.SAXException
systemId
- the system identifier (URI) or a simple filename.
org.xml.sax.SAXException
- any SAX exception, possibly
wrapping another exception.
java.io.IOException
- an IO exception from the parser,
possibly from a byte stream or character stream
supplied by the application.parse(org.xml.sax.InputSource)
public void parse(org.xml.sax.InputSource input) throws java.io.IOException, org.xml.sax.SAXException
The application can use this method to instruct the XML reader to begin parsing an XML document from any valid input source (a character stream, a byte stream, or a URI).
During the parse, the XMLReader
will provide information
about the XML document through the registered event
handlers.
This method is synchronous: it will not return until parsing has ended. If a client application wants to terminate parsing early, it should throw an exception.
If the input source is an input stream and the encoding is not specified, UTF-8 encoding is assumed.
input
- the input source for the top-level of the XML document.
org.xml.sax.SAXException
- any SAX exception, possibly wrapping another
exception.
java.io.IOException
- an IO exception from the parser, possibly from
a byte stream or character stream supplied by the application.public boolean getFeature(java.lang.String name) throws org.xml.sax.SAXNotRecognizedException, org.xml.sax.SAXNotSupportedException
Recognizes http://xml.org/sax/features/namespaces
and the http://xml.org/sax/features/namespace-prefixes
feature names.
name
- the feature name, which is a fully-qualified URI.
org.xml.sax.SAXNotRecognizedException
- when the XMLReader does
not recognize the feature name.
org.xml.sax.SAXNotSupportedException
- when the XMLReader
recognizes the feature name but cannot determine its value
at this time.setFeature(java.lang.String, boolean)
public void setFeature(java.lang.String name, boolean value) throws org.xml.sax.SAXNotRecognizedException, org.xml.sax.SAXNotSupportedException
Recognizes http://xml.org/sax/features/namespaces
and the http://xml.org/sax/features/namespace-prefixes
feature names.
name
- the feature name, which is a fully-qualified URI.value
- the requested state of the feature (true or false).
org.xml.sax.SAXNotRecognizedException
- when the XMLReader does not
recognize the feature name.
org.xml.sax.SAXNotSupportedException
- when the XMLReader
recognizes the feature name but cannot set the requested value.getFeature(java.lang.String)
public java.lang.Object getProperty(java.lang.String name) throws org.xml.sax.SAXNotRecognizedException, org.xml.sax.SAXNotSupportedException
XMLReaderImpl
) supports the property:
"http://jade.dautelle/sax/properties/capacity"
, which holds
the initial data buffer capacity (instance of
java.lang.Number
, default 2048
).
name
- the property name, which is a fully-qualified URI.
org.xml.sax.SAXNotRecognizedException
- when the
XMLReader does not recognize the property name.
org.xml.sax.SAXNotSupportedException
- when the
XMLReader recognizes the property name but
cannot determine its value at this time.setProperty(java.lang.String, java.lang.Object)
public void setProperty(java.lang.String name, java.lang.Object value) throws org.xml.sax.SAXNotRecognizedException, org.xml.sax.SAXNotSupportedException
XMLReaderImpl
) supports the property:
"http://jade.dautelle/sax/properties/capacity"
, which holds
the initial data buffer capacity (instance of
java.lang.Number
, default 2048
).
For example:sax2Parser.setProperty( "http://jade.dautelle/sax/properties/capacity", new Integer(2*1024*1024)); // Capable of holding character data (e.g. CDATA) // of up to 2 MegaBytes without resizing.
name
- the property name, which is a fully-qualified URI.value
- the requested value for the property.
org.xml.sax.SAXNotRecognizedException
- when the
XMLReader does not recognize the property name.
org.xml.sax.SAXNotSupportedException
- when the
XMLReader recognizes the property name but
cannot set the requested value.public void setEntityResolver(org.xml.sax.EntityResolver resolver)
resolver
- the entity resolver.public org.xml.sax.EntityResolver getEntityResolver()
null
if none
has been registered.setEntityResolver(org.xml.sax.EntityResolver)
public void setDTDHandler(org.xml.sax.DTDHandler handler)
handler
- the DTD handler.public org.xml.sax.DTDHandler getDTDHandler()
null
if none
has been registered.setDTDHandler(org.xml.sax.DTDHandler)
|
JADE v6.1 | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |