[Batchserver-cvs] batchserver/src/org/jmonks/batchserver/io FileReader.java, 1.8, 1.9 FileSpec.java
Brought to you by:
suresh_pragada
From: Suresh <sur...@us...> - 2006-06-08 22:21:22
|
Update of /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/io In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv22592 Modified Files: FileReader.java FileSpec.java FileWriter.java 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.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** FileWriter.java 8 Jun 2006 03:39:13 -0000 1.3 --- FileWriter.java 8 Jun 2006 22:21:15 -0000 1.4 *************** *** 26,30 **** * </p> * <p> ! * <pre * FileWriter fileWriter=FileWriter.getFileWriter("/data/consumer.dat","/config/consumer-file-spec.xml"); * WriterRecord record=fileWriter.createWriterRecord(RecordType.DETAIL); --- 26,30 ---- * </p> * <p> ! * <pre> * FileWriter fileWriter=FileWriter.getFileWriter("/data/consumer.dat","/config/consumer-file-spec.xml"); * WriterRecord record=fileWriter.createWriterRecord(RecordType.DETAIL); *************** *** 74,78 **** * </p> * ! * @param filePath Absolute path to create the data file. * @param fileSpecPath Absolute path to the file contains the file spec. * --- 74,78 ---- * </p> * ! * @param filePath Absolute path to create the data file. Path should not be directory and should not exist on the file system. * @param fileSpecPath Absolute path to the file contains the file spec. * Index: FileReader.java =================================================================== RCS file: /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/io/FileReader.java,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** FileReader.java 8 Jun 2006 03:39:13 -0000 1.8 --- FileReader.java 8 Jun 2006 22:21:15 -0000 1.9 *************** *** 21,30 **** * 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 of all the records or required 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. * </p> * <p> ! * <pre * FileReader fileReader=FileReader.getFileReader("/data/consumer.dat","/config/consumer-file-spec.xml"); * ReaderRecord record=null; --- 21,30 ---- * 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. * </p> * <p> ! * <pre> * FileReader fileReader=FileReader.getFileReader("/data/consumer.dat","/config/consumer-file-spec.xml"); * ReaderRecord record=null; Index: FileSpec.java =================================================================== RCS file: /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/io/FileSpec.java,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** FileSpec.java 8 Jun 2006 03:39:13 -0000 1.7 --- FileSpec.java 8 Jun 2006 22:21:15 -0000 1.8 *************** *** 16,22 **** import java.io.IOException; import java.io.InputStream; ! import java.util.ArrayList; ! import java.util.Iterator; import java.util.List; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; --- 16,22 ---- 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; import javax.xml.parsers.DocumentBuilderFactory; *************** *** 69,75 **** protected FileType fileType=null; /** ! * Holds the list of record specs. */ ! protected List recordSpecList=null; /** * Constant defines the file spec tage name. --- 69,75 ---- protected FileType fileType=null; /** ! * Map holds the record specs with their record types as keys. */ ! protected Map recordSpecMap=null; /** * Constant defines the file spec tage name. *************** *** 94,98 **** this.fileSpecPath=fileSpecPath; this.fileType=fileType; ! recordSpecList=new ArrayList(); } --- 94,98 ---- this.fileSpecPath=fileSpecPath; this.fileType=fileType; ! recordSpecMap=new HashMap(); } *************** *** 113,123 **** else { ! for(Iterator iterator=this.recordSpecList.iterator();iterator.hasNext();) { ! RecordSpec existingRecordSpec=(RecordSpec)iterator.next(); ! if(existingRecordSpec.getRecordType().toString().equalsIgnoreCase(recordSpec.getRecordType().toString())) ! throw new FileSpecException("Duplicate record spec with the record type " + recordSpec.getRecordType().toString()); } - return this.recordSpecList.add(recordSpec); } } --- 113,125 ---- else { ! if(this.recordSpecMap.containsKey(recordSpec.getRecordType())) { ! throw new FileSpecException("Duplicate record spec with the same record type " + recordSpec.getRecordType().toString()); ! } ! else ! { ! this.recordSpecMap.put(recordSpec.getRecordType(),recordSpec); ! return true; } } } *************** *** 130,134 **** public List getRecordSpecs() { ! return this.recordSpecList; } --- 132,136 ---- public List getRecordSpecs() { ! return (List)this.recordSpecMap.keySet(); } *************** *** 148,164 **** throw new IllegalArgumentException("RecordType cannot be null to get the record spec from file spec."); else ! { ! for(Iterator iterator=this.recordSpecList.iterator();iterator.hasNext();) ! { ! RecordSpec recordSpec=(RecordSpec)iterator.next(); ! if(recordType.toString().equalsIgnoreCase(recordSpec.getRecordType().toString())) ! { ! return recordSpec; ! } ! } ! return null; ! } } /** * Gets the file type. --- 150,161 ---- throw new IllegalArgumentException("RecordType cannot be null to get the record spec from file spec."); else ! return (RecordSpec)this.recordSpecMap.get(recordType); } + public boolean isValidRecordType(RecordType recordType) + { + return this.recordSpecMap.containsKey(recordType); + } + /** * Gets the file type. Index: RecordType.java =================================================================== RCS file: /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/io/RecordType.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** RecordType.java 8 Jun 2006 03:39:13 -0000 1.4 --- RecordType.java 8 Jun 2006 22:21:15 -0000 1.5 *************** *** 16,19 **** --- 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> * *************** *** 22,26 **** * @since 1.0 */ ! public class RecordType { /** --- 25,29 ---- * @since 1.0 */ ! public final class RecordType { /** *************** *** 37,41 **** * @throws IllegalArgumentException Throws if the type is null or the value is in use. */ ! protected RecordType(String type) { if(type!=null) --- 40,44 ---- * @throws IllegalArgumentException Throws if the type is null or the value is in use. */ ! private RecordType(String type) { if(type!=null) *************** *** 51,71 **** /** ! * Utility method returns the RecordType object matches to the given value. * * @param type String representing the type of record. * ! * @return Returns the RecordType references matches to the given value, null ! * if it cannot match the given value to any of the available record types. */ 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 ! return null; } --- 54,97 ---- /** ! * Utility method returns the RecordType object matches to the given value. If ! * it doesnt match with the any pre defined record types, it creates and returns ! * a new record type. * * @param type String representing the type of record. * ! * @return Returns the RecordType. ! * ! * @throws IllegalArgumentException Throws if the recordType is null or the value is in use. */ 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 ! return new RecordType(recordType); ! } ! /** ! * Equality will be based on the type. ! * ! * @see java.lang.Object#equals(java.lang.Object) ! */ ! public boolean equals(Object recordType) ! { ! return (recordType!=null) && (this.getClass()==recordType.getClass()) && ! (this.type.equalsIgnoreCase(recordType.toString())); ! } ! ! /** ! * Hashcode of the type will be returned as a hash code. ! * ! * @see java.lang.Object#hashCode() ! */ ! public int hashCode() ! { ! return this.type.hashCode(); } |