com.croftsoft.core.text.sml
Class SmlNodeLoader

java.lang.Object
  extended by com.croftsoft.core.text.sml.SmlNodeLoader
All Implemented Interfaces:
SmlParseHandler

public final class SmlNodeLoader
extends Object
implements SmlParseHandler

Used to parse large SML files one data record at a time.

The input is assumed to be a very large Simplified Markup Language (SML) file consisting of a root node containing zero or more child nodes, each child representing an individual data record. As each direct child of the top-level root element is parsed, it is passed as an SmlNode to a Consumer.

This parser is useful when you have a database dump in SML format and you want to read it back in one data record at a time. Since the data file is large, your Consumer implementation will typically commit each record to secondary storage (disk or database) as it is received. This prevents an out-of-memory condition that might result from loading the entire file into primary storage (memory) as a Document Object Model (DOM), an object graph composed of a root node and multiple child nodes, as it is being parsed.

Example:

 SmlNodeLoader.load ( smlInputStream,
   new Consumer ( )
   {
     public void  consume ( Object  o )
     {
       SmlNode  smlNode = ( SmlNode ) o;

       User  user = User.fromSmlNode ( smlNode );

       userDatabase.add ( user );
     }
   } );
 

It is assumed that an SML node will have never have both character data and SML nodes mixed together as immediate children. Given that assumption, this parser will overwrite a parsed String child with a subsequently parsed SmlNode child. Additionally, character data will not be recorded as a child once an SmlNode child is already in place. This is useful for preventing unnecessary white space between element tags in the SML file from being stored as character data.

Since:
2001-05-10
Version:
2001-05-18
Author:
David W. Croft

Method Summary
 void handleCData(String cData)
           
 void handleElementClose(String elementName)
           
 void handleElementOpen(String elementName)
           
 void handleParseError()
           
static void main(String[] args)
           
static void parse(InputStream inputStream, Consumer smlNodeConsumer)
           
static void parse(String smlDataFilename, Consumer smlNodeConsumer, boolean isZipFile)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

main

public static void main(String[] args)
                 throws Exception
Throws:
Exception

parse

public static void parse(InputStream inputStream,
                         Consumer smlNodeConsumer)
                  throws IOException
Throws:
IOException

parse

public static void parse(String smlDataFilename,
                         Consumer smlNodeConsumer,
                         boolean isZipFile)
                  throws IOException
Throws:
IOException

handleCData

public void handleCData(String cData)
Specified by:
handleCData in interface SmlParseHandler

handleElementOpen

public void handleElementOpen(String elementName)
Specified by:
handleElementOpen in interface SmlParseHandler

handleElementClose

public void handleElementClose(String elementName)
Specified by:
handleElementClose in interface SmlParseHandler

handleParseError

public void handleParseError()
Specified by:
handleParseError in interface SmlParseHandler

CroftSoft Javadoc

CroftSoft Core Javadoc (2008-09-28 20:58:02)