org.jmonks.batch.io.xml
Class XMLFileReader

java.lang.Object
  extended byorg.jmonks.batch.io.FileReader
      extended byorg.jmonks.batch.io.xml.XMLFileReader

public class XMLFileReader
extends FileReader

XMLFileReader reads the specified xml file according to the given file spec and returns the recrods on the needed basis. It finds the record location using the xpath given in each xml record spec and loads all the child elements as a fields. Field values should be accessed using the element names. If element is a complex element, returned value will be a reader record and it again follow the same convention. If element is repeated more than once, the value will be loaded as a list. ReaderRecord returned by this reader will have additional methods used to read the data accurately. To find out how to read each record from the file and to read the each field from the record, refer to the package javadoc.

Since:
1.0
Version:
1.0
Author:
Suresh Pragada

Nested Class Summary
 class XMLFileReader.XMLReaderRecord
          XMLReaderRecord implements ReaderRecord by maintaing the field names and values as a map and provides the methods with proper access privileges to read into and write from the record.
 
Field Summary
protected  XMLFileSpec fileSpec
          File spec to read the file.
 
Constructor Summary
XMLFileReader(java.io.InputStream fileInputStream, FileSpec fileSpec)
          Constructs and initializes the XML File reader.
XMLFileReader(java.io.Reader reader, FileSpec fileSpec)
          Constructs and initializes the XML File reader.
 
Method Summary
 void close()
          Closes the reader.
 ReaderRecord getNextRecord()
          Gets the next available record from the file.
 
Methods inherited from class org.jmonks.batch.io.FileReader
getFileReader, getFileReader, getFileReader, getFileReader
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

fileSpec

protected XMLFileSpec fileSpec
File spec to read the file.

Constructor Detail

XMLFileReader

public XMLFileReader(java.io.InputStream fileInputStream,
                     FileSpec fileSpec)
Constructs and initializes the XML File reader.

Parameters:
fileInputStream - Input stream to the file.
fileSpec - File spec to be used to read the file.
Throws:
FileParseException - If root element doesnt match with the element specified in file spec and problems to initializes the reader.

XMLFileReader

public XMLFileReader(java.io.Reader reader,
                     FileSpec fileSpec)
Constructs and initializes the XML File reader.

Parameters:
reader - Reader to the file.
fileSpec - File spec to be used to read the file.
Throws:
FileParseException - If root element doesnt match with the element specified in file spec and problems to initializes the reader.
Method Detail

getNextRecord

public ReaderRecord getNextRecord()
Gets the next available record from the file. If file doesnt have any more records, it returns null.

Specified by:
getNextRecord in class FileReader
Returns:
Returns the next available record.
Throws:
FileParseException - Problems getting the next record.

close

public void close()
Closes the reader.

Specified by:
close in class FileReader