batchserver-cvs Mailing List for Enterprise Batch Server (Page 14)
Brought to you by:
suresh_pragada
You can subscribe to this list here.
2006 |
Jan
|
Feb
(10) |
Mar
(159) |
Apr
(5) |
May
(52) |
Jun
(70) |
Jul
|
Aug
(28) |
Sep
(256) |
Oct
(38) |
Nov
|
Dec
|
---|---|---|---|---|---|---|---|---|---|---|---|---|
2007 |
Jan
|
Feb
|
Mar
|
Apr
|
May
(3) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
From: Suresh <sur...@us...> - 2006-06-23 16:45:56
|
Update of /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/io/flat In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv19759 Modified Files: DelimitedFlatFileReader.java Log Message: no message Index: DelimitedFlatFileReader.java =================================================================== RCS file: /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/io/flat/DelimitedFlatFileReader.java,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** DelimitedFlatFileReader.java 22 Jun 2006 22:52:01 -0000 1.7 --- DelimitedFlatFileReader.java 23 Jun 2006 16:45:50 -0000 1.8 *************** *** 15,18 **** --- 15,19 ---- import java.util.Iterator; import java.util.List; + import java.util.StringTokenizer; import org.apache.log4j.Logger; import org.jmonks.batchserver.io.FileParseException; *************** *** 78,85 **** logger.trace("Entering parseRecord"); FlatFileReaderRecord record=null; ! String[] fieldValuesArray=recordString.split(recordSpec.getDelimiter()); ! if(fieldValuesArray.length!=recordSpec.getFieldCount()) throw new FileParseException("Record " + recordString + " doesnt have " + recordSpec.getFieldCount() + " fields."); ! List fieldSpecList=recordSpec.getFieldSpecs(); record=new FlatFileReaderRecord(recordSpec.getRecordType(),fieldSpecList.size()); --- 79,98 ---- logger.trace("Entering parseRecord"); FlatFileReaderRecord record=null; ! StringTokenizer tokenizer=new StringTokenizer(recordString,recordSpec.getDelimiter()); ! int totalTokensAvailable=tokenizer.countTokens(); ! if(totalTokensAvailable!=recordSpec.getFieldCount()) throw new FileParseException("Record " + recordString + " doesnt have " + recordSpec.getFieldCount() + " fields."); ! /** ! * Populate all the tokens into the array. ! */ ! String[] fieldValuesArray=new String[totalTokensAvailable]; ! int i=0; ! while(tokenizer.hasMoreTokens()) ! { ! fieldValuesArray[i++]=tokenizer.nextToken(); ! } ! /** ! * Go through the each field spec and populate the values in the record. ! */ List fieldSpecList=recordSpec.getFieldSpecs(); record=new FlatFileReaderRecord(recordSpec.getRecordType(),fieldSpecList.size()); *************** *** 95,99 **** } logger.trace("Exiting parseRecord"); ! return record; } } --- 108,112 ---- } logger.trace("Exiting parseRecord"); ! return record; } } |
Update of /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/io In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv7914 Modified Files: FieldSpec.java FileReader.java FileSpec.java FileWriter.java ReaderRecord.java Record.java RecordType.java Log Message: no message Index: RecordType.java =================================================================== RCS file: /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/io/RecordType.java,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** RecordType.java 14 Jun 2006 03:46:10 -0000 1.8 --- RecordType.java 22 Jun 2006 22:52:01 -0000 1.9 *************** *** 16,22 **** * This defines the constants to identify all the records as enums. This record * type information should be provided when defining the record spec in file spec. - * <br> - * TODO ::: Override the java.lang.Object#equals() and java.lang.Object#hashCode() - * to use this record type in maps. * </p> * --- 16,19 ---- Index: Record.java =================================================================== RCS file: /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/io/Record.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** Record.java 8 Jun 2006 03:39:13 -0000 1.4 --- Record.java 22 Jun 2006 22:52:01 -0000 1.5 *************** *** 19,23 **** * <br> * TODO :: Based on the memory statistics on handling huge files introduces a method to ! * remove the data from the records, once they have been done using. * </p> * --- 19,23 ---- * <br> * TODO :: Based on the memory statistics on handling huge files introduces a method to ! * remove the data from the records, once they have been used. * </p> * Index: FileReader.java =================================================================== RCS file: /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/io/FileReader.java,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** FileReader.java 13 Jun 2006 22:09:53 -0000 1.13 --- FileReader.java 22 Jun 2006 22:52:01 -0000 1.14 *************** *** 19,26 **** /** * <p> ! * FileReader reads/parses the specified file based on the given file spec and ! * returns the data in the form of ReaderRecord's to read the interested field values. * This provides the methods to reads the records in an iterative manner. Once finished ! * reading the records file reader should be closed by calling * the appropriate methods. This provides the factory method to create the file reader * based on the file spec. Here is a sample code snippet to use the file reader. --- 19,26 ---- /** * <p> ! * FileReader reads the specified file based on the given file spec and ! * returns the data in the form of ReaderRecord's to read the required values referring the field names. * This provides the methods to reads the records in an iterative manner. Once finished ! * reading all or required records from the file reader, it should be closed by calling * the appropriate methods. This provides the factory method to create the file reader * based on the file spec. Here is a sample code snippet to use the file reader. *************** *** 28,32 **** * <p> * <pre> ! * FileReader fileReader=FileReader.getFileReader("/data/consumer.dat","/config/consumer-file-spec.xml"); * ReaderRecord record=null; * while((record=fileReader.getNextRecord())!=null) --- 28,34 ---- * <p> * <pre> ! * InputStream fileSpecInputStream=...; ! * InputStream fileInputStream=....; ! * FileReader fileReader=FileReader.getFileReader(fileInputStream,fileSpecInputStream); * ReaderRecord record=null; * while((record=fileReader.getNextRecord())!=null) *************** *** 52,56 **** /** * <p> ! * Gets the next record from the file. If file doesnt have any more records * it returns null. * </p> --- 54,58 ---- /** * <p> ! * Gets the next available record from the file. If file doesnt have any more records * it returns null. * </p> *************** *** 102,106 **** * @param fileSpec File spec to create the file reader. * ! * @return Returns the appropriate reader. * * @throws IllegalArgumentException If the given fileInputStream or fileSpec is null. --- 104,108 ---- * @param fileSpec File spec to create the file reader. * ! * @return Returns the appropriate file reader. * * @throws IllegalArgumentException If the given fileInputStream or fileSpec is null. *************** *** 138,142 **** * @return Returns the appropriate reader. * ! * @throws IllegalArgumentException If the given fileInputStream or fileSpecInputStream is null. * @throws org.jmonks.batchserver.io.FileSpecException If the configured file type in file spec doesnt * exist in FileType class. --- 140,144 ---- * @return Returns the appropriate reader. * ! * @throws IllegalArgumentException If the given reader or fileSpecInputStream is null. * @throws org.jmonks.batchserver.io.FileSpecException If the configured file type in file spec doesnt * exist in FileType class. *************** *** 164,168 **** * @return Returns the appropriate reader. * ! * @throws IllegalArgumentException If the given fileInputStream or fileSpec is null. * @throws org.jmonks.batchserver.io.FileSpecException If the configured file type in file spec doesnt * exist in FileType class. --- 166,170 ---- * @return Returns the appropriate reader. * ! * @throws IllegalArgumentException If the given reader or fileSpec is null. * @throws org.jmonks.batchserver.io.FileSpecException If the configured file type in file spec doesnt * exist in FileType class. Index: FileSpec.java =================================================================== RCS file: /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/io/FileSpec.java,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** FileSpec.java 21 Jun 2006 22:02:29 -0000 1.12 --- FileSpec.java 22 Jun 2006 22:52:01 -0000 1.13 *************** *** 35,39 **** * <p> * File spec defines the file type and possible records could exists in the file. ! * Each record will have possible fields. Every file spec will contains one or * more record specs. Element file-spec should contain one attribute file-type * defines the type of the file this spec is going to represent. Based on the file --- 35,39 ---- * <p> * File spec defines the file type and possible records could exists in the file. ! * Every file spec will contains one or * more record specs. Element file-spec should contain one attribute file-type * defines the type of the file this spec is going to represent. Based on the file *************** *** 77,84 **** /** ! * Constructs the FileSpec object by accepting the path of the file contains ! * the file specification and file type. * - * @param fileSpecPath Path of a file contains the spec. * @param fileType Type of the file this spec is representing. */ --- 77,82 ---- /** ! * Constructs the FileSpec object by accepting file type. * * @param fileType Type of the file this spec is representing. */ *************** *** 125,129 **** * </p> * ! * @return Returns record spec's as a list. */ public Collection getRecordSpecs() --- 123,127 ---- * </p> * ! * @return Returns record spec's as a collection. */ public Collection getRecordSpecs() *************** *** 150,153 **** --- 148,158 ---- } + /** + * Tells whether a record spec is exists with the given record type in the file spec. + * + * @param recordType Type of the record to check in the file spec. + * + * @return Return true if there is a record spec with this type, false otherwise. + */ public boolean isValidRecordType(RecordType recordType) { Index: ReaderRecord.java =================================================================== RCS file: /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/io/ReaderRecord.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** ReaderRecord.java 8 Jun 2006 03:39:13 -0000 1.2 --- ReaderRecord.java 22 Jun 2006 22:52:01 -0000 1.3 *************** *** 13,17 **** /** * <p> ! * ReaderRecord provides the methods to read the values of the fields for a record. * This record will be generated from the FileReader's. * </p> --- 13,17 ---- /** * <p> ! * ReaderRecord provides the methods to read the values of the fields from a record. * This record will be generated from the FileReader's. * </p> Index: FieldSpec.java =================================================================== RCS file: /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/io/FieldSpec.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** FieldSpec.java 8 Jun 2006 03:39:13 -0000 1.5 --- FieldSpec.java 22 Jun 2006 22:52:01 -0000 1.6 *************** *** 14,28 **** /** * <p> ! * FieldSpec represents the <field-spec> element in reocrd spec. * Field spec specifies the name of the field and additional attributes to * identifies the field among the record and other properties based on the file type. ! * Every field-spec element contains field-name attribute identifies among the ! * record spec. The field-name values should be unique across one record spec. * </p> * <p> - * Here is a sample record-spec configuration. - * <br> * <pre> ! * <field-spec field-name="consumer-id"> * </pre> * </p> --- 14,26 ---- /** * <p> ! * FieldSpec represents the <field-spec> element in file spec. * Field spec specifies the name of the field and additional attributes to * identifies the field among the record and other properties based on the file type. ! * Every field-spec element contains <code>field-name</code> attribute identifies among the ! * record spec. The <code>field-name</code> values should be unique across one record spec. * </p> * <p> * <pre> ! * <field-spec field-name="consumer-id"/> * </pre> * </p> Index: FileWriter.java =================================================================== RCS file: /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/io/FileWriter.java,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** FileWriter.java 13 Jun 2006 22:09:54 -0000 1.8 --- FileWriter.java 22 Jun 2006 22:52:01 -0000 1.9 *************** *** 20,24 **** /** * <p> ! * FileWriter writes/generates the specified file based on the given file spec with * the data written in the form of WriterRecord's. This provides the methods * to create the required records and write them into the file writer. Once finished --- 20,24 ---- /** * <p> ! * FileWriter writes the specified file based on the given file spec with * the data written in the form of WriterRecord's. This provides the methods * to create the required records and write them into the file writer. Once finished *************** *** 29,33 **** * <p> * <pre> ! * FileWriter fileWriter=FileWriter.getFileWriter("/data/consumer.dat","/config/consumer-file-spec.xml"); * WriterRecord record=fileWriter.createWriterRecord(RecordType.DETAIL); * record.writeField("consumer-id","123456"); --- 29,35 ---- * <p> * <pre> ! * InputStream fileSpecInputStream=...; ! * OutputStream fileOutputStream=...; ! * FileWriter fileWriter=FileWriter.getFileWriter(fileOutputStream,fileSpecInputStream); * WriterRecord record=fileWriter.createWriterRecord(RecordType.DETAIL); * record.writeField("consumer-id","123456"); *************** *** 47,51 **** /** ! * Writes the given record into the file. * * @throws org.jmonks.batchserver.io.FileParseException Problems while writing the record into file. --- 49,56 ---- /** ! * Writes the given record into the file. The record should be obtained ! * from this file writer using the <code>createWriterRecord</code> method. ! * ! * @param record WriterRecord that you want to write into the file. * * @throws org.jmonks.batchserver.io.FileParseException Problems while writing the record into file. *************** *** 81,85 **** * @return Returns the appropriate writer. * ! * @throws IllegalArgumentException If the given file output stream or file spec is null. * @throws org.jmonks.batchserver.io.FileSpecException If the configured file type in file spec doesnt * exist in FileType class. --- 86,90 ---- * @return Returns the appropriate writer. * ! * @throws IllegalArgumentException If the given file output stream or file spec input stream is null. * @throws org.jmonks.batchserver.io.FileSpecException If the configured file type in file spec doesnt * exist in FileType class. *************** *** 142,146 **** * @return Returns the appropriate writer. * ! * @throws IllegalArgumentException If the given file output stream or file spec is null. * @throws org.jmonks.batchserver.io.FileSpecException If the configured file type in file spec doesnt * exist in FileType class. --- 147,151 ---- * @return Returns the appropriate writer. * ! * @throws IllegalArgumentException If the given file output stream or file spec input stream is null. * @throws org.jmonks.batchserver.io.FileSpecException If the configured file type in file spec doesnt * exist in FileType class. |
From: Suresh <sur...@us...> - 2006-06-22 22:52:06
|
Update of /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/io/flat In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv7914/flat Modified Files: DelimitedFlatFileFieldSpec.java DelimitedFlatFileFileSpec.java DelimitedFlatFileReader.java DelimitedFlatFileRecordSpec.java DelimitedFlatFileWriter.java FixedWidthFlatFileFieldSpec.java FixedWidthFlatFileWriter.java Log Message: no message Index: DelimitedFlatFileRecordSpec.java =================================================================== RCS file: /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/io/flat/DelimitedFlatFileRecordSpec.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** DelimitedFlatFileRecordSpec.java 15 Jun 2006 18:57:02 -0000 1.3 --- DelimitedFlatFileRecordSpec.java 22 Jun 2006 22:52:01 -0000 1.4 *************** *** 27,31 **** * Attribute <code>delimiter</code> tells the value that divides or delimits the fields * and attribute <code>field-count</code> tells the number of fields exists in the record. ! * There should be only one record spec is allwed in the file spec. * Here is a sample spec snippet... * </p> --- 27,31 ---- * Attribute <code>delimiter</code> tells the value that divides or delimits the fields * and attribute <code>field-count</code> tells the number of fields exists in the record. ! * There should be only one record spec is allowed in this file spec. * Here is a sample spec snippet... * </p> *************** *** 117,122 **** String delimiter=recordSpecElement.getAttribute(DelimitedFlatFileRecordSpec.DELIMITER_ATTRIB_NAME); logger.debug("record specs delimiter value = " + delimiter); ! if(delimiter!=null && !"".equals(delimiter.trim())) ! recordSpec.delimiter=delimiter.trim(); else throw new FileSpecException("Record Spec in Delimited File Spec should have delimiter attribute."); --- 117,122 ---- String delimiter=recordSpecElement.getAttribute(DelimitedFlatFileRecordSpec.DELIMITER_ATTRIB_NAME); logger.debug("record specs delimiter value = " + delimiter); ! if(delimiter!=null && !"".equals(delimiter)) ! recordSpec.delimiter=delimiter; else throw new FileSpecException("Record Spec in Delimited File Spec should have delimiter attribute."); Index: DelimitedFlatFileWriter.java =================================================================== RCS file: /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/io/flat/DelimitedFlatFileWriter.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** DelimitedFlatFileWriter.java 21 Jun 2006 22:02:29 -0000 1.5 --- DelimitedFlatFileWriter.java 22 Jun 2006 22:52:01 -0000 1.6 *************** *** 21,25 **** /** * <p> ! * DelimitedFlatFileWriter writes/generates the file according to the given file spec * with the data submitted in the form of WriterRecord's. This provides the methods * to create the required writer records and write the writer record into the file writer. --- 21,25 ---- /** * <p> ! * DelimitedFlatFileWriter writes the file according to the given file spec * with the data submitted in the form of WriterRecord's. This provides the methods * to create the required writer records and write the writer record into the file writer. *************** *** 44,48 **** * and file spec. * ! * @param fileOutputStream Output stream representing the file to generate. * @param fileSpec File spec of the delimited flat to be generated. */ --- 44,48 ---- * and file spec. * ! * @param outputStream Output stream representing the file to generate. * @param fileSpec File spec of the delimited flat to be generated. */ Index: DelimitedFlatFileReader.java =================================================================== RCS file: /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/io/flat/DelimitedFlatFileReader.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** DelimitedFlatFileReader.java 21 Jun 2006 22:02:29 -0000 1.6 --- DelimitedFlatFileReader.java 22 Jun 2006 22:52:01 -0000 1.7 *************** *** 25,29 **** * DelimitedFlatFileReader reads the specified delimited flat file according to the given file spec * and returns the recrods on the needed basis. Each field value from the record ! * should be read using readField method by passing the fieldName mentioned in * the file spec. To find out how to read each record from the file and to read * the each field from the record, refer to the FileReader javadoc. --- 25,29 ---- * DelimitedFlatFileReader reads the specified delimited flat file according to the given file spec * and returns the recrods on the needed basis. Each field value from the record ! * should be read using <code>readField</code> method by passing the fieldName mentioned in * the file spec. To find out how to read each record from the file and to read * the each field from the record, refer to the FileReader javadoc. *************** *** 80,84 **** String[] fieldValuesArray=recordString.split(recordSpec.getDelimiter()); if(fieldValuesArray.length!=recordSpec.getFieldCount()) ! throw new FileParseException("Record " + recordString + " doesnt have " + recordSpec.getFieldCount() + " of fields."); List fieldSpecList=recordSpec.getFieldSpecs(); --- 80,84 ---- String[] fieldValuesArray=recordString.split(recordSpec.getDelimiter()); if(fieldValuesArray.length!=recordSpec.getFieldCount()) ! throw new FileParseException("Record " + recordString + " doesnt have " + recordSpec.getFieldCount() + " fields."); List fieldSpecList=recordSpec.getFieldSpecs(); Index: FixedWidthFlatFileFieldSpec.java =================================================================== RCS file: /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/io/flat/FixedWidthFlatFileFieldSpec.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** FixedWidthFlatFileFieldSpec.java 21 Jun 2006 22:02:29 -0000 1.5 --- FixedWidthFlatFileFieldSpec.java 22 Jun 2006 22:52:01 -0000 1.6 *************** *** 17,25 **** /** * <p> ! * FixedWidthFlatFileFieldSpec represents field-spec element in the record spec ! * belongs to the fixed width flat file type. Along with the field-name attribute ! * it looks for the start-pos and end-pos attributes in the field-spec element to retrieve ! * the field from the record. Filed name on field-spec should be unique across the record-spec. ! * Position value starts with "1" and the start-pos and end-pos values are inclusive. * Here is a sample spec snippet... * </p> --- 17,25 ---- /** * <p> ! * FixedWidthFlatFileFieldSpec represents <code>field-spec</code> element in the record spec ! * belongs to the fixed width flat file type. Along with the <code>field-name</code> attribute ! * it looks for the <code>start-pos</code> and <code>end-pos</code> attributes in the field-spec element to retrieve ! * the field from the record. Field name on <code>field-spec</code> should be unique across the record-spec. ! * Position value starts with "1" in the record and the start-pos and end-pos values are inclusive. * Here is a sample spec snippet... * </p> Index: FixedWidthFlatFileWriter.java =================================================================== RCS file: /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/io/flat/FixedWidthFlatFileWriter.java,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** FixedWidthFlatFileWriter.java 21 Jun 2006 22:02:29 -0000 1.10 --- FixedWidthFlatFileWriter.java 22 Jun 2006 22:52:01 -0000 1.11 *************** *** 23,27 **** /** * <p> ! * FixedWidthFlatFileWriter writes/generates the file according to the given file spec * with the data submitted in the form of WriterRecord's. This provides the methods * to create the required writer records and write the writer record into the file writer. --- 23,27 ---- /** * <p> ! * FixedWidthFlatFileWriter writes the file according to the given file spec * with the data submitted in the form of WriterRecord's. This provides the methods * to create the required writer records and write the writer record into the file writer. Index: DelimitedFlatFileFieldSpec.java =================================================================== RCS file: /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/io/flat/DelimitedFlatFileFieldSpec.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** DelimitedFlatFileFieldSpec.java 10 Jun 2006 17:51:37 -0000 1.1 --- DelimitedFlatFileFieldSpec.java 22 Jun 2006 22:52:01 -0000 1.2 *************** *** 18,23 **** /** * <p> ! * DelimitedFlatFileFieldSpec represents field-spec element in the record spec ! * belongs to the delimited flat file type. Along with the field-name attribute * it looks for the <code>index</code> attribute in the field-spec element to retrieve * the field from the record. It specifies the field position in the record. --- 18,23 ---- /** * <p> ! * DelimitedFlatFileFieldSpec represents <code>field-spec</code> element in the <code>record spec</code> ! * element belongs to the delimited flat file type. Along with the <code>field-name</code> attribute * it looks for the <code>index</code> attribute in the field-spec element to retrieve * the field from the record. It specifies the field position in the record. Index: DelimitedFlatFileFileSpec.java =================================================================== RCS file: /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/io/flat/DelimitedFlatFileFileSpec.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** DelimitedFlatFileFileSpec.java 12 Jun 2006 13:15:37 -0000 1.2 --- DelimitedFlatFileFileSpec.java 22 Jun 2006 22:52:01 -0000 1.3 *************** *** 24,28 **** * DelimitedFlatFileFileSpec represents the file spec defines the flat file * where all the fields in the records delimited with a particular character or value. ! * This file-spec doesn't require any special attributes other than file-type, * which should be "delimited-flat". * Here is a sample file spec... --- 24,28 ---- * DelimitedFlatFileFileSpec represents the file spec defines the flat file * where all the fields in the records delimited with a particular character or value. ! * This file spec doesn't require any special attributes other than <code>file-type</code> attribute, * which should be "delimited-flat". * Here is a sample file spec... |
From: Suresh <sur...@us...> - 2006-06-22 22:52:05
|
Update of /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/io/xml In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv7914/xml Modified Files: XMLFileReader.java XMLFileSpec.java XMLFileWriter.java Log Message: no message Index: XMLFileReader.java =================================================================== RCS file: /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/io/xml/XMLFileReader.java,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** XMLFileReader.java 21 Jun 2006 22:02:29 -0000 1.11 --- XMLFileReader.java 22 Jun 2006 22:52:01 -0000 1.12 *************** *** 35,45 **** * 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 ! * of that xpath as a fields. Field values should be accessed using the element names. ! * If element has child elements, that 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 ! * FileReader javadoc. * </p> * --- 35,45 ---- * 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. * </p> * *************** *** 207,211 **** * * @return Returns true if the first start element name matches with configured element name, ! * flase otherwise. */ private boolean validateRootElement() --- 207,211 ---- * * @return Returns true if the first start element name matches with configured element name, ! * false otherwise. */ private boolean validateRootElement() *************** *** 258,263 **** * Loads all the elements available in the stream from now onwards as a fields * into the record until we reach an end element matches the recordElement name. - * - * <i>TODO :: Eliminate Possible limitation :: Two elements with the same name cannot follow. </i> * </p> * --- 258,261 ---- *************** *** 298,305 **** EndElement endElement=(EndElement)reader.nextEvent(); isPreviousElementStart=false; ! if(recordElement.equalsIgnoreCase(endElement.getName().getLocalPart()) && elementStack.capacity()==0) { /** ! * End element name matches the starting element name of this record and no elements in stack. */ break; --- 296,303 ---- EndElement endElement=(EndElement)reader.nextEvent(); isPreviousElementStart=false; ! if(recordElement.equalsIgnoreCase(endElement.getName().getLocalPart()) && elementStack.empty()) { /** ! * End element name matches the starting element name of this record and stack is empty. */ break; Index: XMLFileWriter.java =================================================================== RCS file: /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/io/xml/XMLFileWriter.java,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** XMLFileWriter.java 13 Jun 2006 22:10:19 -0000 1.9 --- XMLFileWriter.java 22 Jun 2006 22:52:01 -0000 1.10 *************** *** 14,19 **** import java.io.Writer; import java.util.ArrayList; - import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; --- 14,19 ---- import java.io.Writer; import java.util.ArrayList; import java.util.Iterator; + import java.util.LinkedHashMap; import java.util.List; import java.util.Map; *************** *** 30,40 **** /** * <p> ! * XMLFileWriter writes/generates the specified xml file according to the given file spec * with the the recrods submitted to write into the file. It generates the root tag * from the attribute given in file-spec. It uses the last part in record xpath to ! * write the record element. If nested element needs to be written, get another ! * record from the writer and writes it to the main record and submit the main ! * record to the writer. If repeated element needs to be written submit the values ! * as a list. * </p> * --- 30,38 ---- /** * <p> ! * XMLFileWriter writes the specified xml file according to the given file spec * with the the recrods submitted to write into the file. It generates the root tag * from the attribute given in file-spec. It uses the last part in record xpath to ! * write the record element. If nested elements or repeated elements needs to be written, ! * writer record provides the methods to write these elements. * </p> * *************** *** 282,286 **** super(recordType); this.isNestedElementRecord=isNestedElementRecord; ! fieldMap=new HashMap(); } --- 280,284 ---- super(recordType); this.isNestedElementRecord=isNestedElementRecord; ! fieldMap=new LinkedHashMap(); } Index: XMLFileSpec.java =================================================================== RCS file: /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/io/xml/XMLFileSpec.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** XMLFileSpec.java 10 Jun 2006 17:51:54 -0000 1.4 --- XMLFileSpec.java 22 Jun 2006 22:52:01 -0000 1.5 *************** *** 21,27 **** * XMLFileSpec represents the file spec defines the xml file * where each different kind of record identified by the xpath. ! * This file-spec requires additional attribute root-element which specified ! * root element of the xml file along with the file-type attribute. ! * Here is a sample file spec... * </p> * <p> --- 21,27 ---- * XMLFileSpec represents the file spec defines the xml file * where each different kind of record identified by the xpath. ! * This file-spec requires additional attribute root-element which specifies ! * root element of the xml file along with the file-type attribute, which is supposed ! * to be "xml". Here is a sample file spec... * </p> * <p> |
From: Suresh <sur...@us...> - 2006-06-21 22:02:32
|
Update of /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/io/flat In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv26950/flat Modified Files: DelimitedFlatFileReader.java DelimitedFlatFileWriter.java FixedWidthFlatFileFieldSpec.java FixedWidthFlatFileReader.java FixedWidthFlatFileWriter.java FlatFileReader.java sample-fixed-width-file-spec.xml Log Message: no message Index: DelimitedFlatFileWriter.java =================================================================== RCS file: /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/io/flat/DelimitedFlatFileWriter.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** DelimitedFlatFileWriter.java 13 Jun 2006 22:10:08 -0000 1.4 --- DelimitedFlatFileWriter.java 21 Jun 2006 22:02:29 -0000 1.5 *************** *** 50,54 **** { super(outputStream,fileSpec); ! recordSpec=(DelimitedFlatFileRecordSpec)fileSpec.getRecordSpecs().get(0); } --- 50,54 ---- { super(outputStream,fileSpec); ! recordSpec=(DelimitedFlatFileRecordSpec)fileSpec.getRecordSpecs().iterator().next(); } *************** *** 63,67 **** { super(writer,fileSpec); ! recordSpec=(DelimitedFlatFileRecordSpec)fileSpec.getRecordSpecs().get(0); } --- 63,67 ---- { super(writer,fileSpec); ! recordSpec=(DelimitedFlatFileRecordSpec)fileSpec.getRecordSpecs().iterator().next(); } Index: FixedWidthFlatFileReader.java =================================================================== RCS file: /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/io/flat/FixedWidthFlatFileReader.java,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** FixedWidthFlatFileReader.java 13 Jun 2006 22:10:08 -0000 1.8 --- FixedWidthFlatFileReader.java 21 Jun 2006 22:02:29 -0000 1.9 *************** *** 12,15 **** --- 12,16 ---- import java.io.InputStream; import java.io.Reader; + import java.util.Collection; import java.util.Iterator; import java.util.List; *************** *** 70,75 **** logger.trace("Entering parseRecord"); FlatFileReaderRecord record=null; ! List recordSpecList=this.fileSpec.getRecordSpecs(); ! for(Iterator recordSpecIterator=recordSpecList.iterator();recordSpecIterator.hasNext();) { FixedWidthFlatFileRecordSpec recordSpec=(FixedWidthFlatFileRecordSpec)recordSpecIterator.next(); --- 71,76 ---- logger.trace("Entering parseRecord"); FlatFileReaderRecord record=null; ! Collection recordSpecCollection=this.fileSpec.getRecordSpecs(); ! for(Iterator recordSpecIterator=recordSpecCollection.iterator();recordSpecIterator.hasNext();) { FixedWidthFlatFileRecordSpec recordSpec=(FixedWidthFlatFileRecordSpec)recordSpecIterator.next(); *************** *** 84,88 **** try { ! fieldValue=recordString.substring(fieldSpec.getStartPosition(),fieldSpec.getEndPosition()); } catch(IndexOutOfBoundsException exception) --- 85,89 ---- try { ! fieldValue=recordString.substring(fieldSpec.getStartPosition()-1,fieldSpec.getEndPosition()); } catch(IndexOutOfBoundsException exception) Index: FixedWidthFlatFileFieldSpec.java =================================================================== RCS file: /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/io/flat/FixedWidthFlatFileFieldSpec.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** FixedWidthFlatFileFieldSpec.java 10 Jun 2006 17:51:37 -0000 1.4 --- FixedWidthFlatFileFieldSpec.java 21 Jun 2006 22:02:29 -0000 1.5 *************** *** 117,121 **** String endPosition=fieldSpecElement.getAttribute(FixedWidthFlatFileFieldSpec.END_POSITION_ATTRIB_NAME); if(endPosition!=null && !"".equals(endPosition.trim())) ! fieldSpec.startPosition=Integer.parseInt(endPosition); else throw new FileSpecException("end-pos attribute is required in fixed width flat file spec element."); --- 117,121 ---- String endPosition=fieldSpecElement.getAttribute(FixedWidthFlatFileFieldSpec.END_POSITION_ATTRIB_NAME); if(endPosition!=null && !"".equals(endPosition.trim())) ! fieldSpec.endPosition=Integer.parseInt(endPosition); else throw new FileSpecException("end-pos attribute is required in fixed width flat file spec element."); Index: sample-fixed-width-file-spec.xml =================================================================== RCS file: /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/io/flat/sample-fixed-width-file-spec.xml,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** sample-fixed-width-file-spec.xml 15 Jun 2006 18:57:02 -0000 1.3 --- sample-fixed-width-file-spec.xml 21 Jun 2006 22:02:29 -0000 1.4 *************** *** 11,15 **** <field-spec field-name="field4" start-pos="32" end-pos="41"/> </record-spec> ! <record-spec record-type="trailor" starts-with="6" record-length="9"> <field-spec field-name="recordCount" start-pos="2" end-pos="9"/> </record-spec> --- 11,15 ---- <field-spec field-name="field4" start-pos="32" end-pos="41"/> </record-spec> ! <record-spec record-type="trailer" starts-with="6" record-length="9"> <field-spec field-name="recordCount" start-pos="2" end-pos="9"/> </record-spec> Index: FixedWidthFlatFileWriter.java =================================================================== RCS file: /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/io/flat/FixedWidthFlatFileWriter.java,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** FixedWidthFlatFileWriter.java 15 Jun 2006 18:57:02 -0000 1.9 --- FixedWidthFlatFileWriter.java 21 Jun 2006 22:02:29 -0000 1.10 *************** *** 81,87 **** { FixedWidthFlatFileFieldSpec fieldSpec=(FixedWidthFlatFileFieldSpec)iterator.next(); ! char[] fieldValue=((String)record.readField(fieldSpec.getFieldName())).toCharArray(); ! System.arraycopy(fieldValue, 0, recordBuffer, fieldSpec.getStartPosition()-1, ! ((fieldValue.length>fieldSpec.getFieldWidth())?fieldSpec.getFieldWidth():fieldValue.length)); } logger.trace("Exiting generateRecord"); --- 81,91 ---- { FixedWidthFlatFileFieldSpec fieldSpec=(FixedWidthFlatFileFieldSpec)iterator.next(); ! String fieldValue=(String)record.readField(fieldSpec.getFieldName()); ! if(fieldValue!=null) ! { ! char[] fieldValueChars=fieldValue.toCharArray(); ! System.arraycopy(fieldValueChars, 0, recordBuffer, fieldSpec.getStartPosition()-1, ! ((fieldValueChars.length>fieldSpec.getFieldWidth())?fieldSpec.getFieldWidth():fieldValueChars.length)); ! } } logger.trace("Exiting generateRecord"); Index: DelimitedFlatFileReader.java =================================================================== RCS file: /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/io/flat/DelimitedFlatFileReader.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** DelimitedFlatFileReader.java 15 Jun 2006 18:57:02 -0000 1.5 --- DelimitedFlatFileReader.java 21 Jun 2006 22:02:29 -0000 1.6 *************** *** 52,56 **** { super(fileInputStream, fileSpec); ! recordSpec=(DelimitedFlatFileRecordSpec)fileSpec.getRecordSpecs().get(0); } --- 52,56 ---- { super(fileInputStream, fileSpec); ! recordSpec=(DelimitedFlatFileRecordSpec)fileSpec.getRecordSpecs().iterator().next(); } *************** *** 65,69 **** { super(reader, fileSpec); ! recordSpec=(DelimitedFlatFileRecordSpec)fileSpec.getRecordSpecs().get(0); } --- 65,69 ---- { super(reader, fileSpec); ! recordSpec=(DelimitedFlatFileRecordSpec)fileSpec.getRecordSpecs().iterator().next(); } Index: FlatFileReader.java =================================================================== RCS file: /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/io/flat/FlatFileReader.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** FlatFileReader.java 13 Jun 2006 22:10:08 -0000 1.3 --- FlatFileReader.java 21 Jun 2006 22:02:29 -0000 1.4 *************** *** 68,72 **** logger.trace("Entering FlatFileReader constructor"); this.fileSpec=fileSpec; ! reader=new BufferedReader(reader); logger.info("Done creating the flat file reader."); } --- 68,72 ---- logger.trace("Entering FlatFileReader constructor"); this.fileSpec=fileSpec; ! this.reader=new BufferedReader(reader); logger.info("Done creating the flat file reader."); } |
From: Suresh <sur...@us...> - 2006-06-21 22:02:32
|
Update of /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/io In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv26950 Modified Files: FileSpec.java Log Message: no message Index: FileSpec.java =================================================================== RCS file: /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/io/FileSpec.java,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** FileSpec.java 13 Jun 2006 22:09:54 -0000 1.11 --- FileSpec.java 21 Jun 2006 22:02:29 -0000 1.12 *************** *** 12,17 **** import java.io.IOException; import java.io.InputStream; import java.util.HashMap; - import java.util.List; import java.util.Map; import javax.xml.parsers.DocumentBuilder; --- 12,17 ---- import java.io.IOException; import java.io.InputStream; + import java.util.Collection; import java.util.HashMap; import java.util.Map; import javax.xml.parsers.DocumentBuilder; *************** *** 127,133 **** * @return Returns record spec's as a list. */ ! public List getRecordSpecs() { ! return (List)this.recordSpecMap.keySet(); } --- 127,133 ---- * @return Returns record spec's as a list. */ ! public Collection getRecordSpecs() { ! return this.recordSpecMap.values(); } |
From: Suresh <sur...@us...> - 2006-06-21 22:02:32
|
Update of /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/io/xml In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv26950/xml Modified Files: XMLFileReader.java Log Message: no message Index: XMLFileReader.java =================================================================== RCS file: /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/io/xml/XMLFileReader.java,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** XMLFileReader.java 13 Jun 2006 22:10:19 -0000 1.10 --- XMLFileReader.java 21 Jun 2006 22:02:29 -0000 1.11 *************** *** 14,17 **** --- 14,18 ---- import java.io.Reader; import java.util.ArrayList; + import java.util.Collection; import java.util.HashMap; import java.util.Iterator; *************** *** 243,247 **** private XMLRecordSpec getRecordSpec() { ! List recordSpecs=this.fileSpec.getRecordSpecs(); for(Iterator iterator=recordSpecs.iterator();iterator.hasNext();) { --- 244,248 ---- private XMLRecordSpec getRecordSpec() { ! Collection recordSpecs=this.fileSpec.getRecordSpecs(); for(Iterator iterator=recordSpecs.iterator();iterator.hasNext();) { |
From: Suresh <sur...@us...> - 2006-06-15 18:57:10
|
Update of /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/io/flat In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv27657 Modified Files: DelimitedFlatFileReader.java DelimitedFlatFileRecordSpec.java FixedWidthFlatFileRecordSpec.java FixedWidthFlatFileWriter.java package.html sample-delimited-file-spec.xml sample-fixed-width-file-spec.xml Log Message: no message Index: DelimitedFlatFileRecordSpec.java =================================================================== RCS file: /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/io/flat/DelimitedFlatFileRecordSpec.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** DelimitedFlatFileRecordSpec.java 12 Jun 2006 20:58:51 -0000 1.2 --- DelimitedFlatFileRecordSpec.java 15 Jun 2006 18:57:02 -0000 1.3 *************** *** 24,34 **** * DelimitedFlatFileRecordSpec represents record-spec element in the file spec * belongs to the delimited flat file type. Along with the <code>record-type</code> attribute ! * it looks for the <code>delimiter</code> attribute in the record-spec element to parse ! * and generate the record. Here is a sample spec snippet... * </p> * <p> * <pre> * <file-spec file-type="delimited-flat"> ! * <record-spec record-type="detail" delimiter="|"> * <!-- field specs will follow here --> * </record-spec> --- 24,37 ---- * DelimitedFlatFileRecordSpec represents record-spec element in the file spec * belongs to the delimited flat file type. Along with the <code>record-type</code> attribute ! * it looks for the two additional attributes <code>delimiter</code> and <code>field-count</code>. ! * Attribute <code>delimiter</code> tells the value that divides or delimits the fields ! * and attribute <code>field-count</code> tells the number of fields exists in the record. ! * There should be only one record spec is allwed in the file spec. ! * Here is a sample spec snippet... * </p> * <p> * <pre> * <file-spec file-type="delimited-flat"> ! * <record-spec record-type="detail" delimiter="|" field-count="4"> * <!-- field specs will follow here --> * </record-spec> *************** *** 55,58 **** --- 58,65 ---- */ public static final String DELIMITER_ATTRIB_NAME = "delimiter"; + /** + * Constant defines the field count attribute name which the value is "field-count" + */ + public static final String FIELD_COUNT_ATTRIB_NAME = "field-count"; private static Logger logger=Logger.getLogger(DelimitedFlatFileRecordSpec.class); *************** *** 115,119 **** throw new FileSpecException("Record Spec in Delimited File Spec should have delimiter attribute."); ! recordSpec.fieldCount=1; NodeList fieldSpecNodeList=recordSpecElement.getElementsByTagName(FieldSpec.FIELD_SPEC_TAG_NAME); for(int i=0;i<fieldSpecNodeList.getLength();i++) --- 122,132 ---- throw new FileSpecException("Record Spec in Delimited File Spec should have delimiter attribute."); ! String fieldCount=recordSpecElement.getAttribute(DelimitedFlatFileRecordSpec.FIELD_COUNT_ATTRIB_NAME); ! logger.debug("record specs field count value = " + delimiter); ! if(fieldCount!=null && !"".equals(fieldCount.trim())) ! recordSpec.fieldCount=Integer.parseInt(fieldCount); ! else ! throw new FileSpecException("Record Spec in Delimited File Spec should have field-count attribute."); ! NodeList fieldSpecNodeList=recordSpecElement.getElementsByTagName(FieldSpec.FIELD_SPEC_TAG_NAME); for(int i=0;i<fieldSpecNodeList.getLength();i++) *************** *** 129,134 **** } recordSpec.addFieldSpec(fieldSpec); - if(fieldSpec.getIndex()>recordSpec.fieldCount) - recordSpec.fieldCount=fieldSpec.getIndex(); } return recordSpec; --- 142,145 ---- *************** *** 143,146 **** --- 154,158 ---- stringValue.append("[recordType = " + super.recordType.toString() + "]"); stringValue.append("[delimiter = " + this.delimiter + "]"); + stringValue.append("[fieldCount = " + this.fieldCount + "]"); stringValue.append("[fieldSpecList = "); for(Iterator iterator=fieldSpecList.iterator();iterator.hasNext();) Index: sample-delimited-file-spec.xml =================================================================== RCS file: /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/io/flat/sample-delimited-file-spec.xml,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** sample-delimited-file-spec.xml 10 Jun 2006 17:51:37 -0000 1.1 --- sample-delimited-file-spec.xml 15 Jun 2006 18:57:02 -0000 1.2 *************** *** 2,6 **** <file-spec file-type="delimited-flat"> ! <record-spec record-type="detail" delimiter="|"> <field-spec field-name="field1" index="1"/> <field-spec field-name="field2" index="2"/> --- 2,6 ---- <file-spec file-type="delimited-flat"> ! <record-spec record-type="detail" delimiter="|" field-count="4"> <field-spec field-name="field1" index="1"/> <field-spec field-name="field2" index="2"/> Index: DelimitedFlatFileReader.java =================================================================== RCS file: /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/io/flat/DelimitedFlatFileReader.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** DelimitedFlatFileReader.java 13 Jun 2006 22:10:08 -0000 1.4 --- DelimitedFlatFileReader.java 15 Jun 2006 18:57:02 -0000 1.5 *************** *** 78,84 **** logger.trace("Entering parseRecord"); FlatFileReaderRecord record=null; List fieldSpecList=recordSpec.getFieldSpecs(); record=new FlatFileReaderRecord(recordSpec.getRecordType(),fieldSpecList.size()); - String[] fieldValuesArray=recordString.split(recordSpec.getDelimiter()); for(Iterator fieldSpecIterator=fieldSpecList.iterator();fieldSpecIterator.hasNext();) { --- 78,87 ---- logger.trace("Entering parseRecord"); FlatFileReaderRecord record=null; + String[] fieldValuesArray=recordString.split(recordSpec.getDelimiter()); + if(fieldValuesArray.length!=recordSpec.getFieldCount()) + throw new FileParseException("Record " + recordString + " doesnt have " + recordSpec.getFieldCount() + " of fields."); + List fieldSpecList=recordSpec.getFieldSpecs(); record=new FlatFileReaderRecord(recordSpec.getRecordType(),fieldSpecList.size()); for(Iterator fieldSpecIterator=fieldSpecList.iterator();fieldSpecIterator.hasNext();) { Index: package.html =================================================================== RCS file: /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/io/flat/package.html,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** package.html 15 Jun 2006 03:35:52 -0000 1.3 --- package.html 15 Jun 2006 18:57:02 -0000 1.4 *************** *** 19,53 **** is starts with some value to identify the record and each record consists of set of of fields where each field starts at one position and ends at one position. ! <h5>Defining the file spec for fixed width flat files</h5> ! File spec which descibes the fixed width flat file expects the <code>file-type</code> ! attribute value should be "fixed-width-flat". It doesnt require any additional ! attributes along with the <code>file-type</code> attribute. ! <pre> ! <file-spec file-type="fixed-width-flat"> ! </file-spec> ! </pre> ! There could be multiple record specs exists in a file spec. Along with the ! record-type attribute, it requires an additional attribute <code>starts-with</code> ! which tells the value that the record starts with. ! <pre> ! <file-spec file-type="fixed-width-flat"> ! <record-spec record-type="DETAIL" starts-with="5"> ! </record-spec> ! </file-spec> ! </pre> There could be multiple field specs exists in a single record spec. Field spec ! requires few additional attributes along with the field-name attribute to identify ! or extract the field from the record. These attributes are <code>start-pos</code> which ! tells the starting position of the field in the record and <code>end-pos</code> which ! tells the ending position of the field in the record. Starting index in a record starts with "1". ! <pre> ! <file-spec file-type="fixed-width-flat"> ! <record-spec record-type="DETAIL" starts-with="5"> ! <field-spec field-name="field-name1" start-pos="12" end-pos="23"/> ! </record-spec> ! </file-spec> ! </pre> ! <h5>Reading the records from fixed width flat files</h5> ! Reading the records from the fixed width flat files is fairly simple. <pre style="color:green"> <i> --- 19,54 ---- is starts with some value to identify the record and each record consists of set of of fields where each field starts at one position and ends at one position. ! <h5>Defining the file spec for fixed width flat files</h5> ! File spec which descibes the fixed width flat file expects the <code>file-type</code> ! attribute value should be "fixed-width-flat". It doesnt require any additional ! attributes along with the <code>file-type</code> attribute. ! <pre> ! <file-spec file-type="fixed-width-flat"> ! </file-spec> ! </pre> ! There could be multiple record specs exists in a file spec. Along with the ! <code>record-type</code> attribute, it requires two additional attributes ! <code>starts-with</code> which tells the value that the record should starts with ! and <code>record-length</code> which tells the lenght of the record. ! <pre> ! <file-spec file-type="fixed-width-flat"> ! <record-spec record-type="DETAIL" starts-with="5" record-length="42"> ! </record-spec> ! </file-spec> ! </pre> There could be multiple field specs exists in a single record spec. Field spec ! requires few additional attributes along with the field-name attribute to identify ! or extract the field from the record. These attributes are <code>start-pos</code> which ! tells the starting position of the field in the record and <code>end-pos</code> which ! tells the ending position of the field in the record. Starting index in a record starts with "1". ! <pre> ! <file-spec file-type="fixed-width-flat"> ! <record-spec record-type="DETAIL" starts-with="5" record-length="42"> ! <field-spec field-name="field-name1" start-pos="12" end-pos="23"/> ! </record-spec> ! </file-spec> ! </pre> ! <h5>Reading the records from fixed width flat files</h5> ! Reading the records from the fixed width flat files is fairly simple. <pre style="color:green"> <i> *************** *** 89,123 **** consists of same number of fields and each field is are delimited by a special value in the record. ! <h5>Defining the file spec for delimited flat files</h5> ! File spec which descibes the delimited flat file expects the <code>file-type</code> ! attribute value should be "delimited-flat". It doesnt require any additional ! attributes along with the <code>file-type</code> attribute. ! <pre> ! <file-spec file-type="delimited-flat"> ! </file-spec> ! </pre> ! Since all the records in delimited flat file of the same type, it allows only ! one record spec should exists in the file spec. Along with the ! record-type attribute, it requires an additional attribute <code>delimiter</code> ! which tells the value that delimits the fields in the record. ! <pre> ! <file-spec file-type="delimited-flat"> ! <record-spec record-type="DETAIL" delimiter="|"> ! </record-spec> ! </file-spec> ! </pre> There could be multiple field specs exists in a record spec. Field spec ! requires one additional attributes along with the field-name attribute to identify ! or extract the field from the record. This attribute is <code>index</code> which ! tells the position of the field in the record. Starting index in a record starts with "1". ! <pre> ! <file-spec file-type="delimited-flat"> ! <record-spec record-type="DETAIL" delimiter="|"> ! <field-spec field-name="field-name1" index="3"/> ! </record-spec> ! </file-spec> ! </pre> ! <h5>Reading the records from delimited flat files</h5> ! Reading the records from the delimited flat files is fairly simple. <pre style="color:green"> <i> --- 90,126 ---- consists of same number of fields and each field is are delimited by a special value in the record. ! <h5>Defining the file spec for delimited flat files</h5> ! File spec which descibes the delimited flat file expects the <code>file-type</code> ! attribute value should be "delimited-flat". It doesnt require any additional ! attributes along with the <code>file-type</code> attribute. ! <pre> ! <file-spec file-type="delimited-flat"> ! </file-spec> ! </pre> ! Since all the records in delimited flat file of the same type, it allows only ! one record spec should exists in the file spec. Along with the ! record-type attribute, it requires two additional attributes <code>delimiter</code> ! and <code>field-count</code>. Attributes <code>delimiter</code> tells the value ! that delimites fields among the record and attribute <code>field-count</code> ! tells the number of fields can exists in the record. ! <pre> ! <file-spec file-type="delimited-flat"> ! <record-spec record-type="DETAIL" delimiter="|" field-count="4"> ! </record-spec> ! </file-spec> ! </pre> There could be multiple field specs exists in a record spec. Field spec ! requires one additional attributes along with the field-name attribute to identify ! or extract the field from the record. This attribute is <code>index</code> which ! tells the position of the field in the record. Starting index in a record starts with "1". ! <pre> ! <file-spec file-type="delimited-flat"> ! <record-spec record-type="DETAIL" delimiter="|" field-count="4"> ! <field-spec field-name="field-name1" index="3"/> ! </record-spec> ! </file-spec> ! </pre> ! <h5>Reading the records from delimited flat files</h5> ! Reading the records from the delimited flat files is fairly simple. <pre style="color:green"> <i> Index: FixedWidthFlatFileRecordSpec.java =================================================================== RCS file: /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/io/flat/FixedWidthFlatFileRecordSpec.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** FixedWidthFlatFileRecordSpec.java 12 Jun 2006 13:15:37 -0000 1.5 --- FixedWidthFlatFileRecordSpec.java 15 Jun 2006 18:57:02 -0000 1.6 *************** *** 21,32 **** * FixedWidthFlatFileRecordSpec represents record-spec element in the file spec * belongs to the fixed width flat file type. Along with the <code>record-type</code> attribute ! * it looks for the <code>starts-with</code> attribute in the record-spec element to identify ! * the record. Record type and starts-with attribute values should be uniquej across ! * the file-spec. Here is a sample spec snippet... * </p> * <p> * <pre> * <file-spec file-type="fixed-width-flat"> ! * <record-spec record-type="detail" starts-with="5"> * <!-- field specs will follow here --> * </record-spec> --- 21,34 ---- * FixedWidthFlatFileRecordSpec represents record-spec element in the file spec * belongs to the fixed width flat file type. Along with the <code>record-type</code> attribute ! * it looks for the <code>starts-with</code> and <code>record-length</code> attributes ! * in the record-spec element to identify the record. <code>starts-with</code> tells ! * the value that the record starts with and <code>record-length</code> tells the ! * length of the record. Record type and starts-with attribute values ! * should be unique across the file-spec. Here is a sample spec snippet... * </p> * <p> * <pre> * <file-spec file-type="fixed-width-flat"> ! * <record-spec record-type="detail" starts-with="5" record-length="42"> * <!-- field specs will follow here --> * </record-spec> *************** *** 48,56 **** * Holds the length of the record. */ ! protected int recordSize=0; /** * Constant defines the starts with attribute name. */ public static final String STARTS_WITH_ATTRIB_NAME = "starts-with"; private static Logger logger=Logger.getLogger(FixedWidthFlatFileRecordSpec.class); --- 50,62 ---- * Holds the length of the record. */ ! protected int recordLength=0; /** * Constant defines the starts with attribute name. */ public static final String STARTS_WITH_ATTRIB_NAME = "starts-with"; + /** + * Constant defines the record length attribute name. + */ + public static final String RECORD_LENGTH_ATTRIB_NAME = "record-length"; private static Logger logger=Logger.getLogger(FixedWidthFlatFileRecordSpec.class); *************** *** 73,89 **** /** ! * Gets the length of the record. This will be calculated by adding the maximum ! * end position of field specs available in the record spec and the lenght of ! * starts-with value. This will be used while writing/generating the record using ! * file wrier. */ ! public int getRecordSize() { ! return recordSize; } /** * Tells whether the given record matches with the record spec. It checks whether ! * this string starts with the starts-with value. * * @param recordString Record read from the file. --- 79,95 ---- /** ! * Gets the length of the record. This will be obtained from the record-legnth ! * attribute in the record-spec. This will be used while writing/generating the record using ! * file writer and while reading the record to identify the record type. */ ! public int getRecordLength() { ! return recordLength; } /** * Tells whether the given record matches with the record spec. It checks whether ! * this record string starts with the starts-with value and the length is equals ! * to the record length. * * @param recordString Record read from the file. *************** *** 95,99 **** if(recordString==null) throw new IllegalArgumentException("Record string cannot be null to match record spec."); ! return recordString.startsWith(this.startsWith); } --- 101,105 ---- if(recordString==null) throw new IllegalArgumentException("Record string cannot be null to match record spec."); ! return recordString.startsWith(this.startsWith) && recordString.length()==recordLength; } *************** *** 131,135 **** throw new FileSpecException("Record Spec in Fixed Width File Spec should have starts-with attribute."); ! int recordSize=startsWith.length(); NodeList fieldSpecNodeList=recordSpecElement.getElementsByTagName(FieldSpec.FIELD_SPEC_TAG_NAME); for(int i=0;i<fieldSpecNodeList.getLength();i++) --- 137,147 ---- throw new FileSpecException("Record Spec in Fixed Width File Spec should have starts-with attribute."); ! String recordLength=recordSpecElement.getAttribute(FixedWidthFlatFileRecordSpec.RECORD_LENGTH_ATTRIB_NAME); ! logger.debug("record specs length value = " + startsWith); ! if(recordLength!=null && !"".equals(startsWith.trim())) ! recordSpec.recordLength=Integer.parseInt(recordLength); ! else ! throw new FileSpecException("Record Spec in Fixed Width File Spec should have record-length attribute."); ! NodeList fieldSpecNodeList=recordSpecElement.getElementsByTagName(FieldSpec.FIELD_SPEC_TAG_NAME); for(int i=0;i<fieldSpecNodeList.getLength();i++) *************** *** 137,144 **** FixedWidthFlatFileFieldSpec fieldSpec=FixedWidthFlatFileFieldSpec.createFixedWidthFlatFileFieldSpec((Element)fieldSpecNodeList.item(i)); recordSpec.addFieldSpec(fieldSpec); - if(fieldSpec.getEndPosition()>recordSize) - recordSize=fieldSpec.getEndPosition(); } - recordSpec.recordSize=recordSize; return recordSpec; } --- 149,153 ---- *************** *** 152,155 **** --- 161,165 ---- stringValue.append("[recordType = " + super.recordType.toString() + "]"); stringValue.append("[startsWith = " + this.startsWith + "]"); + stringValue.append("[recordLength = " + this.recordLength + "]"); stringValue.append("[fieldSpecList = "); for(Iterator iterator=fieldSpecList.iterator();iterator.hasNext();) Index: sample-fixed-width-file-spec.xml =================================================================== RCS file: /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/io/flat/sample-fixed-width-file-spec.xml,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** sample-fixed-width-file-spec.xml 10 Jun 2006 17:51:37 -0000 1.2 --- sample-fixed-width-file-spec.xml 15 Jun 2006 18:57:02 -0000 1.3 *************** *** 2,9 **** <file-spec file-type="fixed-width-flat"> ! <record-spec record-type="header" starts-with="1"> <field-spec field-name="timestamp" start-pos="2" end-pos="9"/> </record-spec> ! <record-spec record-type="detail" starts-with="5"> <field-spec field-name="field1" start-pos="2" end-pos="11"/> <field-spec field-name="field2" start-pos="12" end-pos="21"/> --- 2,9 ---- <file-spec file-type="fixed-width-flat"> ! <record-spec record-type="header" starts-with="1" record-length="9"> <field-spec field-name="timestamp" start-pos="2" end-pos="9"/> </record-spec> ! <record-spec record-type="detail" starts-with="5" record-length="41"> <field-spec field-name="field1" start-pos="2" end-pos="11"/> <field-spec field-name="field2" start-pos="12" end-pos="21"/> *************** *** 11,15 **** <field-spec field-name="field4" start-pos="32" end-pos="41"/> </record-spec> ! <record-spec record-type="trailor" starts-with="6"> <field-spec field-name="recordCount" start-pos="2" end-pos="9"/> </record-spec> --- 11,15 ---- <field-spec field-name="field4" start-pos="32" end-pos="41"/> </record-spec> ! <record-spec record-type="trailor" starts-with="6" record-length="9"> <field-spec field-name="recordCount" start-pos="2" end-pos="9"/> </record-spec> Index: FixedWidthFlatFileWriter.java =================================================================== RCS file: /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/io/flat/FixedWidthFlatFileWriter.java,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** FixedWidthFlatFileWriter.java 13 Jun 2006 22:10:08 -0000 1.8 --- FixedWidthFlatFileWriter.java 15 Jun 2006 18:57:02 -0000 1.9 *************** *** 74,78 **** FlatFileWriterRecord record=(FlatFileWriterRecord)writerRecord; FixedWidthFlatFileRecordSpec recordSpec=(FixedWidthFlatFileRecordSpec)this.fileSpec.getRecordSpec(record.getRecordType()); ! char[] recordBuffer=new char[recordSpec.getRecordSize()]; Arrays.fill(recordBuffer,' '); System.arraycopy(recordSpec.startsWith.toCharArray(), 0, recordBuffer, 0, recordSpec.startsWith.length()); --- 74,78 ---- FlatFileWriterRecord record=(FlatFileWriterRecord)writerRecord; FixedWidthFlatFileRecordSpec recordSpec=(FixedWidthFlatFileRecordSpec)this.fileSpec.getRecordSpec(record.getRecordType()); ! char[] recordBuffer=new char[recordSpec.getRecordLength()]; Arrays.fill(recordBuffer,' '); System.arraycopy(recordSpec.startsWith.toCharArray(), 0, recordBuffer, 0, recordSpec.startsWith.length()); |
From: Suresh <sur...@us...> - 2006-06-15 03:35:55
|
Update of /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/io In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv715 Modified Files: package.html Log Message: no message Index: package.html =================================================================== RCS file: /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/io/package.html,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** package.html 14 Jun 2006 21:01:38 -0000 1.5 --- package.html 15 Jun 2006 03:35:52 -0000 1.6 *************** *** 9,21 **** 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> --- 9,21 ---- 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> *************** *** 23,31 **** 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. Allowed values for the <code>file-type</code> attribute should be from FileType ! class. This class defines all the available file types can be used. Using the value doesnt exist in the FileType class results FileSpecException being thrown. ! 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. --- 23,31 ---- 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. Allowed values for the <code>file-type</code> attribute should be from FileType ! class. This class defines all the available file types can be used. Using the value doesnt exist in the FileType class results FileSpecException being thrown. ! 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. *************** *** 36,49 **** </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 and the value can be taken from RecordType class. Allowed to use other record types not defined in the RecordType class. ! 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> --- 36,49 ---- </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 and the value can be taken from RecordType class. Allowed to use other record types not defined in the RecordType class. ! 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> *************** *** 53,62 **** </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 --- 53,62 ---- </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 *************** *** 69,80 **** </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. --- 69,80 ---- </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. *************** *** 98,102 **** if(record.getRecordType().equals(RecordType.DETAIL)) { ! String fieldValue1=readerRecord.readField("field-name1"); // Read the rest of the field and does the processing. } --- 98,102 ---- if(record.getRecordType().equals(RecordType.DETAIL)) { ! String fieldValue1=record.readField("field-name1"); // Read the rest of the field and does the processing. } *************** *** 106,113 **** </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 --- 106,113 ---- </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 *************** *** 135,139 **** </i> </pre> ! </p> </body> </html> --- 135,139 ---- </i> </pre> ! </p> </body> </html> |
From: Suresh <sur...@us...> - 2006-06-15 03:35:55
|
Update of /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/io/xml In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv715/xml Modified Files: package.html Log Message: no message Index: package.html =================================================================== RCS file: /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/io/xml/package.html,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** package.html 13 Jun 2006 04:02:33 -0000 1.1 --- package.html 15 Jun 2006 03:35:52 -0000 1.2 *************** *** 5,9 **** </head> <body> ! Explain the usage of XML File IO API. </body> </html> --- 5,101 ---- </head> <body> ! Describes the xml file implementation and its usage. ! <p> ! XML files are becoming popular choice by the enterprises ! to exchange the data. This package provides the implementation to work with ! the XML files. Implementation ! assumes that file consists of set of records and each can be identified using ! the xpath. ! </p> ! ! <p> ! <h3>XML File Implementation</h3> ! XML files consists of set of different records where each record ! can be identified by using xpath expression and all the elements ! beneath the element identified by xpath are treated as fields of that record. ! <h5>Defining the file spec for xml files</h5> ! File spec which descibes the xml file expects the <code>file-type</code> ! attribute value should be "xml". It requires one additional ! attribute along with the <code>file-type</code> attribute, which is ! <code>root-element</code> which will be used highly while generating the ! xml file from the set of records. The value in the attribute specifies the ! root element of the xml document. ! <pre> ! <file-spec file-type="xml" root-element="sample-root> ! </file-spec> ! </pre> ! There could be multiple record specs exists in a file spec. Along with the ! record-type attribute, it requires an additional attribute <code>record-xpath</code> ! which tells the xpath in the document to identify the record. ! <pre> ! <file-spec file-type="xml" root-element="sample-root> ! <record-spec record-type="DETAIL" record-xpath="/sample-root/detail-record"/> ! </file-spec> ! </pre> ! Since all the elements beneath the element represented by record spec will be ! exposed as a field values, record spec doesnt require any field specs. All the ! simple elements in the record element will be exposed as field name and values ! where element name represents the field name and element value represents the field ! value. All the complex elements(nested elements or elements contains child elements) ! will be exposed as a records again. All the repeat elements(elements which can ! repeat more than once) values will be exposed as list. ! ! <h5>Reading the records from xml files</h5> ! Reading the records from the xml files is fairly simple. ! <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)) ! { ! XMLFileReader.XMLReaderRecord xmlRecord=(XMLFileReader.XMLReaderRecord)record; ! String fieldValue1=xmlRecord.readSimpleElement("field-name1"); ! ! List repeatElement=xmlRecord.readRepeatElement("field-name2"); ! //Read the repeated values from the list. ! ! XMLFileReader.XMLReaderRecord complexRecord=(XMLFileReader.XMLReaderRecord)xmlRecord.readComplexElement("field-name3"); ! String fieldValue4=complexRecord.readSimpleElement("field-name4"); ! // Read the rest of the field and does the processing. ! } ! } ! reader.close(); ! </i> ! </pre> ! <h5>Writing the records into xml files</h5> ! Writing the records into xml files is fairly simple. ! <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); ! ! XMLFileWriter.XMLWriterRecord record=(XMLFileWriter.XMLWriterRecord)writer.createWriterRecord(RecordType.DETAIL); ! record.writeSimpleElement("field-name1","field-value1"); ! ! List repeateElement=writer.createRepeateElement("field-name2"); ! repeateElement.add("field-value21"); ! repeateElement.add("field-value22"); ! ! XMLFileWriter.XMLWriterRecord complexRecord=(XMLFileWriter.XMLWriterRecord)writer.createComplexElement("field-name3"); ! complexRecord.writeSimpleElement("field-name4","field-value4"); ! // Write all the other field values into the writer record. ! ! writer.writeRecord(record); ! writer.close(); ! </i> ! </pre> ! </p> ! ! </body> </html> |
From: Suresh <sur...@us...> - 2006-06-15 03:35:55
|
Update of /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/io/flat In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv715/flat Modified Files: package.html Log Message: no message Index: package.html =================================================================== RCS file: /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/io/flat/package.html,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** package.html 14 Jun 2006 21:01:51 -0000 1.2 --- package.html 15 Jun 2006 03:35:52 -0000 1.3 *************** *** 10,14 **** to exchange the data. This package provides the implementation to read and write two flat file formats fixed width and delimited flat files. Implementation ! assumes that each line in a flat file corresponds to a record. </p> --- 10,15 ---- to exchange the data. This package provides the implementation to read and write two flat file formats fixed width and delimited flat files. Implementation ! assumes that each line in a flat file corresponds to a record and there is a way ! to identify each record and each field in that record. </p> *************** *** 18,29 **** is starts with some value to identify the record and each record consists of set of of fields where each field starts at one position and ends at one position. ! </p> <p> <h3>Delimited Flat File Implementation</h3> Delimited flat files consists of set of records of same type where all the records consists of same number of fields and each field is are delimited by a special value ! in the record. </p> --- 19,154 ---- is starts with some value to identify the record and each record consists of set of of fields where each field starts at one position and ends at one position. ! <h5>Defining the file spec for fixed width flat files</h5> ! File spec which descibes the fixed width flat file expects the <code>file-type</code> ! attribute value should be "fixed-width-flat". It doesnt require any additional ! attributes along with the <code>file-type</code> attribute. ! <pre> ! <file-spec file-type="fixed-width-flat"> ! </file-spec> ! </pre> ! There could be multiple record specs exists in a file spec. Along with the ! record-type attribute, it requires an additional attribute <code>starts-with</code> ! which tells the value that the record starts with. ! <pre> ! <file-spec file-type="fixed-width-flat"> ! <record-spec record-type="DETAIL" starts-with="5"> ! </record-spec> ! </file-spec> ! </pre> ! There could be multiple field specs exists in a single record spec. Field spec ! requires few additional attributes along with the field-name attribute to identify ! or extract the field from the record. These attributes are <code>start-pos</code> which ! tells the starting position of the field in the record and <code>end-pos</code> which ! tells the ending position of the field in the record. Starting index in a record starts with "1". ! <pre> ! <file-spec file-type="fixed-width-flat"> ! <record-spec record-type="DETAIL" starts-with="5"> ! <field-spec field-name="field-name1" start-pos="12" end-pos="23"/> ! </record-spec> ! </file-spec> ! </pre> ! <h5>Reading the records from fixed width flat files</h5> ! Reading the records from the fixed width flat files is fairly simple. ! <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=record.readField("field-name1"); ! // Read the rest of the field and does the processing. ! } ! } ! reader.close(); ! </i> ! </pre> ! <h5>Writing the records into fixed width flat files</h5> ! Writing the records into fixed width flat files is fairly simple. ! <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> + <p> <h3>Delimited Flat File Implementation</h3> Delimited flat files consists of set of records of same type where all the records consists of same number of fields and each field is are delimited by a special value ! in the record. ! <h5>Defining the file spec for delimited flat files</h5> ! File spec which descibes the delimited flat file expects the <code>file-type</code> ! attribute value should be "delimited-flat". It doesnt require any additional ! attributes along with the <code>file-type</code> attribute. ! <pre> ! <file-spec file-type="delimited-flat"> ! </file-spec> ! </pre> ! Since all the records in delimited flat file of the same type, it allows only ! one record spec should exists in the file spec. Along with the ! record-type attribute, it requires an additional attribute <code>delimiter</code> ! which tells the value that delimits the fields in the record. ! <pre> ! <file-spec file-type="delimited-flat"> ! <record-spec record-type="DETAIL" delimiter="|"> ! </record-spec> ! </file-spec> ! </pre> ! There could be multiple field specs exists in a record spec. Field spec ! requires one additional attributes along with the field-name attribute to identify ! or extract the field from the record. This attribute is <code>index</code> which ! tells the position of the field in the record. Starting index in a record starts with "1". ! <pre> ! <file-spec file-type="delimited-flat"> ! <record-spec record-type="DETAIL" delimiter="|"> ! <field-spec field-name="field-name1" index="3"/> ! </record-spec> ! </file-spec> ! </pre> ! <h5>Reading the records from delimited flat files</h5> ! Reading the records from the delimited flat files is fairly simple. ! <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=record.readField("field-name1"); ! // Read the rest of the field and does the processing. ! } ! } ! reader.close(); ! </i> ! </pre> ! <h5>Writing the records into delimited flat files</h5> ! Writing the records into delimited flat files is fairly simple. ! <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> |
From: Suresh <sur...@us...> - 2006-06-14 21:01:58
|
Update of /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/io/flat In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv26240 Modified Files: package.html Log Message: no message Index: package.html =================================================================== RCS file: /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/io/flat/package.html,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** package.html 13 Jun 2006 04:02:02 -0000 1.1 --- package.html 14 Jun 2006 21:01:51 -0000 1.2 *************** *** 5,9 **** </head> <body> ! Explain the usage of Flat File IO API. </body> </html> --- 5,31 ---- </head> <body> ! Describes the flat file implementation and its usage. ! <p> ! Flat files are the common type of files being used by the enterprises ! to exchange the data. This package provides the implementation to read and ! write two flat file formats fixed width and delimited flat files. Implementation ! assumes that each line in a flat file corresponds to a record. ! </p> ! ! <p> ! <h3>Fixed Width Flat File Implementation</h3> ! Fixed Width flat files consists of set of different records where each record ! is starts with some value to identify the record and each record consists of ! set of of fields where each field starts at one position and ends at one position. ! ! </p> ! ! <p> ! <h3>Delimited Flat File Implementation</h3> ! Delimited flat files consists of set of records of same type where all the records ! consists of same number of fields and each field is are delimited by a special value ! in the record. ! </p> ! </body> </html> |
From: Suresh <sur...@us...> - 2006-06-14 21:01:47
|
Update of /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/io In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv26216 Modified Files: package.html Log Message: no message Index: package.html =================================================================== RCS file: /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/io/package.html,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** package.html 14 Jun 2006 03:46:10 -0000 1.4 --- package.html 14 Jun 2006 21:01:38 -0000 1.5 *************** *** 24,32 **** 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> --- 24,35 ---- 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. + Allowed values for the <code>file-type</code> attribute should be from FileType + class. This class defines all the available file types can be used. Using the + value doesnt exist in the FileType class results FileSpecException being thrown. 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 file-type="file-format"> <!-- Record specs will go on here --> </file-spec> *************** *** 39,43 **** 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. --- 42,48 ---- 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 and the value can be taken from RecordType class. Allowed to use other record types ! not defined in the RecordType class. ! 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. |
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 |
From: Suresh <sur...@us...> - 2006-06-13 22:10:26
|
Update of /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/io/xml In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv28614 Modified Files: XMLFileReader.java XMLFileWriter.java Log Message: no message Index: XMLFileReader.java =================================================================== RCS file: /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/io/xml/XMLFileReader.java,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** XMLFileReader.java 12 Jun 2006 20:59:02 -0000 1.9 --- XMLFileReader.java 13 Jun 2006 22:10:19 -0000 1.10 *************** *** 10,17 **** package org.jmonks.batchserver.io.xml; - - import java.io.FileNotFoundException; import java.io.InputStream; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.HashMap; --- 10,16 ---- package org.jmonks.batchserver.io.xml; import java.io.InputStream; import java.io.InputStreamReader; + import java.io.Reader; import java.util.ArrayList; import java.util.HashMap; *************** *** 74,78 **** * with the element specified in file spec and problems to initializes the reader. */ ! public XMLFileReader(InputStream filInputStream,FileSpec fileSpec) { logger.trace("Entering XMLFileReader constructor"); --- 73,91 ---- * with the element specified in file spec and problems to initializes the reader. */ ! public XMLFileReader(InputStream fileInputStream,FileSpec fileSpec) ! { ! this(new InputStreamReader(fileInputStream),fileSpec); ! } ! ! /** ! * Constructs and initializes the XML File reader. ! * ! * @param reader Reader to the file. ! * @param fileSpec File spec to be used to read the file. ! * ! * @throws org.jmonks.batchserver.io.FileParseException If root element doesnt match ! * with the element specified in file spec and problems to initializes the reader. ! */ ! public XMLFileReader(Reader reader,FileSpec fileSpec) { logger.trace("Entering XMLFileReader constructor"); *************** *** 81,85 **** { XMLInputFactory inputFactory=XMLInputFactory.newInstance(); ! reader=inputFactory.createXMLEventReader(new InputStreamReader(filInputStream)); logger.debug("Created the XML Event reader"); if(this.validateRootElement()) --- 94,98 ---- { XMLInputFactory inputFactory=XMLInputFactory.newInstance(); ! this.reader=inputFactory.createXMLEventReader(reader); logger.debug("Created the XML Event reader"); if(this.validateRootElement()) *************** *** 87,91 **** else { ! reader.close(); throw new FileParseException("Unexpected root element found. Expecting the root element " + this.fileSpec.getRootElement()); } --- 100,104 ---- else { ! this.reader.close(); throw new FileParseException("Unexpected root element found. Expecting the root element " + this.fileSpec.getRootElement()); } *************** *** 101,105 **** logger.trace("Exiting XMLFileReader constructor"); } ! /** * Gets the next available record from the file. If file doesnt have any more --- 114,118 ---- logger.trace("Exiting XMLFileReader constructor"); } ! /** * Gets the next available record from the file. If file doesnt have any more Index: XMLFileWriter.java =================================================================== RCS file: /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/io/xml/XMLFileWriter.java,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** XMLFileWriter.java 13 Jun 2006 04:02:33 -0000 1.8 --- XMLFileWriter.java 13 Jun 2006 22:10:19 -0000 1.9 *************** *** 11,14 **** --- 11,16 ---- package org.jmonks.batchserver.io.xml; import java.io.OutputStream; + import java.io.OutputStreamWriter; + import java.io.Writer; import java.util.ArrayList; import java.util.HashMap; *************** *** 64,67 **** --- 66,80 ---- public XMLFileWriter(OutputStream outputStream,FileSpec fileSpec) { + this(new OutputStreamWriter(outputStream), fileSpec); + } + + /** + * Constructs and initializes the writer with the given values. + * + * @param writer Writer to write the records. + * @param fileSpec File spec to be used to generate the file. + */ + public XMLFileWriter(Writer writer,FileSpec fileSpec) + { logger.trace("Entering XMLFileWriter constructor"); try *************** *** 69,77 **** this.fileSpec=(XMLFileSpec)fileSpec; XMLOutputFactory outputFactory=XMLOutputFactory.newInstance(); ! writer=outputFactory.createXMLStreamWriter(outputStream); logger.debug("Writer has been created."); ! writer.writeStartDocument("ISO-8859-1", "1.0"); ! writer.writeCharacters(indentationEngine.startElement()); ! writer.writeStartElement(this.fileSpec.rootElement); } catch(XMLStreamException exception) --- 82,90 ---- this.fileSpec=(XMLFileSpec)fileSpec; XMLOutputFactory outputFactory=XMLOutputFactory.newInstance(); ! this.writer=outputFactory.createXMLStreamWriter(writer); logger.debug("Writer has been created."); ! this.writer.writeStartDocument("ISO-8859-1", "1.0"); ! this.writer.writeCharacters(indentationEngine.startElement()); ! this.writer.writeStartElement(this.fileSpec.rootElement); } catch(XMLStreamException exception) *************** *** 83,87 **** logger.trace("Exiting XMLFileWriter constructor"); } ! /** * Writes the record into the file. This record should be obtained from --- 96,100 ---- logger.trace("Exiting XMLFileWriter constructor"); } ! /** * Writes the record into the file. This record should be obtained from *************** *** 326,330 **** * @return Returns the list. */ ! public List writeRepeatElement(String fieldName) { if(fieldName==null) --- 339,343 ---- * @return Returns the list. */ ! public List createRepeatElement(String fieldName) { if(fieldName==null) |
From: Suresh <sur...@us...> - 2006-06-13 22:10:16
|
Update of /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/io/flat In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv28578 Modified Files: DelimitedFlatFileReader.java DelimitedFlatFileWriter.java FixedWidthFlatFileReader.java FixedWidthFlatFileWriter.java FlatFileReader.java FlatFileWriter.java Log Message: no message Index: FixedWidthFlatFileReader.java =================================================================== RCS file: /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/io/flat/FixedWidthFlatFileReader.java,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** FixedWidthFlatFileReader.java 12 Jun 2006 13:15:37 -0000 1.7 --- FixedWidthFlatFileReader.java 13 Jun 2006 22:10:08 -0000 1.8 *************** *** 11,14 **** --- 11,15 ---- package org.jmonks.batchserver.io.flat; import java.io.InputStream; + import java.io.Reader; import java.util.Iterator; import java.util.List; *************** *** 44,48 **** super(fileInputStream,fileSpec); } ! /** * Parses the given record string, translates it into the proper ReaderRecord --- 45,60 ---- super(fileInputStream,fileSpec); } ! ! /** ! * Constructs and initializes the reader with the given file path and file spec. ! * ! * @param reader Reader to the file. ! * @param fileSpec File spec to be used to read the file. ! */ ! public FixedWidthFlatFileReader(Reader reader,FileSpec fileSpec) ! { ! super(reader,fileSpec); ! } ! /** * Parses the given record string, translates it into the proper ReaderRecord Index: DelimitedFlatFileReader.java =================================================================== RCS file: /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/io/flat/DelimitedFlatFileReader.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** DelimitedFlatFileReader.java 12 Jun 2006 20:58:51 -0000 1.3 --- DelimitedFlatFileReader.java 13 Jun 2006 22:10:08 -0000 1.4 *************** *** 12,15 **** --- 12,16 ---- import java.io.InputStream; + import java.io.Reader; import java.util.Iterator; import java.util.List; *************** *** 55,58 **** --- 56,72 ---- /** + * Constructs the Delimited flat file reader from the given input stream + * and file spec. + * + * @param reader Reader representing the file to parse. + * @param fileSpec File spec of the delimited flat to be read. + */ + public DelimitedFlatFileReader(Reader reader,FileSpec fileSpec) + { + super(reader, fileSpec); + recordSpec=(DelimitedFlatFileRecordSpec)fileSpec.getRecordSpecs().get(0); + } + + /** * Parses the given record string where fields are delimited by a special character * and returns the reader record. Index: FlatFileWriter.java =================================================================== RCS file: /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/io/flat/FlatFileWriter.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** FlatFileWriter.java 12 Jun 2006 13:15:37 -0000 1.2 --- FlatFileWriter.java 13 Jun 2006 22:10:08 -0000 1.3 *************** *** 15,22 **** import java.io.OutputStream; import java.io.OutputStreamWriter; ! import java.util.Arrays; import java.util.HashMap; - import java.util.Iterator; - import java.util.List; import java.util.Map; import org.apache.log4j.Logger; --- 15,20 ---- import java.io.OutputStream; import java.io.OutputStreamWriter; ! import java.io.Writer; import java.util.HashMap; import java.util.Map; import org.apache.log4j.Logger; *************** *** 66,75 **** public FlatFileWriter(OutputStream outputStream,FileSpec fileSpec) { logger.trace("Entering FlatFileWriter constructor"); this.fileSpec=fileSpec; ! writer=new BufferedWriter(new OutputStreamWriter(outputStream)); logger.info("Done creating the flat file writer."); } ! /** * Creates the writer record assocites with the given record type. --- 64,84 ---- public FlatFileWriter(OutputStream outputStream,FileSpec fileSpec) { + this(new OutputStreamWriter(outputStream), fileSpec); + } + + /** + * Constructs and initializes the writer with the given values. + * + * @param writer Writer to write the records. + * @param fileSpec File spec to be used to generate the file. + */ + public FlatFileWriter(Writer writer,FileSpec fileSpec) + { logger.trace("Entering FlatFileWriter constructor"); this.fileSpec=fileSpec; ! this.writer=new BufferedWriter(writer); logger.info("Done creating the flat file writer."); } ! /** * Creates the writer record assocites with the given record type. Index: DelimitedFlatFileWriter.java =================================================================== RCS file: /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/io/flat/DelimitedFlatFileWriter.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** DelimitedFlatFileWriter.java 12 Jun 2006 20:58:51 -0000 1.3 --- DelimitedFlatFileWriter.java 13 Jun 2006 22:10:08 -0000 1.4 *************** *** 12,15 **** --- 12,16 ---- import java.io.OutputStream; + import java.io.Writer; import java.util.Iterator; import org.apache.log4j.Logger; *************** *** 53,56 **** --- 54,70 ---- /** + * Constructs the Delimited flat file writer from the given output stream + * and file spec. + * + * @param writer Writer representing the file to generate. + * @param fileSpec File spec of the delimited flat to be generated. + */ + public DelimitedFlatFileWriter(Writer writer,FileSpec fileSpec) + { + super(writer,fileSpec); + recordSpec=(DelimitedFlatFileRecordSpec)fileSpec.getRecordSpecs().get(0); + } + + /** * Generates the string represenatation of the record from the writer record given by client. * Index: FixedWidthFlatFileWriter.java =================================================================== RCS file: /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/io/flat/FixedWidthFlatFileWriter.java,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** FixedWidthFlatFileWriter.java 12 Jun 2006 13:15:37 -0000 1.7 --- FixedWidthFlatFileWriter.java 13 Jun 2006 22:10:08 -0000 1.8 *************** *** 12,15 **** --- 12,16 ---- import java.io.IOException; import java.io.OutputStream; + import java.io.Writer; import java.util.Arrays; import java.util.Iterator; *************** *** 17,21 **** import org.apache.log4j.Logger; import org.jmonks.batchserver.io.FileSpec; - import org.jmonks.batchserver.io.RecordType; import org.jmonks.batchserver.io.WriterRecord; import org.jmonks.batchserver.io.flat.FlatFileWriter.FlatFileWriterRecord; --- 18,21 ---- *************** *** 50,53 **** --- 50,64 ---- /** + * Constructs and initializes the writer with the given values. + * + * @param writer Writer to write the records. + * @param fileSpec File spec to be used to generate the file. + */ + public FixedWidthFlatFileWriter(Writer writer,FileSpec fileSpec) + { + super(writer,fileSpec); + } + + /** * Writes the given record into the file/writer. * Index: FlatFileReader.java =================================================================== RCS file: /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/io/flat/FlatFileReader.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** FlatFileReader.java 12 Jun 2006 13:15:37 -0000 1.2 --- FlatFileReader.java 13 Jun 2006 22:10:08 -0000 1.3 *************** *** 15,18 **** --- 15,19 ---- import java.io.InputStream; import java.io.InputStreamReader; + import java.io.Reader; import java.util.HashMap; import java.util.Map; *************** *** 54,60 **** public FlatFileReader(InputStream fileInputStream,FileSpec fileSpec) { logger.trace("Entering FlatFileReader constructor"); this.fileSpec=fileSpec; ! reader=new BufferedReader(new InputStreamReader(fileInputStream)); logger.info("Done creating the flat file reader."); } --- 55,72 ---- public FlatFileReader(InputStream fileInputStream,FileSpec fileSpec) { + this(new InputStreamReader(fileInputStream),fileSpec); + } + + /** + * Constructs and initializes the flat file reader with the given file path and file spec. + * + * @param reader Reader to the file. + * @param fileSpec File spec to be used to read the file. + */ + public FlatFileReader(Reader reader,FileSpec fileSpec) + { logger.trace("Entering FlatFileReader constructor"); this.fileSpec=fileSpec; ! reader=new BufferedReader(reader); logger.info("Done creating the flat file reader."); } |
From: Suresh <sur...@us...> - 2006-06-13 22:10:00
|
Update of /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/io In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv28202 Modified Files: FileReader.java FileSpec.java FileWriter.java package.html RecordType.java Log Message: no message Index: FileWriter.java =================================================================== RCS file: /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/io/FileWriter.java,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** FileWriter.java 13 Jun 2006 04:01:36 -0000 1.7 --- FileWriter.java 13 Jun 2006 22:09:54 -0000 1.8 *************** *** 12,15 **** --- 12,16 ---- import java.io.InputStream; import java.io.OutputStream; + import java.io.Writer; import org.apache.log4j.Logger; import org.jmonks.batchserver.io.flat.DelimitedFlatFileWriter; *************** *** 129,131 **** --- 130,193 ---- throw new FileSpecException("Unsupported file type in the file spec = " + fileSpec.getFileType().toString()); } + + /** + * <p> + * Factory method to get the file writer. This method returns the appropriate file writer + * based on the file type specified in the file spec. + * </p> + * + * @param writer Writer to write the records. + * @param fileSpecInputStream Input stream to read the file spec. + * + * @return Returns the appropriate writer. + * + * @throws IllegalArgumentException If the given file output stream or file spec is null. + * @throws org.jmonks.batchserver.io.FileSpecException If the configured file type in file spec doesnt + * exist in FileType class. + */ + public static FileWriter getFileWriter(Writer writer,InputStream fileSpecInputStream) + { + logger.trace("Entering getFileReader"); + if(writer==null) + throw new IllegalArgumentException("Writer to write the records cannot be null."); + if(fileSpecInputStream==null) + throw new IllegalArgumentException("Input stream to read the file spec cannot be null."); + + FileSpec fileSpec=FileSpec.createFileSpec(fileSpecInputStream); + return FileWriter.getFileWriter(writer, fileSpec); + } + + /** + * <p> + * Factory method to get the file writer. This method returns the appropriate file writer + * based on the file type specified in the file spec. + * </p> + * + * @param writer Writer to write the records. + * @param fileSpec File spec to be used to create the writer. + * + * @return Returns the appropriate writer. + * + * @throws IllegalArgumentException If the given file output stream or file spec is null. + * @throws org.jmonks.batchserver.io.FileSpecException If the configured file type in file spec doesnt + * exist in FileType class. + */ + public static FileWriter getFileWriter(Writer writer, FileSpec fileSpec) + { + logger.trace("Entering getFileReader"); + if(writer==null) + throw new IllegalArgumentException("Writer to write the records cannot be null."); + if(fileSpec==null) + throw new IllegalArgumentException("File spec to create the writer cannot be null."); + + logger.debug("Given file spec = " + fileSpec.toString()); + if(fileSpec.getFileType()==FileType.FIXED_WIDTH_FLAT_FILE) + return new FixedWidthFlatFileWriter(writer,fileSpec); + else if(fileSpec.getFileType()==FileType.DELIMITED_FLAT_FILE) + return new DelimitedFlatFileWriter(writer, fileSpec); + else if(fileSpec.getFileType()==FileType.XML_FILE) + return new XMLFileWriter(writer,fileSpec); + else + throw new FileSpecException("Unsupported file type in the file spec = " + fileSpec.getFileType().toString()); + } } Index: package.html =================================================================== RCS file: /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/io/package.html,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** package.html 13 Jun 2006 04:01:36 -0000 1.2 --- package.html 13 Jun 2006 22:09:54 -0000 1.3 *************** *** 5,9 **** </head> <body> ! Explain the usage of IO API. </body> </html> --- 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> Index: FileSpec.java =================================================================== RCS file: /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/io/FileSpec.java,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** FileSpec.java 10 Jun 2006 17:50:24 -0000 1.10 --- FileSpec.java 13 Jun 2006 22:09:54 -0000 1.11 *************** *** 118,123 **** --- 118,128 ---- /** + * <p> * Gets all the record spec's in this file spec as a list. * + * TODO :: There is chance that client might misuse this list. Based on the + * performance create a new list and return it. + * </p> + * * @return Returns record spec's as a list. */ Index: RecordType.java =================================================================== RCS file: /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/io/RecordType.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** RecordType.java 10 Jun 2006 17:50:24 -0000 1.6 --- RecordType.java 13 Jun 2006 22:09:54 -0000 1.7 *************** *** 44,52 **** if(type!=null) { ! if("HEADER".equalsIgnoreCase(type) || "DETAIL".equalsIgnoreCase(type) || "TRAILOR".equalsIgnoreCase(type) ! || "BLOCK-START".equalsIgnoreCase(type) || "BLOCK-END".equalsIgnoreCase(type)) ! throw new IllegalArgumentException("Record type value " + type + " is in use."); ! else ! this.type=type; } else --- 44,48 ---- if(type!=null) { ! this.type=type; } else *************** *** 67,79 **** public static RecordType toRecordType(String recordType) { ! if(RecordType.HEADER.equals(recordType)) return RecordType.HEADER; ! else if(RecordType.DETAIL.equals(recordType)) return RecordType.DETAIL; ! else if(RecordType.TRAILOR.equals(recordType)) return RecordType.TRAILOR; ! else if(RecordType.BLOCK_START.equals(recordType)) return RecordType.BLOCK_START; ! else if(RecordType.BLOCK_END.equals(recordType)) return RecordType.BLOCK_END; else --- 63,75 ---- public static RecordType toRecordType(String recordType) { ! if(RecordType.HEADER.toString().equalsIgnoreCase(recordType)) return RecordType.HEADER; ! 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; ! else if(RecordType.BLOCK_END.toString().equalsIgnoreCase(recordType)) return RecordType.BLOCK_END; else Index: FileReader.java =================================================================== RCS file: /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/io/FileReader.java,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** FileReader.java 13 Jun 2006 04:01:35 -0000 1.12 --- FileReader.java 13 Jun 2006 22:09:53 -0000 1.13 *************** *** 11,14 **** --- 11,15 ---- package org.jmonks.batchserver.io; import java.io.InputStream; + import java.io.Reader; import org.apache.log4j.Logger; import org.jmonks.batchserver.io.flat.DelimitedFlatFileReader; *************** *** 125,127 **** --- 126,189 ---- throw new FileSpecException("Unsupported file type in the file spec = " + fileSpec.getFileType().toString()); } + + /** + * <p> + * Factory method to get the file reader. This method returns the appropriate file reader + * based on the file type specified in the file spec. + * </p> + * + * @param reader Reader to read the data file. + * @param fileSpecInputStream Input stream to read the file spec. + * + * @return Returns the appropriate reader. + * + * @throws IllegalArgumentException If the given fileInputStream or fileSpecInputStream is null. + * @throws org.jmonks.batchserver.io.FileSpecException If the configured file type in file spec doesnt + * exist in FileType class. + */ + public static FileReader getFileReader(Reader reader,InputStream fileSpecInputStream) + { + logger.trace("Entering getFileReader"); + if(reader==null) + throw new IllegalArgumentException("Reader to read the data file cannot be null."); + if(fileSpecInputStream==null) + throw new IllegalArgumentException("Input stream to read the file spec cannot be null."); + + FileSpec fileSpec=FileSpec.createFileSpec(fileSpecInputStream); + return FileReader.getFileReader(reader, fileSpec); + } + /** + * <p> + * Factory method to get the file reader. This method returns the appropriate file reader + * based on the file type specified in the file spec. + * </p> + * + * @param reader Reader to read the data file. + * @param fileSpec File spec to create the file reader. + * + * @return Returns the appropriate reader. + * + * @throws IllegalArgumentException If the given fileInputStream or fileSpec is null. + * @throws org.jmonks.batchserver.io.FileSpecException If the configured file type in file spec doesnt + * exist in FileType class. + */ + public static FileReader getFileReader(Reader reader, FileSpec fileSpec) + { + logger.trace("Entering getFileReader"); + if(reader==null) + throw new IllegalArgumentException("Reader to read the data file cannot be null."); + if(fileSpec==null) + throw new IllegalArgumentException("File spec cannot be null to create the file reader."); + + logger.debug("Given file spec = " + fileSpec.toString()); + if(fileSpec.getFileType()==FileType.FIXED_WIDTH_FLAT_FILE) + return new FixedWidthFlatFileReader(reader,fileSpec); + else if(fileSpec.getFileType()==FileType.DELIMITED_FLAT_FILE) + return new DelimitedFlatFileReader(reader,fileSpec); + else if(fileSpec.getFileType()==FileType.XML_FILE) + return new XMLFileReader(reader,fileSpec); + else + throw new FileSpecException("Unsupported file type in the file spec = " + fileSpec.getFileType().toString()); + } + } |
From: Suresh <sur...@us...> - 2006-06-13 22:09:41
|
Update of /cvsroot/batchserver/batchserver In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv28174 Modified Files: build_io.xml Log Message: no message Index: build_io.xml =================================================================== RCS file: /cvsroot/batchserver/batchserver/build_io.xml,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** build_io.xml 13 Jun 2006 04:02:49 -0000 1.2 --- build_io.xml 13 Jun 2006 22:09:35 -0000 1.3 *************** *** 34,38 **** <pathelement location="${lib.home}/xml/xml_apis.jar"/> <pathelement location="${lib.home}/xml/apache/resolver_2.7.1.jar"/> ! <pathelement location="${lib.home}/xml/apache/xerces_impl_2.7.1.jar"/> <pathelement location="${lib.home}/stax/stax_api_1.0.zip"/> <pathelement location="${lib.home}/stax/ri/stax_impl_1.2.zip"/> --- 34,38 ---- <pathelement location="${lib.home}/xml/xml_apis.jar"/> <pathelement location="${lib.home}/xml/apache/resolver_2.7.1.jar"/> ! <pathelement location="${lib.home}/xml/apache/xerces_impl_2.7.1.jar"/> <pathelement location="${lib.home}/stax/stax_api_1.0.zip"/> <pathelement location="${lib.home}/stax/ri/stax_impl_1.2.zip"/> *************** *** 90,94 **** <include name="xml/xml_apis.jar"/> <include name="xml/apache/resolver_2.7.1.jar"/> ! <include name="xml/apache/xerces_impl_2.7.1.jar"/> <include name="stax/ri/stax_impl_1.2.zip"/> <include name="stax/stax_api_1.0.zip"/> --- 90,94 ---- <include name="xml/xml_apis.jar"/> <include name="xml/apache/resolver_2.7.1.jar"/> ! <include name="xml/apache/xerces_impl_2.7.1.jar"/> <include name="stax/ri/stax_impl_1.2.zip"/> <include name="stax/stax_api_1.0.zip"/> *************** *** 100,104 **** <copy todir="${dist.home}/src"> <fileset dir="${src.home}"> ! <include name="org/jmonks/batchserver/io/**.java"/> </fileset> </copy> --- 100,110 ---- <copy todir="${dist.home}/src"> <fileset dir="${src.home}"> ! <include name="org/jmonks/batchserver/io/*.java"/> ! <include name="org/jmonks/batchserver/io/flat/*.java"/> ! <include name="org/jmonks/batchserver/io/xml/*.java"/> ! <include name="org/jmonks/batchserver/io/flat/*.xml"/> ! <include name="org/jmonks/batchserver/io/xml/*.xml"/> ! <include name="org/jmonks/batchserver/io/flat/*.dat"/> ! <include name="org/jmonks/batchserver/io/xml/*.dat"/> </fileset> </copy> |
From: Suresh <sur...@us...> - 2006-06-13 04:02:51
|
Update of /cvsroot/batchserver/batchserver In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv29973 Modified Files: build_io.xml Log Message: no message Index: build_io.xml =================================================================== RCS file: /cvsroot/batchserver/batchserver/build_io.xml,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** build_io.xml 9 Jun 2006 03:57:50 -0000 1.1 --- build_io.xml 13 Jun 2006 04:02:49 -0000 1.2 *************** *** 35,39 **** <pathelement location="${lib.home}/xml/apache/resolver_2.7.1.jar"/> <pathelement location="${lib.home}/xml/apache/xerces_impl_2.7.1.jar"/> - <pathelement location="${lib.home}/stax/some.jar"/> <pathelement location="${lib.home}/stax/stax_api_1.0.zip"/> <pathelement location="${lib.home}/stax/ri/stax_impl_1.2.zip"/> --- 35,38 ---- *************** *** 76,86 **** --- 75,106 ---- <target name="dist" depends="source-clean,source-compile,javadoc" description="Create binary distribution"> + <!-- Copy documentation subdirectories --> <delete dir="${dist.home}"/> <mkdir dir="${dist.home}"/> + <mkdir dir="${dist.home}/docs"/> <copy todir="${dist.home}/docs"> <fileset dir="${docs.home}"/> </copy> + + <mkdir dir="${dist.home}/lib"/> + <copy todir="${dist.home}/lib"> + <fileset dir="${lib.home}"> + <include name="xml/xml_apis.jar"/> + <include name="xml/apache/resolver_2.7.1.jar"/> + <include name="xml/apache/xerces_impl_2.7.1.jar"/> + <include name="stax/ri/stax_impl_1.2.zip"/> + <include name="stax/stax_api_1.0.zip"/> + <include name="log4j/log4j_1.2.13.jar"/> + </fileset> + </copy> + + <mkdir dir="${dist.home}/src"/> + <copy todir="${dist.home}/src"> + <fileset dir="${src.home}"> + <include name="org/jmonks/batchserver/io/**.java"/> + </fileset> + </copy> <!-- Create application JAR file --> |
From: Suresh <sur...@us...> - 2006-06-13 04:02:36
|
Update of /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/io/xml In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv29953 Modified Files: XMLFileWriter.java Added Files: package.html PrettyXMLIndentationEngine.java XMLIndentationEngine.java Log Message: no message --- NEW FILE: XMLIndentationEngine.java --- /* * XMLIndentationEngine.java * * Created on June 12, 2006, 10:01 PM * * To change this template, choose Tools | Options and locate the template under * the Source Creation and Management node. Right-click the template and choose * Open. You can then make changes to the template in the Source Editor. */ package org.jmonks.batchserver.io.xml; /** * <p> * XMLIndentationEngine returns the indentation information to be written to the stream * based on events received. It receives the events before start and end tags being written * to the stream. * * @author Suresh Pragada * @version 1.0 * @since 1.0 * </p> */ public interface XMLIndentationEngine { /** * Returns the indentation string needs to be written to tbe stream before * the start element being written. */ public String startElement(); /** * Returns the indentation string needs to be written to tbe stream before * the element element being written. */ public String endElement(); } Index: XMLFileWriter.java =================================================================== RCS file: /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/io/xml/XMLFileWriter.java,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** XMLFileWriter.java 12 Jun 2006 20:59:02 -0000 1.7 --- XMLFileWriter.java 13 Jun 2006 04:02:33 -0000 1.8 *************** *** 11,14 **** --- 11,15 ---- package org.jmonks.batchserver.io.xml; import java.io.OutputStream; + import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; *************** *** 51,55 **** * Egnine to be used for the indentation. */ ! private XMLIndentationEngine indentationEngine=new XMLIndentationEngine(); private static Logger logger=Logger.getLogger(XMLFileWriter.class); --- 52,56 ---- * Egnine to be used for the indentation. */ ! private XMLIndentationEngine indentationEngine=new PrettyXMLIndentationEngine(); private static Logger logger=Logger.getLogger(XMLFileWriter.class); *************** *** 71,75 **** logger.debug("Writer has been created."); writer.writeStartDocument("ISO-8859-1", "1.0"); ! indentationEngine.startElement(); writer.writeStartElement(this.fileSpec.rootElement); } --- 72,76 ---- logger.debug("Writer has been created."); writer.writeStartDocument("ISO-8859-1", "1.0"); ! writer.writeCharacters(indentationEngine.startElement()); writer.writeStartElement(this.fileSpec.rootElement); } *************** *** 101,104 **** --- 102,107 ---- { XMLWriterRecord record=(XMLWriterRecord)writerRecord; + if(record.isNestedElementRecord()) + throw new IllegalArgumentException("Writer record should be obtained from the file writer to write into the file."); XMLRecordSpec recordSpec=(XMLRecordSpec)this.fileSpec.getRecordSpec(record.getRecordType()); String recordXpath=recordSpec.getRecordXPath(); *************** *** 128,135 **** protected void writeSimpleElement(String fieldName,Object fieldValue) throws XMLStreamException { ! indentationEngine.startElement(); writer.writeStartElement(fieldName); writer.writeCharacters((fieldValue!=null)?fieldValue.toString():""); ! indentationEngine.endElement(); writer.writeEndElement(); } --- 131,138 ---- protected void writeSimpleElement(String fieldName,Object fieldValue) throws XMLStreamException { ! writer.writeCharacters(indentationEngine.startElement()); writer.writeStartElement(fieldName); writer.writeCharacters((fieldValue!=null)?fieldValue.toString():""); ! writer.writeCharacters(indentationEngine.endElement()); writer.writeEndElement(); } *************** *** 143,147 **** protected void writeComplexElement(String recordElementName,XMLWriterRecord fieldValueAsRecord) throws XMLStreamException { ! indentationEngine.startElement(); writer.writeStartElement(recordElementName); for(Iterator iterator=fieldValueAsRecord.getFieldNameIterator();iterator.hasNext();) --- 146,150 ---- protected void writeComplexElement(String recordElementName,XMLWriterRecord fieldValueAsRecord) throws XMLStreamException { ! writer.writeCharacters(indentationEngine.startElement()); writer.writeStartElement(recordElementName); for(Iterator iterator=fieldValueAsRecord.getFieldNameIterator();iterator.hasNext();) *************** *** 162,166 **** } } ! indentationEngine.endElement(); writer.writeEndElement(); } --- 165,169 ---- } } ! writer.writeCharacters(indentationEngine.endElement()); writer.writeEndElement(); } *************** *** 287,290 **** --- 290,295 ---- public void writeField(String fieldName, Object fieldValue) { + if(fieldName==null) + throw new IllegalArgumentException("Field name cannot be null to write the field."); this.fieldMap.put(fieldName, fieldValue); } *************** *** 295,326 **** public void writeSimpleElement(String fieldName, String fieldValue) { this.fieldMap.put(fieldName, fieldValue); } /** ! * Write nested/composite element into the record. */ ! public void writeComplexElement(String fieldName, WriterRecord fieldValue) { ! this.fieldMap.put(fieldName, fieldValue); } /** ! * Writes the repeated element name and value into the record. * * @param fieldName Name of the field repated more than once. ! * @param fieldValue Value of the field repated more than once. ! */ ! public void writeRepeatElement(String fieldName, List fieldValue) ! { ! this.fieldMap.put(fieldName, fieldValue); ! } ! ! /** ! * Returns */ ! public WriterRecord createComplexElementRecord() { ! return new XMLWriterRecord(super.getRecordType(), true); } --- 300,336 ---- public void writeSimpleElement(String fieldName, String fieldValue) { + if(fieldName==null) + throw new IllegalArgumentException("Field name cannot be null to write simple element."); this.fieldMap.put(fieldName, fieldValue); } /** ! * Create complex element and add it to the record and returns the writer ! * record instance to which all the elements can be adde. */ ! public WriterRecord createComplexElement(String fieldName) { ! if(fieldName==null) ! throw new IllegalArgumentException("Field name cannot be null to create the complex element."); ! WriterRecord complexElement=new XMLWriterRecord(super.getRecordType(), true); ! this.fieldMap.put(fieldName, complexElement); ! return complexElement; } /** ! * Creates the list and it to the record with the given field name ! * and returns the list to which values can be added. * * @param fieldName Name of the field repated more than once. ! * ! * @return Returns the list. */ ! public List writeRepeatElement(String fieldName) { ! if(fieldName==null) ! throw new IllegalArgumentException("Field name cannot be null to create the repeat element."); ! List repeatElement=new ArrayList(); ! this.fieldMap.put(fieldName, repeatElement); ! return repeatElement; } *************** *** 342,398 **** } - /** - * <p> - * XMLIndentationEngine writes the indentation information to the streams - * based on events received. It receives the events before tags being written - * to the stream. - * <br> - * TODO ::: Take this class outside and allow others to write their indentation engines. - * </p> - */ - private class XMLIndentationEngine - { - private boolean isPrevStartElement=false; - private boolean isPrevEndElement=false; - - private String indentationString="\n"; - - private XMLIndentationEngine() - { - } - - /** - * Receives before element is being writting to the stream. - */ - private void startElement() throws XMLStreamException - { - isPrevEndElement=false; - if(isPrevStartElement) - { - this.indentationString+=" "; - writer.writeCharacters(this.indentationString); - } - else - { - isPrevStartElement=true; - writer.writeCharacters(indentationString); - } - } - /** - * Receives before end element is being writting to the stream. - */ - private void endElement() throws XMLStreamException - { - isPrevStartElement=false; - if(isPrevEndElement) - { - this.indentationString=this.indentationString.substring(0, this.indentationString.length()-4); - writer.writeCharacters(this.indentationString); - } - else - { - isPrevEndElement=true; - } - } - } } --- 352,354 ---- --- NEW FILE: package.html --- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>XML File Implementation Overview</title> </head> <body> Explain the usage of XML File IO API. </body> </html> --- NEW FILE: PrettyXMLIndentationEngine.java --- /* * PrettyXMLIndentationEngine.java * * Created on June 12, 2006, 10:06 PM * * To change this template, choose Tools | Options and locate the template under * the Source Creation and Management node. Right-click the template and choose * Open. You can then make changes to the template in the Source Editor. */ package org.jmonks.batchserver.io.xml; /** * <p> * PrettyXMLIndentationEngine writes the the elements in XML in the folloing manner. * <br> * <pre> * <root> * <element1>element-data1</element1> * <element2> * <element3>element-data3</element> * <element4>element-data4</element> * </element2> * </root> * </pre> * </p> * * @author Suresh Pragada * @version 1.0 * @since 1.0 */ public class PrettyXMLIndentationEngine implements XMLIndentationEngine { /** * Remembers previous element is start element. */ private boolean isPrevStartElement=false; /** * Remembers previous element is end element. */ private boolean isPrevEndElement=false; private String indentationString="\n"; public PrettyXMLIndentationEngine() { } /** * @see org.jmonks.batchserver.io.xml.XMLIndentationEngine#startElement */ public String startElement() { isPrevEndElement=false; if(isPrevStartElement) { this.indentationString+=" "; return this.indentationString; } else { isPrevStartElement=true; return this.indentationString; } } /** * @see org.jmonks.batchserver.io.xml.XMLIndentationEngine#endElement */ public String endElement() { isPrevStartElement=false; if(isPrevEndElement) { this.indentationString=this.indentationString.substring(0, this.indentationString.length()-4); return this.indentationString; } else { isPrevEndElement=true; return ""; } } } |
From: Suresh <sur...@us...> - 2006-06-13 04:02:07
|
Update of /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/io/flat In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv29576 Added Files: package.html Log Message: no message --- NEW FILE: package.html --- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>Flat File Implementation Overview</title> </head> <body> Explain the usage of Flat File IO API. </body> </html> |
From: Suresh <sur...@us...> - 2006-06-13 04:01:41
|
Update of /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/io In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv29536 Modified Files: FileReader.java FileWriter.java package.html Log Message: no message Index: FileWriter.java =================================================================== RCS file: /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/io/FileWriter.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** FileWriter.java 10 Jun 2006 17:50:24 -0000 1.6 --- FileWriter.java 13 Jun 2006 04:01:36 -0000 1.7 *************** *** 80,85 **** * @return Returns the appropriate writer. * ! * @throws IllegalArgumentException If the given file path or file spec path is null or ! * or if they are directoires. * @throws org.jmonks.batchserver.io.FileSpecException If the configured file type in file spec doesnt * exist in FileType class. --- 80,84 ---- * @return Returns the appropriate writer. * ! * @throws IllegalArgumentException If the given file output stream or file spec is null. * @throws org.jmonks.batchserver.io.FileSpecException If the configured file type in file spec doesnt * exist in FileType class. *************** *** 88,99 **** { logger.trace("Entering getFileReader"); - if(outputStream==null) throw new IllegalArgumentException("Output stream to write the records cannot be null."); - if(fileSpecInputStream==null) throw new IllegalArgumentException("Input stream to read the file spec cannot be null."); FileSpec fileSpec=FileSpec.createFileSpec(fileSpecInputStream); logger.debug("Given file spec = " + fileSpec.toString()); if(fileSpec.getFileType()==FileType.FIXED_WIDTH_FLAT_FILE) --- 87,122 ---- { logger.trace("Entering getFileReader"); if(outputStream==null) throw new IllegalArgumentException("Output stream to write the records cannot be null."); if(fileSpecInputStream==null) throw new IllegalArgumentException("Input stream to read the file spec cannot be null."); FileSpec fileSpec=FileSpec.createFileSpec(fileSpecInputStream); + return FileWriter.getFileWriter(outputStream, fileSpec); + } + + /** + * <p> + * Factory method to get the file writer. This method returns the appropriate file writer + * based on the file type specified in the file spec. + * </p> + * + * @param outputStream Output stream to write the records. + * @param fileSpec File spec to be used to create the writer. + * + * @return Returns the appropriate writer. + * + * @throws IllegalArgumentException If the given file output stream or file spec is null. + * @throws org.jmonks.batchserver.io.FileSpecException If the configured file type in file spec doesnt + * exist in FileType class. + */ + public static FileWriter getFileWriter(OutputStream outputStream, FileSpec fileSpec) + { + logger.trace("Entering getFileReader"); + if(outputStream==null) + throw new IllegalArgumentException("Output stream to write the records cannot be null."); + if(fileSpec==null) + throw new IllegalArgumentException("File spec to create the writer cannot be null."); + logger.debug("Given file spec = " + fileSpec.toString()); if(fileSpec.getFileType()==FileType.FIXED_WIDTH_FLAT_FILE) *************** *** 104,108 **** return new XMLFileWriter(outputStream,fileSpec); else ! throw new FileSpecException("Unsupported file type in the file spec = " + fileSpec.getFileType().toString()); ! } } --- 127,131 ---- return new XMLFileWriter(outputStream,fileSpec); else ! throw new FileSpecException("Unsupported file type in the file spec = " + fileSpec.getFileType().toString()); ! } } Index: package.html =================================================================== RCS file: /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/io/package.html,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** package.html 9 Jun 2006 03:57:22 -0000 1.1 --- package.html 13 Jun 2006 04:01:36 -0000 1.2 *************** *** 5,9 **** </head> <body> ! Here explain the usage of IO API. </body> </html> --- 5,9 ---- </head> <body> ! Explain the usage of IO API. </body> </html> Index: FileReader.java =================================================================== RCS file: /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/io/FileReader.java,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** FileReader.java 10 Jun 2006 17:50:24 -0000 1.11 --- FileReader.java 13 Jun 2006 04:01:35 -0000 1.12 *************** *** 77,82 **** * @return Returns the appropriate reader. * ! * @throws IllegalArgumentException If the given file path or file spec path is null or ! * doesnt exist and if they are directoires. * @throws org.jmonks.batchserver.io.FileSpecException If the configured file type in file spec doesnt * exist in FileType class. --- 77,81 ---- * @return Returns the appropriate reader. * ! * @throws IllegalArgumentException If the given fileInputStream or fileSpecInputStream is null. * @throws org.jmonks.batchserver.io.FileSpecException If the configured file type in file spec doesnt * exist in FileType class. *************** *** 85,96 **** { logger.trace("Entering getFileReader"); - if(fileInputStream==null) throw new IllegalArgumentException("Input stream to read the data file cannot be null."); - if(fileSpecInputStream==null) throw new IllegalArgumentException("Input stream to read the file spec cannot be null."); FileSpec fileSpec=FileSpec.createFileSpec(fileSpecInputStream); logger.debug("Given file spec = " + fileSpec.toString()); if(fileSpec.getFileType()==FileType.FIXED_WIDTH_FLAT_FILE) --- 84,118 ---- { logger.trace("Entering getFileReader"); if(fileInputStream==null) throw new IllegalArgumentException("Input stream to read the data file cannot be null."); if(fileSpecInputStream==null) throw new IllegalArgumentException("Input stream to read the file spec cannot be null."); FileSpec fileSpec=FileSpec.createFileSpec(fileSpecInputStream); + return FileReader.getFileReader(fileInputStream, fileSpec); + } + /** + * <p> + * Factory method to get the file reader. This method returns the appropriate file reader + * based on the file type specified in the file spec. + * </p> + * + * @param fileInputStream Input stream to read the data file. + * @param fileSpec File spec to create the file reader. + * + * @return Returns the appropriate reader. + * + * @throws IllegalArgumentException If the given fileInputStream or fileSpec is null. + * @throws org.jmonks.batchserver.io.FileSpecException If the configured file type in file spec doesnt + * exist in FileType class. + */ + public static FileReader getFileReader(InputStream fileInputStream, FileSpec fileSpec) + { + logger.trace("Entering getFileReader"); + if(fileInputStream==null) + throw new IllegalArgumentException("Input stream to read the data file cannot be null."); + if(fileSpec==null) + throw new IllegalArgumentException("File spec cannot be null to create the file reader."); + logger.debug("Given file spec = " + fileSpec.toString()); if(fileSpec.getFileType()==FileType.FIXED_WIDTH_FLAT_FILE) *************** *** 101,105 **** return new XMLFileReader(fileInputStream,fileSpec); else ! throw new FileSpecException("Unsupported file type in the file spec = " + fileSpec.getFileType().toString()); } } --- 123,127 ---- return new XMLFileReader(fileInputStream,fileSpec); else ! throw new FileSpecException("Unsupported file type in the file spec = " + fileSpec.getFileType().toString()); } } |
From: Suresh <sur...@us...> - 2006-06-12 20:59:06
|
Update of /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/io/xml In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv22023 Modified Files: XMLFileReader.java XMLFileWriter.java Log Message: no message Index: XMLFileReader.java =================================================================== RCS file: /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/io/xml/XMLFileReader.java,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** XMLFileReader.java 10 Jun 2006 17:51:54 -0000 1.8 --- XMLFileReader.java 12 Jun 2006 20:59:02 -0000 1.9 *************** *** 361,365 **** fieldMap=new HashMap(); } ! /** * Reads the values associated with the given field name and returns. --- 361,365 ---- fieldMap=new HashMap(); } ! /** * Reads the values associated with the given field name and returns. *************** *** 461,464 **** } } - } --- 461,463 ---- Index: XMLFileWriter.java =================================================================== RCS file: /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/io/xml/XMLFileWriter.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** XMLFileWriter.java 10 Jun 2006 17:51:54 -0000 1.6 --- XMLFileWriter.java 12 Jun 2006 20:59:02 -0000 1.7 *************** *** 207,211 **** { if(this.fileSpec.isValidRecordType(recordType)) ! return new XMLWriterRecord(recordType); else throw new IllegalArgumentException("Record type " + recordType + " doesnt match with any record specs."); --- 207,211 ---- { if(this.fileSpec.isValidRecordType(recordType)) ! return new XMLWriterRecord(recordType,false); else throw new IllegalArgumentException("Record type " + recordType + " doesnt match with any record specs."); *************** *** 257,270 **** private Map fieldMap=null; /** * Constructs the XML writer record. */ ! private XMLWriterRecord(RecordType recordType) { super(recordType); fieldMap=new HashMap(); } /** * Writes the given field name and value into the record. * --- 257,283 ---- private Map fieldMap=null; + private boolean isNestedElementRecord=false; + /** * Constructs the XML writer record. */ ! private XMLWriterRecord(RecordType recordType, boolean isNestedElementRecord) { super(recordType); + this.isNestedElementRecord=isNestedElementRecord; fieldMap=new HashMap(); } /** + * Tells whether this record has been created to represent the nested element. + * + * @return Returns true if this has been created for the nested element, false otherwise. + */ + private boolean isNestedElementRecord() + { + return this.isNestedElementRecord; + } + + /** * Writes the given field name and value into the record. * *************** *** 303,306 **** --- 316,327 ---- this.fieldMap.put(fieldName, fieldValue); } + + /** + * Returns + */ + public WriterRecord createComplexElementRecord() + { + return new XMLWriterRecord(super.getRecordType(), true); + } /** |
From: Suresh <sur...@us...> - 2006-06-12 20:58:54
|
Update of /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/io/flat In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv21934 Modified Files: DelimitedFlatFileReader.java DelimitedFlatFileRecordSpec.java DelimitedFlatFileWriter.java Log Message: no message Index: DelimitedFlatFileRecordSpec.java =================================================================== RCS file: /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/io/flat/DelimitedFlatFileRecordSpec.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** DelimitedFlatFileRecordSpec.java 10 Jun 2006 17:51:37 -0000 1.1 --- DelimitedFlatFileRecordSpec.java 12 Jun 2006 20:58:51 -0000 1.2 *************** *** 48,51 **** --- 48,55 ---- private String delimiter=null; /** + * Represents the number of fields available in the record. + */ + private int fieldCount; + /** * Constant defines the delimiter attribute name which the value is "delimiter" */ *************** *** 69,72 **** --- 73,84 ---- return this.delimiter; } + + /** + * Returns the number of fields exists in this record. + */ + public int getFieldCount() + { + return this.fieldCount; + } /** *************** *** 103,106 **** --- 115,119 ---- throw new FileSpecException("Record Spec in Delimited File Spec should have delimiter attribute."); + recordSpec.fieldCount=1; NodeList fieldSpecNodeList=recordSpecElement.getElementsByTagName(FieldSpec.FIELD_SPEC_TAG_NAME); for(int i=0;i<fieldSpecNodeList.getLength();i++) *************** *** 116,119 **** --- 129,134 ---- } recordSpec.addFieldSpec(fieldSpec); + if(fieldSpec.getIndex()>recordSpec.fieldCount) + recordSpec.fieldCount=fieldSpec.getIndex(); } return recordSpec; Index: DelimitedFlatFileWriter.java =================================================================== RCS file: /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/io/flat/DelimitedFlatFileWriter.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** DelimitedFlatFileWriter.java 12 Jun 2006 13:15:37 -0000 1.2 --- DelimitedFlatFileWriter.java 12 Jun 2006 20:58:51 -0000 1.3 *************** *** 34,40 **** { private static Logger logger=Logger.getLogger(DelimitedFlatFileWriter.class); ! private DelimitedFlatFileRecordSpec recordSpec=null; ! public DelimitedFlatFileWriter(OutputStream outputStream,FileSpec fileSpec) { --- 34,49 ---- { private static Logger logger=Logger.getLogger(DelimitedFlatFileWriter.class); ! /** ! * Holds the single record spec exists in Delimited file spec. ! */ private DelimitedFlatFileRecordSpec recordSpec=null; ! ! /** ! * Constructs the Delimited flat file writer from the given output stream ! * and file spec. ! * ! * @param fileOutputStream Output stream representing the file to generate. ! * @param fileSpec File spec of the delimited flat to be generated. ! */ public DelimitedFlatFileWriter(OutputStream outputStream,FileSpec fileSpec) { *************** *** 43,51 **** } protected String generateRecord(WriterRecord writerRecord) throws java.io.IOException { FlatFileWriterRecord flatFileWriterRecord=(FlatFileWriterRecord)writerRecord; ! String[] fieldValuesArray=new String[10]; for(Iterator iterator=recordSpec.getFieldSpecs().iterator();iterator.hasNext();) { --- 52,67 ---- } + /** + * Generates the string represenatation of the record from the writer record given by client. + * + * @param writerRecord Writer record consists of field names and values. + * + * @return Returns the string representation of the record. + */ protected String generateRecord(WriterRecord writerRecord) throws java.io.IOException { FlatFileWriterRecord flatFileWriterRecord=(FlatFileWriterRecord)writerRecord; ! String[] fieldValuesArray=new String[recordSpec.getFieldCount()]; for(Iterator iterator=recordSpec.getFieldSpecs().iterator();iterator.hasNext();) { Index: DelimitedFlatFileReader.java =================================================================== RCS file: /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/io/flat/DelimitedFlatFileReader.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** DelimitedFlatFileReader.java 12 Jun 2006 13:15:37 -0000 1.2 --- DelimitedFlatFileReader.java 12 Jun 2006 20:58:51 -0000 1.3 *************** *** 36,42 **** { private static Logger logger=Logger.getLogger(DelimitedFlatFileReader.class); ! private DelimitedFlatFileRecordSpec recordSpec=null; ! public DelimitedFlatFileReader(InputStream fileInputStream,FileSpec fileSpec) { --- 36,51 ---- { private static Logger logger=Logger.getLogger(DelimitedFlatFileReader.class); ! /** ! * Holds the single record spec exists in Delimited file spec. ! */ private DelimitedFlatFileRecordSpec recordSpec=null; ! ! /** ! * Constructs the Delimited flat file reader from the given input stream ! * and file spec. ! * ! * @param fileInputStream Input stream representing the file to parse. ! * @param fileSpec File spec of the delimited flat to be read. ! */ public DelimitedFlatFileReader(InputStream fileInputStream,FileSpec fileSpec) { *************** *** 45,48 **** --- 54,63 ---- } + /** + * Parses the given record string where fields are delimited by a special character + * and returns the reader record. + * + * @param recordString Record consists of fields delimited by special character. + */ protected ReaderRecord parseRecord(String recordString) { |
From: Suresh <sur...@us...> - 2006-06-12 13:15:45
|
Update of /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/io/flat In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv12531 Modified Files: DelimitedFlatFileFileSpec.java DelimitedFlatFileReader.java DelimitedFlatFileWriter.java FixedWidthFlatFileReader.java FixedWidthFlatFileRecordSpec.java FixedWidthFlatFileWriter.java FlatFileReader.java FlatFileWriter.java Log Message: no message Index: FixedWidthFlatFileWriter.java =================================================================== RCS file: /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/io/flat/FixedWidthFlatFileWriter.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** FixedWidthFlatFileWriter.java 10 Jun 2006 17:51:37 -0000 1.6 --- FixedWidthFlatFileWriter.java 12 Jun 2006 13:15:37 -0000 1.7 *************** *** 13,24 **** import java.io.OutputStream; import java.util.Arrays; - import java.util.HashMap; import java.util.Iterator; import java.util.List; - import java.util.Map; import org.apache.log4j.Logger; import org.jmonks.batchserver.io.FileSpec; import org.jmonks.batchserver.io.RecordType; import org.jmonks.batchserver.io.WriterRecord; /** --- 13,23 ---- import java.io.OutputStream; import java.util.Arrays; import java.util.Iterator; import java.util.List; import org.apache.log4j.Logger; import org.jmonks.batchserver.io.FileSpec; import org.jmonks.batchserver.io.RecordType; import org.jmonks.batchserver.io.WriterRecord; + import org.jmonks.batchserver.io.flat.FlatFileWriter.FlatFileWriterRecord; /** *************** *** 51,73 **** /** - * Creates the writer record assocites with the given record type. - * IllegalArgumentException will be thrown, if there is no record - * spec is found with this record type. - * - * @param recordType Type fo the record to be created. - * - * @return Returns the requested writer record. - * - * @throws IllegalArgumentException No record spec is found with this record type. - */ - public WriterRecord createWriterRecord(RecordType recordType) - { - if(this.fileSpec.isValidRecordType(recordType)) - return new FixedWidthFlatFileWriterRecord(recordType); - else - throw new IllegalArgumentException("No record spec has been found with the record type = " + recordType); - } - - /** * Writes the given record into the file/writer. * --- 50,53 ---- *************** *** 81,85 **** { logger.trace("Entering generateRecord"); ! FixedWidthFlatFileWriterRecord record=(FixedWidthFlatFileWriterRecord)writerRecord; FixedWidthFlatFileRecordSpec recordSpec=(FixedWidthFlatFileRecordSpec)this.fileSpec.getRecordSpec(record.getRecordType()); char[] recordBuffer=new char[recordSpec.getRecordSize()]; --- 61,65 ---- { logger.trace("Entering generateRecord"); ! FlatFileWriterRecord record=(FlatFileWriterRecord)writerRecord; FixedWidthFlatFileRecordSpec recordSpec=(FixedWidthFlatFileRecordSpec)this.fileSpec.getRecordSpec(record.getRecordType()); char[] recordBuffer=new char[recordSpec.getRecordSize()]; *************** *** 97,149 **** return new String(recordBuffer); } - - /** - * FixedWidthFlatFileWriterRecord implements WriterRecord 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. - * - * @author Suresh Pragada - */ - public class FixedWidthFlatFileWriterRecord extends WriterRecord - { - /** - * Map to hold the field names and values. - */ - private Map fieldMap=null; - - /** - * Constructs and initializes the writer record. - */ - private FixedWidthFlatFileWriterRecord(RecordType recordType) - { - super(recordType); - fieldMap=new HashMap(); - } - - /** - * Writes the field data into the record. - * - * @param fieldName Name of the field defined in field spec. - * @param fieldValue Value for the field name. - */ - public void writeField(String fieldName, Object fieldValue) - { - this.fieldMap.put(fieldName,fieldValue); - } - - /** - * Reads and returns the value associated with requested field name. - * - * @param fieldName Name of the field. - * - * @return Returns the value associated with the field name. - */ - private Object readField(String fieldName) - { - if(this.fieldMap.containsKey(fieldName)) - return this.fieldMap.get(fieldName); - else - return ""; - } - } } --- 77,79 ---- Index: DelimitedFlatFileFileSpec.java =================================================================== RCS file: /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/io/flat/DelimitedFlatFileFileSpec.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** DelimitedFlatFileFileSpec.java 10 Jun 2006 17:51:37 -0000 1.1 --- DelimitedFlatFileFileSpec.java 12 Jun 2006 13:15:37 -0000 1.2 *************** *** 72,75 **** --- 72,80 ---- throw new FileSpecException("Delimited file spec should have only one record spec."); } + else if(recordSpecNodeList.getLength()<1) + { + logger.fatal("Delimited file spec should have atleast one record spec."); + throw new FileSpecException("Delimited file spec should have atleast one record spec."); + } else { Index: FixedWidthFlatFileReader.java =================================================================== RCS file: /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/io/flat/FixedWidthFlatFileReader.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** FixedWidthFlatFileReader.java 10 Jun 2006 17:51:37 -0000 1.6 --- FixedWidthFlatFileReader.java 12 Jun 2006 13:15:37 -0000 1.7 *************** *** 11,20 **** package org.jmonks.batchserver.io.flat; import java.io.InputStream; - import java.util.HashMap; import java.util.Iterator; import java.util.List; - import java.util.Map; import org.apache.log4j.Logger; import org.jmonks.batchserver.io.*; /** --- 11,19 ---- package org.jmonks.batchserver.io.flat; import java.io.InputStream; import java.util.Iterator; import java.util.List; import org.apache.log4j.Logger; import org.jmonks.batchserver.io.*; + import org.jmonks.batchserver.io.flat.FlatFileReader.FlatFileReaderRecord; /** *************** *** 58,62 **** { logger.trace("Entering parseRecord"); ! FixedWidthFlatFileReaderRecord record=null; List recordSpecList=this.fileSpec.getRecordSpecs(); for(Iterator recordSpecIterator=recordSpecList.iterator();recordSpecIterator.hasNext();) --- 57,61 ---- { logger.trace("Entering parseRecord"); ! FlatFileReaderRecord record=null; List recordSpecList=this.fileSpec.getRecordSpecs(); for(Iterator recordSpecIterator=recordSpecList.iterator();recordSpecIterator.hasNext();) *************** *** 66,70 **** { List fieldSpecList=recordSpec.getFieldSpecs(); ! record=new FixedWidthFlatFileReaderRecord(recordSpec.getRecordType(),fieldSpecList.size()); for(Iterator fieldSpecIterator=fieldSpecList.iterator();fieldSpecIterator.hasNext();) { --- 65,69 ---- { List fieldSpecList=recordSpec.getFieldSpecs(); ! record=new FlatFileReaderRecord(recordSpec.getRecordType(),fieldSpecList.size()); for(Iterator fieldSpecIterator=fieldSpecList.iterator();fieldSpecIterator.hasNext();) { *************** *** 88,143 **** throw new FileParseException("Record " + recordString + " cannot be matched with any configured record specs."); } ! logger.trace("Entering parseRecord"); return record; } - - /** - * FixedWidthFlatFileReaderRecord 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. - * - * @author Suresh Pragada - */ - public class FixedWidthFlatFileReaderRecord extends ReaderRecord - { - /** - * Holds the field data. - */ - private Map fieldMap=null; - - /** - * Private constructor to make sure only reader can create the record. - * - * @param recordType Type of the record. - * @param fieldCount Number of fields expected in this record to initializes the map properly. - */ - private FixedWidthFlatFileReaderRecord(RecordType recordType,int fieldCount) - { - super(recordType); - fieldMap=new HashMap(fieldCount); - } - - /** - * Field values can be read by using the names provided in the field spec. - * - * @param fieldName Name of the field. - * - * @return Returns the field value. - */ - public Object readField(String fieldName) - { - return this.fieldMap.get(fieldName); - } - - /** - * This is for the Reader to write the data into the record. - * - * @param fieldName Name of the field. - * @param fieldValue Value of the field. - */ - private void writeField(String fieldName,String fieldValue) - { - this.fieldMap.put(fieldName,fieldValue); - } - } } --- 87,92 ---- throw new FileParseException("Record " + recordString + " cannot be matched with any configured record specs."); } ! logger.trace("Exiting parseRecord"); return record; } } Index: FlatFileWriter.java =================================================================== RCS file: /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/io/flat/FlatFileWriter.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** FlatFileWriter.java 10 Jun 2006 17:51:37 -0000 1.1 --- FlatFileWriter.java 12 Jun 2006 13:15:37 -0000 1.2 *************** *** 83,87 **** * @throws IllegalArgumentException No record spec is found with this record type. */ ! public abstract WriterRecord createWriterRecord(RecordType recordType); /** --- 83,93 ---- * @throws IllegalArgumentException No record spec is found with this record type. */ ! public WriterRecord createWriterRecord(RecordType recordType) ! { ! if(this.fileSpec.isValidRecordType(recordType)) ! return new FlatFileWriterRecord(recordType); ! else ! throw new IllegalArgumentException("No record spec has been found with the record type = " + recordType); ! } /** *************** *** 160,162 **** --- 166,218 ---- } } + + /** + * FixedWidthFlatFileWriterRecord implements WriterRecord 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. + * + * @author Suresh Pragada + */ + public class FlatFileWriterRecord extends WriterRecord + { + /** + * Map to hold the field names and values. + */ + private Map fieldMap=null; + + /** + * Constructs and initializes the writer record. + */ + protected FlatFileWriterRecord(RecordType recordType) + { + super(recordType); + fieldMap=new HashMap(); + } + + /** + * Writes the field data into the record. + * + * @param fieldName Name of the field defined in field spec. + * @param fieldValue Value for the field name. + */ + public void writeField(String fieldName, Object fieldValue) + { + this.fieldMap.put(fieldName,fieldValue); + } + + /** + * Reads and returns the value associated with requested field name. + * + * @param fieldName Name of the field. + * + * @return Returns the value associated with the field name. + */ + protected Object readField(String fieldName) + { + if(this.fieldMap.containsKey(fieldName)) + return this.fieldMap.get(fieldName); + else + return ""; + } + } } Index: FixedWidthFlatFileRecordSpec.java =================================================================== RCS file: /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/io/flat/FixedWidthFlatFileRecordSpec.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** FixedWidthFlatFileRecordSpec.java 10 Jun 2006 17:51:37 -0000 1.4 --- FixedWidthFlatFileRecordSpec.java 12 Jun 2006 13:15:37 -0000 1.5 *************** *** 140,144 **** recordSize=fieldSpec.getEndPosition(); } - recordSize+=startsWith.length(); recordSpec.recordSize=recordSize; return recordSpec; --- 140,143 ---- Index: DelimitedFlatFileWriter.java =================================================================== RCS file: /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/io/flat/DelimitedFlatFileWriter.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** DelimitedFlatFileWriter.java 10 Jun 2006 17:51:37 -0000 1.1 --- DelimitedFlatFileWriter.java 12 Jun 2006 13:15:37 -0000 1.2 *************** *** 12,41 **** import java.io.OutputStream; import org.apache.log4j.Logger; import org.jmonks.batchserver.io.FileSpec; - import org.jmonks.batchserver.io.RecordType; import org.jmonks.batchserver.io.WriterRecord; /** * ! * @author Suresh Pragada */ public class DelimitedFlatFileWriter extends FlatFileWriter { private static Logger logger=Logger.getLogger(DelimitedFlatFileWriter.class); ! /** Creates a new instance of DelimitedFlatFileWriter */ public DelimitedFlatFileWriter(OutputStream outputStream,FileSpec fileSpec) { super(outputStream,fileSpec); ! } ! ! public WriterRecord createWriterRecord(RecordType recordType) ! { ! return null; } protected String generateRecord(WriterRecord writerRecord) throws java.io.IOException { ! return null; } } --- 12,71 ---- import java.io.OutputStream; + import java.util.Iterator; import org.apache.log4j.Logger; import org.jmonks.batchserver.io.FileSpec; import org.jmonks.batchserver.io.WriterRecord; + import org.jmonks.batchserver.io.flat.FlatFileWriter.FlatFileWriterRecord; /** + * <p> + * DelimitedFlatFileWriter writes/generates the file according to the given file spec + * with the data submitted in the form of WriterRecord's. This provides the methods + * to create the required writer records and write the writer record into the file writer. + * Once finished writing of all the records file writer should be closed by calling + * the "close" method. + * </p> * ! * @author Suresh Pragada ! * @version 1.0 ! * @since 1.0 */ public class DelimitedFlatFileWriter extends FlatFileWriter { private static Logger logger=Logger.getLogger(DelimitedFlatFileWriter.class); ! ! private DelimitedFlatFileRecordSpec recordSpec=null; ! public DelimitedFlatFileWriter(OutputStream outputStream,FileSpec fileSpec) { super(outputStream,fileSpec); ! recordSpec=(DelimitedFlatFileRecordSpec)fileSpec.getRecordSpecs().get(0); } protected String generateRecord(WriterRecord writerRecord) throws java.io.IOException { ! FlatFileWriterRecord flatFileWriterRecord=(FlatFileWriterRecord)writerRecord; ! ! String[] fieldValuesArray=new String[10]; ! for(Iterator iterator=recordSpec.getFieldSpecs().iterator();iterator.hasNext();) ! { ! DelimitedFlatFileFieldSpec fieldSpec=(DelimitedFlatFileFieldSpec)iterator.next(); ! String fieldValue=(String)flatFileWriterRecord.readField(fieldSpec.getFieldName()); ! fieldValuesArray[fieldSpec.getIndex()-1]= fieldValue!=null?fieldValue:""; ! } ! ! StringBuffer recordBuffer=new StringBuffer(); ! for(int i=0;i<fieldValuesArray.length;i++) ! { ! if(i==fieldValuesArray.length-1) ! recordBuffer.append(fieldValuesArray[i]); ! else ! { ! recordBuffer.append(fieldValuesArray[i]); ! recordBuffer.append(recordSpec.getDelimiter()); ! } ! } ! ! return recordBuffer.toString(); } } Index: DelimitedFlatFileReader.java =================================================================== RCS file: /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/io/flat/DelimitedFlatFileReader.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** DelimitedFlatFileReader.java 10 Jun 2006 17:51:37 -0000 1.1 --- DelimitedFlatFileReader.java 12 Jun 2006 13:15:37 -0000 1.2 *************** *** 12,22 **** import java.io.InputStream; import org.apache.log4j.Logger; import org.jmonks.batchserver.io.FileSpec; import org.jmonks.batchserver.io.ReaderRecord; /** * ! * @author Suresh Pragada */ public class DelimitedFlatFileReader extends FlatFileReader --- 12,35 ---- import java.io.InputStream; + import java.util.Iterator; + import java.util.List; import org.apache.log4j.Logger; + import org.jmonks.batchserver.io.FileParseException; import org.jmonks.batchserver.io.FileSpec; import org.jmonks.batchserver.io.ReaderRecord; + import org.jmonks.batchserver.io.flat.FlatFileReader.FlatFileReaderRecord; /** + * <p> + * DelimitedFlatFileReader reads the specified delimited flat file according to the given file spec + * and returns the recrods on the needed basis. Each field value from the record + * should be read using readField method by passing the fieldName mentioned in + * the file spec. To find out how to read each record from the file and to read + * the each field from the record, refer to the FileReader javadoc. + * </p> * ! * @author Suresh Pragada ! * @version 1.0 ! * @since 1.0 */ public class DelimitedFlatFileReader extends FlatFileReader *************** *** 24,36 **** private static Logger logger=Logger.getLogger(DelimitedFlatFileReader.class); public DelimitedFlatFileReader(InputStream fileInputStream,FileSpec fileSpec) { super(fileInputStream, fileSpec); } protected ReaderRecord parseRecord(String recordString) ! { ! return null; } - } --- 37,67 ---- private static Logger logger=Logger.getLogger(DelimitedFlatFileReader.class); + private DelimitedFlatFileRecordSpec recordSpec=null; + public DelimitedFlatFileReader(InputStream fileInputStream,FileSpec fileSpec) { super(fileInputStream, fileSpec); + recordSpec=(DelimitedFlatFileRecordSpec)fileSpec.getRecordSpecs().get(0); } protected ReaderRecord parseRecord(String recordString) ! { ! logger.trace("Entering parseRecord"); ! FlatFileReaderRecord record=null; ! List fieldSpecList=recordSpec.getFieldSpecs(); ! record=new FlatFileReaderRecord(recordSpec.getRecordType(),fieldSpecList.size()); ! String[] fieldValuesArray=recordString.split(recordSpec.getDelimiter()); ! for(Iterator fieldSpecIterator=fieldSpecList.iterator();fieldSpecIterator.hasNext();) ! { ! DelimitedFlatFileFieldSpec fieldSpec=(DelimitedFlatFileFieldSpec)fieldSpecIterator.next(); ! int index=fieldSpec.getIndex(); ! if(index<=fieldValuesArray.length) ! record.writeField(fieldSpec.getFieldName(),fieldValuesArray[index-1]); ! else ! throw new FileParseException("Unable to find the field for the field spec = " + fieldSpec.toString() + ! ". Number of fields found in record from the file = " + fieldValuesArray.length); ! } ! logger.trace("Exiting parseRecord"); ! return record; } } Index: FlatFileReader.java =================================================================== RCS file: /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/io/flat/FlatFileReader.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** FlatFileReader.java 10 Jun 2006 17:51:37 -0000 1.1 --- FlatFileReader.java 12 Jun 2006 13:15:37 -0000 1.2 *************** *** 15,18 **** --- 15,20 ---- import java.io.InputStream; import java.io.InputStreamReader; + import java.util.HashMap; + import java.util.Map; import org.apache.log4j.Logger; import org.jmonks.batchserver.io.*; *************** *** 138,140 **** --- 140,192 ---- */ protected abstract ReaderRecord parseRecord(String recordString); + + /** + * FixedWidthFlatFileReaderRecord 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. + * + * @author Suresh Pragada + */ + public class FlatFileReaderRecord extends ReaderRecord + { + /** + * Holds the field data. + */ + private Map fieldMap=null; + + /** + * Private constructor to make sure only reader can create the record. + * + * @param recordType Type of the record. + * @param fieldCount Number of fields expected in this record to initializes the map properly. + */ + protected FlatFileReaderRecord(RecordType recordType,int fieldCount) + { + super(recordType); + fieldMap=new HashMap(fieldCount); + } + + /** + * Field values can be read by using the names provided in the field spec. + * + * @param fieldName Name of the field. + * + * @return Returns the field value. + */ + public Object readField(String fieldName) + { + return this.fieldMap.get(fieldName); + } + + /** + * This is for the Reader to write the data into the record. + * + * @param fieldName Name of the field. + * @param fieldValue Value of the field. + */ + protected void writeField(String fieldName,String fieldValue) + { + this.fieldMap.put(fieldName,fieldValue); + } + } } |