|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.croftsoft.core.text.sml.SmlNodeLoader
public final class SmlNodeLoader
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.
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 |
---|
public static void main(String[] args) throws Exception
Exception
public static void parse(InputStream inputStream, Consumer smlNodeConsumer) throws IOException
IOException
public static void parse(String smlDataFilename, Consumer smlNodeConsumer, boolean isZipFile) throws IOException
IOException
public void handleCData(String cData)
handleCData
in interface SmlParseHandler
public void handleElementOpen(String elementName)
handleElementOpen
in interface SmlParseHandler
public void handleElementClose(String elementName)
handleElementClose
in interface SmlParseHandler
public void handleParseError()
handleParseError
in interface SmlParseHandler
|
CroftSoft Javadoc | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |