[Batchserver-cvs] batchserver/src/org/jmonks/batchserver/io FixedWidthFlatFileFileSpec.java, NONE,
Brought to you by:
suresh_pragada
From: Suresh <sur...@us...> - 2006-06-01 23:51:50
|
Update of /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/io In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv32398 Modified Files: FieldSpec.java FileSpec.java FileSpecException.java FileType.java FixedWidthFlatFileFieldSpec.java FixedWidthFlatFileReader.java FixedWidthFlatFileRecordSpec.java RecordSpec.java RecordType.java Added Files: FixedWidthFlatFileFileSpec.java Log Message: no message Index: FileSpecException.java =================================================================== RCS file: /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/io/FileSpecException.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** FileSpecException.java 30 May 2006 17:09:43 -0000 1.1 --- FileSpecException.java 1 Jun 2006 22:11:41 -0000 1.2 *************** *** 21,27 **** /** Creates a new instance of FileSpecException */ ! public FileSpecException() { } - } --- 21,27 ---- /** Creates a new instance of FileSpecException */ ! public FileSpecException(String message) { + super(message); } } Index: RecordType.java =================================================================== RCS file: /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/io/RecordType.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** RecordType.java 26 May 2006 22:22:26 -0000 1.1 --- RecordType.java 1 Jun 2006 22:11:41 -0000 1.2 *************** *** 25,28 **** --- 25,40 ---- } + 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; + } + public String toString() { Index: FixedWidthFlatFileReader.java =================================================================== RCS file: /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/io/FixedWidthFlatFileReader.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** FixedWidthFlatFileReader.java 26 May 2006 22:22:26 -0000 1.1 --- FixedWidthFlatFileReader.java 1 Jun 2006 22:11:41 -0000 1.2 *************** *** 17,23 **** public class FixedWidthFlatFileReader extends FileReader { public Record getNextRecord() { - if() return null; } --- 17,26 ---- public class FixedWidthFlatFileReader extends FileReader { + public void initialize() + { + + } public Record getNextRecord() { return null; } Index: FixedWidthFlatFileFieldSpec.java =================================================================== RCS file: /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/io/FixedWidthFlatFileFieldSpec.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** FixedWidthFlatFileFieldSpec.java 30 May 2006 17:09:43 -0000 1.1 --- FixedWidthFlatFileFieldSpec.java 1 Jun 2006 22:11:41 -0000 1.2 *************** *** 11,14 **** --- 11,15 ---- package org.jmonks.batchserver.io; + import org.apache.log4j.Logger; import org.w3c.dom.Element; *************** *** 20,34 **** { private int startPosition=0; private int endPosition=0; /** * Creates a new instance of FixedWidthFlatFileFieldSpec */ ! protected FixedWidthFlatFileFieldSpec() { } ! public static FixedWidthFlatFileFieldSpec createFieldSpec(final Element fieldSpecElement) { ! return null; } } --- 21,85 ---- { private int startPosition=0; + private int endPosition=0; + + public static final String START_POSITION_ATTRIB_NAME = "start-pos"; + + public static final String END_POSITION_ATTRIB_NAME = "end-pos"; + + private static Logger logger=Logger.getLogger(FixedWidthFlatFileFieldSpec.class); + /** * Creates a new instance of FixedWidthFlatFileFieldSpec */ ! protected FixedWidthFlatFileFieldSpec(String fieldName,Class fieldType) { + super(fieldName,fieldType); } ! public int getStartPosition() { ! return this.startPosition; ! } ! ! public int getEndPosition() ! { ! return this.endPosition; ! } ! ! public static FieldSpec createFixedWidthFlatFileFieldSpec(final Element fieldSpecElement) ! { ! String fieldName=fieldSpecElement.getAttribute(FieldSpec.FIELD_NAME_ATTRIB_NAME); ! Class fieldType=null; ! try ! { ! fieldType=Class.forName(fieldSpecElement.getAttribute(FieldSpec.FIELD_TYPE_ATTRIB_NAME)); ! } ! catch(ClassNotFoundException exception) ! { ! exception.printStackTrace(); ! logger.fatal("Invalid field type configured for the field name = " + fieldName,exception); ! throw new FileSpecException("Invalid field type configured for the field name = " + fieldName + " Message = " + exception.getMessage()); ! } ! FieldSpec fieldSpec=new FixedWidthFlatFileFieldSpec(fieldName, fieldType); ! ! int startPosition=Integer.parseInt(fieldSpecElement.getAttribute(FixedWidthFlatFileFieldSpec.START_POSITION_ATTRIB_NAME)); ! int endPosition=Integer.parseInt(fieldSpecElement.getAttribute(FixedWidthFlatFileFieldSpec.END_POSITION_ATTRIB_NAME)); ! ! ((FixedWidthFlatFileFieldSpec)fieldSpec).startPosition=startPosition; ! ((FixedWidthFlatFileFieldSpec)fieldSpec).endPosition=endPosition; ! ! return fieldSpec; ! } ! ! public String toString() ! { ! StringBuffer stringValue=new StringBuffer("{FixedWidthFlatFileFieldSpec "); ! stringValue.append("[fieldName = " + super.fieldName + "]"); ! stringValue.append("[fieldType = " + super.fieldType.getName()+ "]"); ! stringValue.append("[startPosition = " + this.startPosition + "]"); ! stringValue.append("[endPosition = " + this.endPosition+ "]"); ! stringValue.append("}"); ! return stringValue.toString(); } } Index: RecordSpec.java =================================================================== RCS file: /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/io/RecordSpec.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** RecordSpec.java 30 May 2006 17:09:43 -0000 1.2 --- RecordSpec.java 1 Jun 2006 22:11:41 -0000 1.3 *************** *** 13,17 **** import java.util.ArrayList; import java.util.List; ! import org.w3c.dom.Element; /** --- 13,17 ---- import java.util.ArrayList; import java.util.List; ! import org.apache.log4j.Logger; /** *************** *** 19,29 **** * @author Suresh Pragada */ ! public class RecordSpec { ! private RecordType recordType=null; ! private List fieldSpecList=null; - /** Creates a new instance of RecordSpec */ protected RecordSpec(RecordType recordType) { --- 19,34 ---- * @author Suresh Pragada */ ! public abstract class RecordSpec { ! protected RecordType recordType=null; ! protected List fieldSpecList=null; ! ! public static final String RECORD_SPEC_TAG_NAME = "record-spec"; ! ! public static final String RECORD_TYPE_ATTRIB_NAME = "record-type"; ! ! private static Logger logger=Logger.getLogger(RecordSpec.class); protected RecordSpec(RecordType recordType) { *************** *** 32,36 **** } ! public boolean addFieldSpec(FieldSpec fieldSpec) { this.fieldSpecList.add(fieldSpec); --- 37,41 ---- } ! protected boolean addFieldSpec(FieldSpec fieldSpec) { this.fieldSpecList.add(fieldSpec); *************** *** 42,58 **** return fieldSpecList; } - - /** - * Constructs Record specification object from the given DOM Element - * representing the <record-spec> tag in file specification. - */ - public static RecordSpec createRecordSpec(final FileType fileType,final Element recordSpecElement) - { - if(fileType==FileType.FIXED_WIDTH_FLAT_FILE) - return FixedWidthFlatFileRecordSpec.createRecordSpec(fileType, recordSpecElement); - else if(fileType==FileType.DELIMITED_FLAT_FILE) - return null; //DelimitedFlatFileRecordSpec.createRecordSpec(fileType, recordSpecElement); - else - return null; - } } --- 47,49 ---- Index: FileSpec.java =================================================================== RCS file: /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/io/FileSpec.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** FileSpec.java 30 May 2006 17:09:43 -0000 1.2 --- FileSpec.java 1 Jun 2006 22:11:41 -0000 1.3 *************** *** 11,17 **** --- 11,28 ---- package org.jmonks.batchserver.io; + import java.io.File; + import java.io.FileInputStream; + import java.io.FileNotFoundException; + import java.io.IOException; + import java.io.InputStream; import java.util.ArrayList; import java.util.List; + import javax.xml.parsers.DocumentBuilder; + import javax.xml.parsers.DocumentBuilderFactory; + import javax.xml.parsers.ParserConfigurationException; import org.apache.log4j.Logger; + import org.w3c.dom.Document; + import org.w3c.dom.Element; + import org.xml.sax.SAXException; /** *************** *** 21,31 **** * @since 1.0 */ ! public class FileSpec { ! private String fileSpecPath=null; ! private FileType fileType=null; ! private List recordSpecList=null; private static Logger logger=Logger.getLogger(FileSpec.class); --- 32,46 ---- * @since 1.0 */ ! public abstract class FileSpec { ! protected String fileSpecPath=null; ! protected FileType fileType=null; ! protected List recordSpecList=null; ! ! public static final String FILE_SPEC_TAG_NAME = "file-spec"; ! ! public static final String FILE_TYPE_ATTRIB_NAME = "file-type"; private static Logger logger=Logger.getLogger(FileSpec.class); *************** *** 34,39 **** * Creates a new instance of FileSpec */ ! protected FileSpec() { recordSpecList=new ArrayList(); } --- 49,55 ---- * Creates a new instance of FileSpec */ ! protected FileSpec(String fileSpecPath,FileType fileType) { + this.fileType=fileType; recordSpecList=new ArrayList(); } *************** *** 46,50 **** * @return Returns true, if record spec is added, false otherwise. */ ! public boolean addRecordSpec(RecordSpec recordSpec) { this.recordSpecList.add(recordSpec); --- 62,66 ---- * @return Returns true, if record spec is added, false otherwise. */ ! protected boolean addRecordSpec(RecordSpec recordSpec) { this.recordSpecList.add(recordSpec); *************** *** 53,61 **** /** ! * Gets the record spec's list. * ! * @return Returns record spec's list. */ ! public List getRecordSpec() { return this.recordSpecList; --- 69,77 ---- /** ! * Gets the record spec's as a list. * ! * @return Returns record spec's as a list. */ ! public List getRecordSpecs() { return this.recordSpecList; *************** *** 78,83 **** public static FileSpec createFileSpec(String fileSpecPath) { ! FileSpec fileSpec=null; ! return null; } } --- 94,146 ---- public static FileSpec createFileSpec(String fileSpecPath) { ! try ! { ! /** ! * Read the file specification to find out the file type and then ! * instantiate the appropirate file spec object. ! */ ! InputStream fileSpecStream=new FileInputStream(new File(fileSpecPath)); ! DocumentBuilderFactory documentBuilderFactory=DocumentBuilderFactory.newInstance(); ! DocumentBuilder documentBuilder=documentBuilderFactory.newDocumentBuilder(); ! Document document=documentBuilder.parse(fileSpecStream); ! Element fileSpecElement=document.getDocumentElement(); ! ! if(FileSpec.FILE_SPEC_TAG_NAME.equals(fileSpecElement.getTagName())) ! { ! FileType fileType=FileType.toFileType(fileSpecElement.getAttribute(FileSpec.FILE_TYPE_ATTRIB_NAME)); ! if(fileType==FileType.FIXED_WIDTH_FLAT_FILE) ! return FixedWidthFlatFileFileSpec.createFixedWidthFlatFileFileSpec(fileSpecPath,fileSpecElement); ! else if(fileType==FileType.DELIMITED_FLAT_FILE) ! return null; //DelimitedFlatFileFileSpec.createDelimitedFlatFileFileSpec(fileSpecPath,fileSpecElement); ! else ! throw new FileSpecException("Configured file type in the file spec is not recognizable."); ! } ! else ! throw new FileSpecException("File spec root element doenst match the expected " + FileSpec.FILE_SPEC_TAG_NAME + " value."); ! } ! catch(FileNotFoundException exception) ! { ! exception.printStackTrace(); ! logger.fatal("Couldnt find the file spec in the given file path = " + fileSpecPath,exception); ! throw new FileSpecException("Cannot find the file = " + fileSpecPath + " Message = " + exception.getMessage()); ! } ! catch(ParserConfigurationException exception) ! { ! exception.printStackTrace(); ! logger.fatal("Couldnt find DOM parser in the classpath to parse the file spec",exception); ! throw new FileSpecException("Couldnt find DOM parser in the classpath to parse the file spec. Message = " + exception.getMessage()); ! } ! catch(SAXException exception) ! { ! exception.printStackTrace(); ! logger.fatal("Parsing exception while parsing the file spec = " + fileSpecPath,exception); ! throw new FileSpecException("Parsing exception while parsing the file spec = " + fileSpecPath + " Message = " + exception.getMessage()); ! } ! catch(IOException exception) ! { ! exception.printStackTrace(); ! logger.fatal("IO exception while parsing the file spec = " + fileSpecPath,exception); ! throw new FileSpecException("IO exception while parsing the file spec = " + fileSpecPath + " Message = " + exception.getMessage()); ! } } } --- NEW FILE: FixedWidthFlatFileFileSpec.java --- /* * FixedWidthFlatFileFileSpec.java * * Created on June 1, 2006, 2: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; import java.util.Iterator; import org.apache.log4j.Logger; import org.w3c.dom.Element; import org.w3c.dom.NodeList; /** * * @author Suresh Pragada */ public class FixedWidthFlatFileFileSpec extends FileSpec { private static Logger logger=Logger.getLogger(FixedWidthFlatFileFileSpec.class); protected FixedWidthFlatFileFileSpec(String fileSpecPath,FileType fileType) { super(fileSpecPath,fileType); } public static FileSpec createFixedWidthFlatFileFileSpec(String fileSpecPath,final Element fileSpecElement) { FileSpec fileSpec=new FixedWidthFlatFileFileSpec(fileSpecPath,FileType.FIXED_WIDTH_FLAT_FILE); NodeList recordSpecList=fileSpecElement.getElementsByTagName(RecordSpec.RECORD_SPEC_TAG_NAME); for(int i=0;i<recordSpecList.getLength();i++) { RecordSpec recordSpec=FixedWidthFlatFileRecordSpec.createFixedWidthFlatFileRecordSpec((Element)recordSpecList.item(i)); fileSpec.addRecordSpec(recordSpec); } return fileSpec; } public String toString() { StringBuffer stringValue=new StringBuffer("{FixedWidthFlatFileFileSpec "); stringValue.append("[fileType = " + super.fileType.toString() + "]"); stringValue.append("[recordSpecList = "); for(Iterator iterator=recordSpecList.iterator();iterator.hasNext();) stringValue.append(((FixedWidthFlatFileRecordSpec)iterator.next()).toString()); stringValue.append("]}"); return stringValue.toString(); } } Index: FileType.java =================================================================== RCS file: /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/io/FileType.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** FileType.java 26 May 2006 22:22:26 -0000 1.1 --- FileType.java 1 Jun 2006 22:11:41 -0000 1.2 *************** *** 24,27 **** --- 24,37 ---- } + public static FileType toFileType(String fileType) + { + if(FileType.FIXED_WIDTH_FLAT_FILE.toString().equalsIgnoreCase(fileType)) + return FileType.FIXED_WIDTH_FLAT_FILE; + else if(FileType.DELIMITED_FLAT_FILE.toString().equalsIgnoreCase(fileType)) + return FileType.DELIMITED_FLAT_FILE; + else + return null; + } + public String toString() { Index: FixedWidthFlatFileRecordSpec.java =================================================================== RCS file: /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/io/FixedWidthFlatFileRecordSpec.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** FixedWidthFlatFileRecordSpec.java 30 May 2006 17:09:43 -0000 1.1 --- FixedWidthFlatFileRecordSpec.java 1 Jun 2006 22:11:41 -0000 1.2 *************** *** 11,15 **** --- 11,17 ---- package org.jmonks.batchserver.io; + import java.util.Iterator; import org.w3c.dom.Element; + import org.w3c.dom.NodeList; /** *************** *** 19,31 **** public class FixedWidthFlatFileRecordSpec extends RecordSpec { /** Creates a new instance of FixedWidthFlatFileRecordSpec */ ! protected FixedWidthFlatFileRecordSpec() { } ! public static RecordSpec createFixedWidthFlatFileRecordSpec(final FileType fileType, final Element recordSpecElement) { ! return null; } } --- 21,64 ---- public class FixedWidthFlatFileRecordSpec extends RecordSpec { + public static final String STARTS_WITH_ATTRIB_NAME = "starts-with"; + + protected String startsWith=null; /** Creates a new instance of FixedWidthFlatFileRecordSpec */ ! protected FixedWidthFlatFileRecordSpec(RecordType recordType) { + super(recordType); } ! public String getStartsWith() { ! return this.startsWith; } + + public static RecordSpec createFixedWidthFlatFileRecordSpec(final Element recordSpecElement) + { + RecordType recordType=RecordType.toRecordType(recordSpecElement.getAttribute(RecordSpec.RECORD_TYPE_ATTRIB_NAME)); + RecordSpec recordSpec=new FixedWidthFlatFileRecordSpec(recordType); + ((FixedWidthFlatFileRecordSpec)recordSpec).startsWith=recordSpecElement.getAttribute(FixedWidthFlatFileRecordSpec.STARTS_WITH_ATTRIB_NAME); + NodeList fieldSpecNodeList=recordSpecElement.getElementsByTagName(FieldSpec.FIELD_SPEC_TAG_NAME); + for(int i=0;i<fieldSpecNodeList.getLength();i++) + { + FieldSpec fieldSpec=FixedWidthFlatFileFieldSpec.createFixedWidthFlatFileFieldSpec((Element)fieldSpecNodeList.item(i)); + recordSpec.addFieldSpec(fieldSpec); + } + return recordSpec; + } + + public String toString() + { + StringBuffer stringValue=new StringBuffer("{FixedWidthFlatFileRecordSpec "); + stringValue.append("[recordType = " + super.recordType.toString() + "]"); + stringValue.append("[startsWith = " + this.startsWith + "]"); + stringValue.append("[fieldSpecList = "); + for(Iterator iterator=fieldSpecList.iterator();iterator.hasNext();) + stringValue.append(((FixedWidthFlatFileFieldSpec)iterator.next()).toString()); + stringValue.append("]}"); + return stringValue.toString(); + } + } Index: FieldSpec.java =================================================================== RCS file: /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/io/FieldSpec.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** FieldSpec.java 30 May 2006 17:09:43 -0000 1.2 --- FieldSpec.java 1 Jun 2006 22:11:41 -0000 1.3 *************** *** 17,25 **** * @author Suresh Pragada */ ! public class FieldSpec { ! private String fieldName=null; ! private Class fieldType=null; /** Creates a new instance of FieldSpec */ --- 17,31 ---- * @author Suresh Pragada */ ! public abstract class FieldSpec { ! protected String fieldName=null; ! protected Class fieldType=null; ! ! public static final String FIELD_SPEC_TAG_NAME = "field-spec"; ! ! public static final String FIELD_NAME_ATTRIB_NAME = "field-name"; ! ! public static final String FIELD_TYPE_ATTRIB_NAME = "field-type"; /** Creates a new instance of FieldSpec */ *************** *** 40,46 **** } - public static FieldSpec createFieldSpec(final FileType fileType,final RecordType recordType,final Element fieldSpecElement) - { - return null; - } } --- 46,48 ---- |