Class XMLSaxParser

  • All Implemented Interfaces:
    ParserInterface, VersionInfoInterface

    public class XMLSaxParser
    extends ParserImpl
    A class reading Entries in XML format. XML Sax Parser doesn't support writing. This parser uses a SAX2 parser to read an XML document. For every start-tag read from the input document the parser concatenates this tag name with its parent tag name into a currentTag value. The currentTag value holds the path to the current position in the XML document. When character data is read an attribute is either created or appended to using the currentTag name and the character data as the value. Data collection is only done when a group tag is found (e.g. when any of the group tag values are found). When an end-tag is encountered the parser will first check to see if the currentTag matches the GroupTag configured for the parser, and if it does, the current entry is added to a queue which is read by the readEntry() method. Since SAX2 is event driven, this class creates a thread that performs the XML parsing and notifies the parser class when an entry is ready for consumption. The currentTag is composed of tag names concatenate with the "@" character. The GroupTag specifies which tag-path marks the boundary for an entry. If specified as a string not starting with an asterix, the tag is checked for equality with the currentTag. If the GroupTag starts with "*" then the currentTag is checked for containment of the GroupTag (e.g. "Root@Entry@X" matches "*Root@Entry" but not "Root@Entry"). You can specify multiple group tags by comma-separating the tags (e.g. a,b@x etc) Big Data Blue Data 12 88 Blue Data Using "Root@Entry" as the GroupTag, the above XML document would yield two entries with the following attributes: ENTRY [ "Root@Entry@attribute": [ "Big Data", "Blue Data" ] ] ENTRY [ "Root@Entry@attribute#name": [ "big" "blue" ] "Root@Entry@attribute@size": [ "12" ] "Root@Entry@attribute@age": [ "88" ] "Root@Entry@attribute": [ "Blue Data" ] ] The saxRemovePrefix parameter is a convenience parameter that cause the parser to remove a specific prefix. If the parser was configured with "Root@Entry@" for the saxRemovePrefix the entries would be simpler like "attribute@size" rather than "Root@Entry@attribute@size". The Parser creates Sax Content handler thread. It parses the XML document and in its endElement method puts the Entry object in XMLSaxParser's queue and notifies XMLSaxParser to read the entry. After reading XMLSaxParser deletes the Entry object from queue. Sax Content Handler thread waits in startElement method for Entry to be read. XMLSaxParser, upon request for readEntry, trigger SaxContentHandler thread to go ahead.
    • Constructor Detail

      • XMLSaxParser

        public XMLSaxParser()
        Constructor
    • Method Detail

      • initParser

        public void initParser()
                        throws java.lang.Exception
        Initializes queue object, reads configuration parameters, creates SaxContentHandler thread and starts the thread.
        Specified by:
        initParser in interface ParserInterface
        Overrides:
        initParser in class ParserImpl
        Throws:
        java.lang.Exception - if getInputStream() and getReader() both returns null.
      • closeParser

        public void closeParser()
                         throws java.lang.Exception
        Stops the Sax Content Handler thread.
        Specified by:
        closeParser in interface ParserInterface
        Overrides:
        closeParser in class ParserImpl
        Throws:
        java.lang.Exception
      • readEntry

        public Entry readEntry()
                        throws java.lang.Exception
        readEntry() uses the queue object to check for new entries provided by the xml-parser thread. The object found in the queue governs when an entry is ready, an end-of-file has been reached or if there is an error parsing the document. The method simply checks the class type for the object and decides what to do next.
        Returns:
        The next Entry in the XML document.
        Throws:
        java.lang.Exception - if an error occurs.
      • writeEntry

        public void writeEntry​(Entry entry)
                        throws java.lang.Exception
        Not supported
        Parameters:
        entry -
        Throws:
        java.lang.Exception
      • getVersion

        public java.lang.String getVersion()
        Description copied from interface: VersionInfoInterface
        Version information.
        Returns:
        version information