[Batchserver-cvs] batchserver/src/org/jmonks/batchserver/io package.html, 1.3, 1.4 RecordType.java,
Brought to you by:
suresh_pragada
From: Suresh <sur...@us...> - 2006-06-14 03:46:14
|
Update of /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/io In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv349 Modified Files: package.html RecordType.java Log Message: no message Index: package.html =================================================================== RCS file: /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/io/package.html,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** package.html 13 Jun 2006 22:09:54 -0000 1.3 --- package.html 14 Jun 2006 03:46:10 -0000 1.4 *************** *** 5,17 **** </head> <body> ! Defines API to be used by clients to read records from the files and writer ! records to the file. <p> ! This package provides the API for the clients to work with the files easily irrespective of the file format. This API is based on the analogy that all the ! files have some data in the form of records and each record consists set of ! fields and the structure of these files, records and fields can be defined or ! configured using xml file. API parses or generates the records </p> </body> </html> --- 5,134 ---- </head> <body> ! Defines API for the clients to read records from the file and write records into the file. <p> ! This package provides the API for the client programs to work with the files easily irrespective of the file format. This API is based on the analogy that all the ! files to be read and write have some data in the form of records and each ! record consists of a set of fields. Structure of these files, records and fields ! can be defined or configured using xml format. API allows the client programs ! to reads the records in an iterative manner from the file by specifying the xml file ! defined the file structure (It will be called as file spec here onwards) ! and file to read. API allows the client programs to create the record and ! write that record into the file. </p> + + <p> + <h3>Defining file structure</h3> + API expects the file consists of the data in the form of mulitple records + and each record consists of multiple fields. Structure of the file will be defined + using the root tag <file-spec> accepts the attribute + <code>file-type</code> which signifies the kind of format of the file it is defining. + Implementations may expects other attributes along with the <code>file-type</code> + attribute for better file reading and file writing. + These additional attributes will be mentioned by the FileSpec impelementors. + <pre> + <file-spec> + <!-- Record specs will go on here --> + </file-spec> + </pre> + </p> + + <p> + As every file will have its data in the form of records, each record will be defined + using the tag <record-spec> in the <file-spec> tag. Every <code>record-spec</code> + will have a <code>record-type</code> attribute which signifies the kind of record it is configuring + like header record or detail record or trailer record. This <code>record-type</code> should be unique + across the file spec. Along with the <code>record-type</code> attribute each implementation will require + additional attributes to idnetify the records in the file and to write the records into the file. + These additional attributes will be mentioned by the RecordSpec implementations. + <pre> + <file-spec file-type="file-format"> + <record-spec record-type="detail"> + <!-- Record specs will go on here --> + </record-spec> + </file-spec> + </pre> + </p> + + <p> + As every record spec consists of set of fields, each field is defined using the tag <field-spec> + in <record-spec> tag. Each <code>field-spec</code> should have an attribute </code>field-name</code> + identifies the name of the field, which will be used to populate the field values into the record. + Based on the implementation, additional attributes will be required along with the <code>field-name</code> to identify + the field. Some implementations might not require <code>field-spec</code> elements at all. Whether clients neeeds to + define the <code>field-spec</code> elements or not will be decided by RecordSpec implementations. + <pre> + <file-spec file-type="file-format"> + <record-spec record-type="detail"> + <field-spec field-name="field-name1"/> + </record-spec> + </file-spec> + </pre> + </p> + + <p> + <h3>Reading records from the file</h3> + FileReader class helps us in obtaining the FileReader instance through various factory methods + by accepting the file to be read and file spec in different forms. FileReader reads + data from the file according to the given file spec and when it finds a match to any of the + provided record spec, it reads that record and returns field values as ReaderRecord instance. + ReaderRecord instance has a method to read the field values by passing the field names. + FileReader implementations provides ReaderRecord implementations, which + allow additional methods to read the field values. Look at the FileReader implementation + javadoc for the additional methods. Reader records can be read from FileReader in an + iterative manner. When file reader doesnt have any more records, it returns null indicating + that reader doenst have any more records. At this point client can stop requesting for + further records. Once done reading all the records, client should close the reader. + <br/><br/> + Folloing example indicates how to obtain a file reader instance and how to obtain reader + record and how to read field values from the reader records. + <pre style="color:green"> + <i> + InputStream fileSpecInputStream= // Get the input stream for the XML file contains the file structure. + InputStream fileInputStream= // Get the input stream of the file to be read. + FileReader reader=FileReader.getFileReader(fileInputStream,fileSpecInputStream); + ReaderRecord record=null; + while((record=reader.getNextRecord())!=null) + { + if(record.getRecordType().equals(RecordType.DETAIL)) + { + String fieldValue1=readerRecord.readField("field-name1"); + // Read the rest of the field and does the processing. + } + } + reader.close(); + </i> + </pre> + </p> + + <p> + <h3>Writing records into the file</h3> + FileWriter class helps us in obtaining the FileWriter instance through various factory methods + by accepting the file to be written and file spec in different forms. FileWriter accepts + WriterRecord instances which actually consists of the field values to write the data + into the file. WriterRecord instances can be obtained from FileWriter instances. WriterRecord + instances provides the method to write the field values associated to field name. FileWriter + implementation classes will provide additional methods to write the field values in an + effective way into the writer record. Once all the required field values have been pushed + into the writer record, this record needs to be submitted to the FileWriter instance. This + will writes that record according to the file spec provided while obtaining the file writer instance. + Once done writing all the records, file writer needs to be closed. + <br/><br/> + Folloing example indicates how to obtain a file writer instance and how to obtain writer + record and how to write field values into the writer records and how to submit that record to the file writer. + + <pre style="color:green"> + <i> + InputStream fileSpecInputStream= // Get the input stream for the XML file contains the file structure. + OutputStream fileOutputStream= // Get the output stream of the file to be written/generated. + FileWriter writer=FileWriter.getFileWriter(fileOutputStream,fileSpecInputStream); + WriterRecord record=writer.createWriterRecord(RecordType.DETAIL); + record.writeField("field-name1","field-value1"); + // Write all the other field values into the writer record. + writer.writeRecord(record); + writer.close(); + </i> + </pre> + </p> </body> </html> Index: RecordType.java =================================================================== RCS file: /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/io/RecordType.java,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** RecordType.java 13 Jun 2006 22:09:54 -0000 1.7 --- RecordType.java 14 Jun 2006 03:46:10 -0000 1.8 *************** *** 67,72 **** else if(RecordType.DETAIL.toString().equalsIgnoreCase(recordType)) return RecordType.DETAIL; ! else if(RecordType.TRAILOR.toString().equalsIgnoreCase(recordType)) ! return RecordType.TRAILOR; else if(RecordType.BLOCK_START.toString().equalsIgnoreCase(recordType)) return RecordType.BLOCK_START; --- 67,72 ---- else if(RecordType.DETAIL.toString().equalsIgnoreCase(recordType)) return RecordType.DETAIL; ! else if(RecordType.TRAILER.toString().equalsIgnoreCase(recordType)) ! return RecordType.TRAILER; else if(RecordType.BLOCK_START.toString().equalsIgnoreCase(recordType)) return RecordType.BLOCK_START; *************** *** 113,119 **** /** * Represents the header record and the value to be used in the record ! * spec is "TRAILOR". */ ! public static final RecordType TRAILOR = new RecordType("TRAILOR"); /** * Represents the detailed record and the value to be used in the record --- 113,119 ---- /** * Represents the header record and the value to be used in the record ! * spec is "TRAILER". */ ! public static final RecordType TRAILER = new RecordType("TRAILER"); /** * Represents the detailed record and the value to be used in the record |