JADE v6.1

com.dautelle.xml.sax
Class RealtimeParser

java.lang.Object
  extended bycom.dautelle.xml.sax.RealtimeParser

public final class RealtimeParser
extends java.lang.Object

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:

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.

Version:
4.6, June 11, 2003
Author:
Jean-Marie Dautelle

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

RealtimeParser

public RealtimeParser()
Default constructor.

Method Detail

setContentHandler

public void setContentHandler(ContentHandler handler)
Allows an application to register a real-time content event 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.

Parameters:
handler - the real-time content handler.
Throws:
java.lang.NullPointerException - if the handler argument is null.
See Also:
getContentHandler()

getContentHandler

public ContentHandler getContentHandler()
Returns the current real-time content handler.

Returns:
the current real-time content handler, or null if none has been registered.
See Also:
setContentHandler(com.dautelle.xml.sax.ContentHandler)

setErrorHandler

public void setErrorHandler(org.xml.sax.ErrorHandler handler)
Allows an application to register an error event 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.

Parameters:
handler - the error handler.
Throws:
java.lang.NullPointerException - if the handler argument is null.
See Also:
getErrorHandler()

getErrorHandler

public org.xml.sax.ErrorHandler getErrorHandler()
Returns the current error handler.

Returns:
the current error handler, or null if none has been registered.
See Also:
setErrorHandler(org.xml.sax.ErrorHandler)

parse

public void parse(java.lang.String systemId)
           throws java.io.IOException,
                  org.xml.sax.SAXException
Parses an XML document from a system identifier (URI). For convenience, the systemId can also be as simple filename (converts the filename to a "file:" URL instead of throwing an exception.

Parameters:
systemId - the system identifier (URI) or a simple filename.
Throws:
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.
See Also:
parse(org.xml.sax.InputSource)

parse

public void parse(org.xml.sax.InputSource input)
           throws java.io.IOException,
                  org.xml.sax.SAXException
Parses an XML document; this method does not allocate any object and is extremely fast.

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.

Parameters:
input - the input source for the top-level of the XML document.
Throws:
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.

getFeature

public boolean getFeature(java.lang.String name)
                   throws org.xml.sax.SAXNotRecognizedException,
                          org.xml.sax.SAXNotSupportedException
Looks up the value of a feature.

Recognizes http://xml.org/sax/features/namespaces and the http://xml.org/sax/features/namespace-prefixes feature names.

Parameters:
name - the feature name, which is a fully-qualified URI.
Returns:
the current state of the feature (true or false).
Throws:
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.
See Also:
setFeature(java.lang.String, boolean)

setFeature

public void setFeature(java.lang.String name,
                       boolean value)
                throws org.xml.sax.SAXNotRecognizedException,
                       org.xml.sax.SAXNotSupportedException
Sets the state of a feature.

Recognizes http://xml.org/sax/features/namespaces and the http://xml.org/sax/features/namespace-prefixes feature names.

Parameters:
name - the feature name, which is a fully-qualified URI.
value - the requested state of the feature (true or false).
Throws:
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.
See Also:
getFeature(java.lang.String)

getProperty

public java.lang.Object getProperty(java.lang.String name)
                             throws org.xml.sax.SAXNotRecognizedException,
                                    org.xml.sax.SAXNotSupportedException
Look up the value of a property. This parser (and its SAX2 wrapper XMLReaderImpl) supports the property: "http://jade.dautelle/sax/properties/capacity", which holds the initial data buffer capacity (instance of java.lang.Number, default 2048).

Parameters:
name - the property name, which is a fully-qualified URI.
Returns:
the current value of the property.
Throws:
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.
See Also:
setProperty(java.lang.String, java.lang.Object)

setProperty

public void setProperty(java.lang.String name,
                        java.lang.Object value)
                 throws org.xml.sax.SAXNotRecognizedException,
                        org.xml.sax.SAXNotSupportedException
Sets the value of a property. This parser (and its SAX2 wrapper 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.

Parameters:
name - the property name, which is a fully-qualified URI.
value - the requested value for the property.
Throws:
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.

setEntityResolver

public void setEntityResolver(org.xml.sax.EntityResolver resolver)
Allows an application to register an entity resolver (ignored by this parser).

Parameters:
resolver - the entity resolver.

getEntityResolver

public org.xml.sax.EntityResolver getEntityResolver()
Returns the current entity resolver.

Returns:
the current entity resolver, or null if none has been registered.
See Also:
setEntityResolver(org.xml.sax.EntityResolver)

setDTDHandler

public void setDTDHandler(org.xml.sax.DTDHandler handler)
Allows an application to register a DTD handler (ignored by this parser).

Parameters:
handler - the DTD handler.

getDTDHandler

public org.xml.sax.DTDHandler getDTDHandler()
Returns the current DTD handler.

Returns:
the current DTD handler, or null if none has been registered.
See Also:
setDTDHandler(org.xml.sax.DTDHandler)

JADE v6.1

Copyright © 2004 Jean-Marie Dautelle.