batchserver-cvs Mailing List for Enterprise Batch Server (Page 16)
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-07 22:26:49
|
Update of /cvsroot/batchserver/batchserver/test/org/jmonks/batchserver/io/flat In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv20772/flat Log Message: Directory /cvsroot/batchserver/batchserver/test/org/jmonks/batchserver/io/flat added to the repository |
From: Suresh <sur...@us...> - 2006-06-07 22:26:49
|
Update of /cvsroot/batchserver/batchserver/test/org/jmonks/batchserver/io/xml In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv20800/xml Log Message: Directory /cvsroot/batchserver/batchserver/test/org/jmonks/batchserver/io/xml added to the repository |
From: Suresh <sur...@us...> - 2006-06-07 22:26:41
|
Update of /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/io/flat In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv30008 Modified Files: FixedWidthFlatFileWriter.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.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** FixedWidthFlatFileWriter.java 6 Jun 2006 21:19:58 -0000 1.1 --- FixedWidthFlatFileWriter.java 7 Jun 2006 03:11:35 -0000 1.2 *************** *** 82,86 **** } ! public void writerRecord(WriterRecord writerRecord) { if(this.writer!=null) --- 82,86 ---- } ! public void writeRecord(WriterRecord writerRecord) { if(this.writer!=null) |
From: Suresh <sur...@us...> - 2006-06-07 22:26:38
|
Update of /cvsroot/batchserver/batchserver/test/org/jmonks/batchserver/io/xml In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv30538 Added Files: XMLFileWriterTest.java Log Message: no message --- NEW FILE: XMLFileWriterTest.java --- /* * XMLFileWriterTest.java * JUnit based test * * Created on June 6, 2006, 9:08 PM */ package org.jmonks.batchserver.io.xml; import junit.framework.*; import java.io.IOException; import java.util.HashMap; import java.util.Map; import javax.xml.stream.XMLOutputFactory; import javax.xml.stream.XMLStreamException; import javax.xml.stream.XMLStreamWriter; import org.apache.log4j.Logger; import org.jmonks.batchserver.io.FileParseException; import org.jmonks.batchserver.io.FileSpec; import org.jmonks.batchserver.io.FileWriter; import org.jmonks.batchserver.io.RecordType; import org.jmonks.batchserver.io.WriterRecord; /** * * @author Suresh Pragada */ public class XMLFileWriterTest extends TestCase { public XMLFileWriterTest(String testName) { super(testName); } protected void setUp() throws Exception { } protected void tearDown() throws Exception { } public static Test suite() { TestSuite suite = new TestSuite(XMLFileWriterTest.class); return suite; } /** * Test of writerRecord method, of class org.jmonks.batchserver.io.xml.XMLFileWriter. */ public void testWriterRecord() { System.out.println("testWriterRecord"); FileWriter fileWriter=FileWriter.getFileWriter("C:\\sample-xml-file_2.xml", "C:\\workspace\\workarea\\openapp\\batchserver\\src\\org\\jmonks\\batchserver\\io\\xml\\sample-xml-file-spec.xml"); fileWriter.close(); } } |
From: Suresh <sur...@us...> - 2006-06-07 22:26:37
|
Update of /cvsroot/batchserver/batchserver/test/org/jmonks/batchserver/io/flat In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv30593 Modified Files: FixedWidthFlatFileWriterTest.java Log Message: no message Index: FixedWidthFlatFileWriterTest.java =================================================================== RCS file: /cvsroot/batchserver/batchserver/test/org/jmonks/batchserver/io/flat/FixedWidthFlatFileWriterTest.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** FixedWidthFlatFileWriterTest.java 6 Jun 2006 21:21:17 -0000 1.1 --- FixedWidthFlatFileWriterTest.java 7 Jun 2006 03:12:48 -0000 1.2 *************** *** 52,56 **** /** ! * Test of writerRecord method, of class org.jmonks.batchserver.io.flat.FixedWidthFlatFileWriter. */ public void testWriterRecord() --- 52,56 ---- /** ! * Test of writeRecord method, of class org.jmonks.batchserver.io.flat.FixedWidthFlatFileWriter. */ public void testWriterRecord() *************** *** 65,69 **** rec1.writeField("field3", "VALUE3VALUE3VALUE3"); rec1.writeField("field4", "VALUE4"); ! fileWriter.writerRecord(rec1); WriterRecord rec2=fileWriter.createWriterRecord(RecordType.DETAIL); --- 65,69 ---- rec1.writeField("field3", "VALUE3VALUE3VALUE3"); rec1.writeField("field4", "VALUE4"); ! fileWriter.writeRecord(rec1); WriterRecord rec2=fileWriter.createWriterRecord(RecordType.DETAIL); *************** *** 72,76 **** rec2.writeField("field3", "VALUE3"); rec2.writeField("field4", "VALUE4"); ! fileWriter.writerRecord(rec2); fileWriter.close(); --- 72,76 ---- rec2.writeField("field3", "VALUE3"); rec2.writeField("field4", "VALUE4"); ! fileWriter.writeRecord(rec2); fileWriter.close(); |
From: Suresh <sur...@us...> - 2006-06-07 22:26:34
|
Update of /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/io In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv16349 Modified Files: FileReader.java Log Message: no message Index: FileReader.java =================================================================== RCS file: /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/io/FileReader.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** FileReader.java 3 Jun 2006 13:14:41 -0000 1.6 --- FileReader.java 5 Jun 2006 03:12:43 -0000 1.7 *************** *** 27,30 **** --- 27,32 ---- public abstract ReaderRecord getNextRecord(); + public abstract void close(); + public static FileReader getFileReader(String absoluteFilePath,String absoluteFileSpecPath) { |
From: Suresh <sur...@us...> - 2006-06-07 22:26:32
|
Update of /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/io/xml In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv16808 Modified Files: sample-xml-file.xml XMLFileReader.java Log Message: no message Index: sample-xml-file.xml =================================================================== RCS file: /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/io/xml/sample-xml-file.xml,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** sample-xml-file.xml 3 Jun 2006 13:14:42 -0000 1.1 --- sample-xml-file.xml 5 Jun 2006 03:13:11 -0000 1.2 *************** *** 23,26 **** --- 23,27 ---- </sample-field3> <sample-field4>sample-value1</sample-field4> + <sample-field5> </sample-field5> </sample-detail> <sample-trailor> Index: XMLFileReader.java =================================================================== RCS file: /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/io/xml/XMLFileReader.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** XMLFileReader.java 3 Jun 2006 13:14:42 -0000 1.1 --- XMLFileReader.java 5 Jun 2006 03:13:11 -0000 1.2 *************** *** 11,15 **** --- 11,19 ---- package org.jmonks.batchserver.io.xml; + import java.io.FileNotFoundException; import java.util.Map; + import javax.xml.stream.XMLEventReader; + import javax.xml.stream.XMLInputFactory; + import javax.xml.stream.XMLStreamException; import org.apache.log4j.Logger; import org.jmonks.batchserver.io.*; *************** *** 25,28 **** --- 29,34 ---- protected FileSpec fileSpec=null; + protected XMLEventReader reader=null; + private static Logger logger=Logger.getLogger(XMLFileReader.class); *************** *** 31,34 **** --- 37,57 ---- this.absoluteFilePath=absoluteFilePath; this.fileSpec=fileSpec; + try + { + XMLInputFactory inputFactory=XMLInputFactory.newInstance(); + reader=inputFactory.createXMLEventReader(new java.io.FileReader(this.absoluteFilePath)); + } + catch(FileNotFoundException exception) + { + exception.printStackTrace(); + logger.fatal("File to create the reader cannot be found. Exception Message = " + exception.getMessage(),exception); + throw new FileParseException("File to create the reader cannot be found. Exception Message = " + exception.getMessage()); + } + catch(XMLStreamException exception) + { + exception.printStackTrace(); + logger.fatal("Exception while initializing the xml stream reader. Message = " + exception.getMessage(),exception); + throw new FileParseException("Exception while initializing the xml stream reader. Message = " + exception.getMessage()); + } } *************** *** 38,41 **** --- 61,72 ---- } + public void close() + { + if(this.reader!=null) + { + this.reader.close(); + } + } + public class XMLReaderRecord extends ReaderRecord { |
From: Suresh <sur...@us...> - 2006-06-07 22:26:32
|
Update of /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/io/xml In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv9364 Modified Files: sample-xml-file.xml XMLFileReader.java XMLRecordSpec.java Log Message: no message Index: sample-xml-file.xml =================================================================== RCS file: /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/io/xml/sample-xml-file.xml,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** sample-xml-file.xml 5 Jun 2006 03:13:11 -0000 1.2 --- sample-xml-file.xml 5 Jun 2006 22:40:34 -0000 1.3 *************** *** 22,27 **** <sample-nested-field3>sample-nested-value3</sample-nested-field3> </sample-field3> ! <sample-field4>sample-value1</sample-field4> ! <sample-field5> </sample-field5> </sample-detail> <sample-trailor> --- 22,27 ---- <sample-nested-field3>sample-nested-value3</sample-nested-field3> </sample-field3> ! <sample-field4>sample-value4</sample-field4> ! <sample-field5/> <!-- <sample-field5/> --> </sample-detail> <sample-trailor> Index: XMLFileReader.java =================================================================== RCS file: /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/io/xml/XMLFileReader.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** XMLFileReader.java 5 Jun 2006 03:13:11 -0000 1.2 --- XMLFileReader.java 5 Jun 2006 22:40:34 -0000 1.3 *************** *** 12,19 **** --- 12,28 ---- import java.io.FileNotFoundException; + import java.util.ArrayList; + import java.util.HashMap; + import java.util.Iterator; + import java.util.List; import java.util.Map; + import java.util.Stack; import javax.xml.stream.XMLEventReader; import javax.xml.stream.XMLInputFactory; import javax.xml.stream.XMLStreamException; + import javax.xml.stream.events.Characters; + import javax.xml.stream.events.EndElement; + import javax.xml.stream.events.StartElement; + import javax.xml.stream.events.XMLEvent; import org.apache.log4j.Logger; import org.jmonks.batchserver.io.*; *************** *** 27,33 **** protected String absoluteFilePath=null; ! protected FileSpec fileSpec=null; ! protected XMLEventReader reader=null; private static Logger logger=Logger.getLogger(XMLFileReader.class); --- 36,44 ---- protected String absoluteFilePath=null; ! protected XMLFileSpec fileSpec=null; ! protected XMLEventReader eventReader=null; ! ! protected String xpath=""; private static Logger logger=Logger.getLogger(XMLFileReader.class); *************** *** 35,54 **** public XMLFileReader(String absoluteFilePath,FileSpec fileSpec) { ! this.absoluteFilePath=absoluteFilePath; ! this.fileSpec=fileSpec; try { XMLInputFactory inputFactory=XMLInputFactory.newInstance(); ! reader=inputFactory.createXMLEventReader(new java.io.FileReader(this.absoluteFilePath)); } catch(FileNotFoundException exception) { exception.printStackTrace(); logger.fatal("File to create the reader cannot be found. Exception Message = " + exception.getMessage(),exception); throw new FileParseException("File to create the reader cannot be found. Exception Message = " + exception.getMessage()); ! } catch(XMLStreamException exception) { exception.printStackTrace(); logger.fatal("Exception while initializing the xml stream reader. Message = " + exception.getMessage(),exception); throw new FileParseException("Exception while initializing the xml stream reader. Message = " + exception.getMessage()); --- 46,74 ---- public XMLFileReader(String absoluteFilePath,FileSpec fileSpec) { ! this.absoluteFilePath=absoluteFilePath; ! this.fileSpec=(XMLFileSpec)fileSpec; try { XMLInputFactory inputFactory=XMLInputFactory.newInstance(); ! eventReader=inputFactory.createXMLEventReader(new java.io.FileReader(absoluteFilePath)); ! if(this.validateRootElement()) ! xpath="/"+this.fileSpec.getRootElement(); ! else ! { ! eventReader.close(); ! throw new RuntimeException("Root tag doesnt match."); ! } } catch(FileNotFoundException exception) { exception.printStackTrace(); + this.eventReader=null; logger.fatal("File to create the reader cannot be found. Exception Message = " + exception.getMessage(),exception); throw new FileParseException("File to create the reader cannot be found. Exception Message = " + exception.getMessage()); ! } catch(XMLStreamException exception) { exception.printStackTrace(); + this.eventReader=null; logger.fatal("Exception while initializing the xml stream reader. Message = " + exception.getMessage(),exception); throw new FileParseException("Exception while initializing the xml stream reader. Message = " + exception.getMessage()); *************** *** 58,72 **** public ReaderRecord getNextRecord() { ! return null; } ! public void close() { ! if(this.reader!=null) { ! this.reader.close(); } } public class XMLReaderRecord extends ReaderRecord { --- 78,267 ---- public ReaderRecord getNextRecord() { ! XMLReaderRecord readerRecord=null; ! if(this.eventReader==null) ! return readerRecord; ! else ! { ! try ! { ! while(eventReader.hasNext()) ! { ! XMLEvent event=eventReader.nextEvent(); ! if(event.isStartElement()) ! { ! StartElement startElement=(StartElement)event; ! String startElementName=startElement.getName().getLocalPart(); ! xpath=xpath+"/"+startElementName; ! XMLRecordSpec recordSpec=this.getRecordSpec(); ! if(recordSpec!=null) ! { ! //logger.debug("Found configured " + xpath); ! readerRecord=retrieveRecord(recordSpec,startElementName); ! int index=xpath.lastIndexOf("/"+startElementName); ! if(index!=-1) ! xpath=xpath.substring(0, index); ! break; ! } ! } ! else if(event.isEndElement()) ! { ! EndElement endElement=(EndElement)event; ! String endElementName=endElement.getName().getLocalPart(); ! int index=xpath.lastIndexOf("/"+endElementName); ! if(index!=-1) ! xpath=xpath.substring(0, index); ! } ! } ! } ! catch(XMLStreamException exception) ! { ! exception.printStackTrace(); ! //logger.fatal(); ! throw new RuntimeException("Exception while reading the record. Message = " + exception.getMessage()); ! } ! } ! return readerRecord; } ! public void close() { ! if(this.eventReader!=null) { ! try ! { ! this.eventReader.close(); ! } ! catch(XMLStreamException exception) ! { ! //logger.debug("Streamexception while closing the reader. Message = " + exception.getMessage(),exception); ! } ! finally ! { ! this.eventReader=null; ! } } } + private boolean validateRootElement() + { + boolean valid=false; + try + { + while(eventReader.hasNext()) + { + XMLEvent event=eventReader.nextEvent(); + if(event.isStartElement()) + { + StartElement startElement=(StartElement)event; + if(this.fileSpec.getRootElement().equalsIgnoreCase(startElement.getName().getLocalPart())) + { + valid=true; + break; + } + } + } + } + catch(XMLStreamException exception) + { + exception.printStackTrace(); + logger.fatal("Exception while validating the root element. Message = " + exception.getMessage(),exception); + throw new FileParseException("Exception while validating the root element. Message = " + exception.getMessage()); + } + return valid; + } + + private XMLRecordSpec getRecordSpec() + { + List recordSpecs=this.fileSpec.getRecordSpecs(); + for(Iterator iterator=recordSpecs.iterator();iterator.hasNext();) + { + XMLRecordSpec recordSpec=(XMLRecordSpec)iterator.next(); + if(recordSpec.isMatch(this.xpath)) + return recordSpec; + } + return null; + } + + private XMLReaderRecord retrieveRecord(XMLRecordSpec recordSpec,String recordElement) + { + XMLReaderRecord readerRecord=new XMLReaderRecord(recordSpec.getRecordType()); + Stack elementStack=new Stack(); + boolean isPreviousElementStart=false; + try + { + while(eventReader.hasNext()) + { + XMLEvent nextEvent=eventReader.peek(); + if(nextEvent.isStartElement()) + { + /** + * If the previous element is also a start element, retrieve the + * nested element and returns it as a nested record. + */ + if(isPreviousElementStart) + { + StartElement previousStartElement=(StartElement)elementStack.pop(); + XMLReaderRecord nestedRecord=this.retrieveRecord(recordSpec, previousStartElement.getName().getLocalPart()); + readerRecord.writeElement(previousStartElement.getName().getLocalPart(),nestedRecord); + isPreviousElementStart=false; + } + else + { + StartElement startElement=(StartElement)eventReader.nextEvent(); + isPreviousElementStart=true; + elementStack.push(startElement); + } + } + else if(nextEvent.isEndElement()) + { + EndElement endElement=(EndElement)eventReader.nextEvent(); + isPreviousElementStart=false; + if(recordElement.equalsIgnoreCase(endElement.getName().getLocalPart())) + break; + else + { + /** + * Check the value on top of the stack. If it is start element, no value has + * been provided for this element in the file, otherwise pop the values and start element. + */ + Object topValue=elementStack.peek(); + if(topValue instanceof StartElement) + { + StartElement startElement=(StartElement)elementStack.pop(); + readerRecord.writeElement(startElement.getName().getLocalPart(),""); + } + else + { + Object fieldValue=elementStack.pop(); + StartElement startElement=(StartElement)elementStack.pop(); + readerRecord.writeElement(startElement.getName().getLocalPart(), fieldValue); + } + } + } + else if(nextEvent.isCharacters()) + { + Characters chars=(Characters)eventReader.nextEvent(); + if(!chars.isWhiteSpace()) + { + isPreviousElementStart=false; + elementStack.push(chars.getData()); + } + } + else + { + /** + * Ignore the other events for now. + */ + eventReader.nextEvent(); + } + } + } + catch(XMLStreamException exception) + { + throw new RuntimeException("XMLStream exception while retrieving the record. Message = " + exception.getMessage(), exception); + } + return readerRecord; + } + public class XMLReaderRecord extends ReaderRecord { *************** *** 76,95 **** { super(recordType); } public Object readField(String fieldName) { ! return null; } public Object readElement(String elementName) { ! return null; } ! protected void writeElement(String fieldName, String fieldValue) { ! this.fieldMap.put(fieldName,fieldValue); } ! } } --- 271,316 ---- { super(recordType); + fieldMap=new HashMap(); } public Object readField(String fieldName) { ! return readElement(fieldName); } public Object readElement(String elementName) { ! return fieldMap.get(elementName); } + ! protected void writeElement(String fieldName, Object fieldValue) { ! if(fieldMap.containsKey(fieldName)) ! { ! Object existingFieldValue=fieldMap.remove(fieldName); ! if(existingFieldValue instanceof List) ! { ! List existingFieldValueList=(List)existingFieldValue; ! existingFieldValueList.add(fieldValue); ! fieldMap.put(fieldName, existingFieldValueList); ! } ! else ! { ! List fieldValueList=new ArrayList(); ! fieldValueList.add(existingFieldValue); ! fieldValueList.add(fieldValue); ! fieldMap.put(fieldName,fieldValueList); ! } ! } ! else ! fieldMap.put(fieldName,fieldValue); } ! ! public String toString() ! { ! return this.fieldMap.toString(); ! } ! } ! } Index: XMLRecordSpec.java =================================================================== RCS file: /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/io/xml/XMLRecordSpec.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** XMLRecordSpec.java 3 Jun 2006 13:14:42 -0000 1.1 --- XMLRecordSpec.java 5 Jun 2006 22:40:34 -0000 1.2 *************** *** 37,40 **** --- 37,47 ---- return this.recordXPath; } + + public boolean isMatch(String xpath) + { + if(xpath==null) + throw new IllegalArgumentException("xpath cannot be null to match XML record spec."); + return xpath.equalsIgnoreCase(this.recordXPath); + } public static RecordSpec createXMLRecordSpec(final Element recordSpecElement) |
Update of /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/io/xml In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv14982/xml Added Files: sample-xml-file-spec.xml sample-xml-file.xml XMLFileReader.java XMLFileSpec.java XMLRecordSpec.java Log Message: no message --- NEW FILE: sample-xml-file-spec.xml --- <?xml version="1.0" encoding="UTF-8"?> <file-spec file-type="xml" root-element="sample-root"> <record-spec record-type="header" record-xpath="/sample-root/sample-header"/> <record-spec record-type="detail" record-xpath="/sample-root/sample-detail"/> <record-spec record-type="trailor" record-xpath="/sample-root/sample-trailor"/> </file-spec> --- NEW FILE: sample-xml-file.xml --- <?xml version="1.0" encoding="UTF-8"?> <sample-root> <sample-header> <time-stamp>20060602152356</time-stamp> </sample-header> <sample-detail> <sample-field1>sample-value1</sample-field1> <sample-field2>sample-value1</sample-field2> <sample-field3> <sample-nested-field1>sample-nested-value1</sample-nested-field1> <sample-nested-field1>sample-nested-value2</sample-nested-field1> <sample-nested-field3>sample-nested-value3</sample-nested-field3> </sample-field3> <sample-field4>sample-value1</sample-field4> </sample-detail> <sample-detail> <sample-field1>sample-value1</sample-field1> <sample-field2>sample-value1</sample-field2> <sample-field3> <sample-nested-field1>sample-nested-value1</sample-nested-field1> <sample-nested-field1>sample-nested-value2</sample-nested-field1> <sample-nested-field3>sample-nested-value3</sample-nested-field3> </sample-field3> <sample-field4>sample-value1</sample-field4> </sample-detail> <sample-trailor> <record-count>10000</record-count> </sample-trailor> </sample-root> --- NEW FILE: XMLFileReader.java --- /* * XMLFileReader.java * * Created on June 2, 2006, 11:05 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; import java.util.Map; import org.apache.log4j.Logger; import org.jmonks.batchserver.io.*; /** * * @author Suresh Pragada */ public class XMLFileReader extends FileReader { protected String absoluteFilePath=null; protected FileSpec fileSpec=null; private static Logger logger=Logger.getLogger(XMLFileReader.class); public XMLFileReader(String absoluteFilePath,FileSpec fileSpec) { this.absoluteFilePath=absoluteFilePath; this.fileSpec=fileSpec; } public ReaderRecord getNextRecord() { return null; } public class XMLReaderRecord extends ReaderRecord { private Map fieldMap=null; private XMLReaderRecord(RecordType recordType) { super(recordType); } public Object readField(String fieldName) { return null; } public Object readElement(String elementName) { return null; } protected void writeElement(String fieldName, String fieldValue) { this.fieldMap.put(fieldName,fieldValue); } } } --- NEW FILE: XMLFileSpec.java --- /* * XMLFileSpec.java * * Created on June 2, 2006, 10:42 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; import java.util.Iterator; import org.apache.log4j.Logger; import org.w3c.dom.Element; import org.w3c.dom.NodeList; import org.jmonks.batchserver.io.*; /** * * @author Suresh Pragada */ public class XMLFileSpec extends FileSpec { protected String rootElement=null; public static final String ROOT_ELEMENT_ATTRIB_NAME = "root-element"; private static Logger logger=Logger.getLogger(XMLFileSpec.class); public XMLFileSpec(String fileSpecPath,FileType fileType) { super(fileSpecPath,fileType); } public String getRootElement() { return this.rootElement; } public static FileSpec createXMLFileSpec(final String fileSpecPath,final Element fileSpecElement) { XMLFileSpec fileSpec=new XMLFileSpec(fileSpecPath,FileType.XML_FILE); String rootElement=fileSpecElement.getAttribute(XMLFileSpec.ROOT_ELEMENT_ATTRIB_NAME); if(rootElement!=null && !"".equals(rootElement.trim())) fileSpec.rootElement=rootElement; else throw new FileSpecException("XML FileSpec requires attribute root-element in element file-spec."); NodeList recordSpecNodeList=fileSpecElement.getElementsByTagName(RecordSpec.RECORD_SPEC_TAG_NAME); for(int i=0;i<recordSpecNodeList.getLength();i++) { RecordSpec recordSpec=XMLRecordSpec.createXMLRecordSpec((Element)recordSpecNodeList.item(i)); fileSpec.addRecordSpec(recordSpec); } return fileSpec; } public String toString() { StringBuffer stringValue=new StringBuffer("{XMLFileSpec "); stringValue.append("[fileType = " + super.fileType.toString() + "]"); stringValue.append("[rootElement = " + this.rootElement + "]"); stringValue.append("[recordSpecList = "); for(Iterator iterator=recordSpecList.iterator();iterator.hasNext();) stringValue.append(((XMLRecordSpec)iterator.next()).toString()); stringValue.append("]}"); return stringValue.toString(); } } --- NEW FILE: XMLRecordSpec.java --- /* * XMLRecordSpec.java * * Created on June 2, 2006, 10:54 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; import org.apache.log4j.Logger; import org.w3c.dom.Element; import org.w3c.dom.NodeList; import org.jmonks.batchserver.io.*; /** * * @author Suresh Pragada */ public class XMLRecordSpec extends RecordSpec { protected String recordXPath=null; public static final String RECORD_XPATH_ATTRIB_NAME = "record-xpath"; private static Logger logger=Logger.getLogger(XMLRecordSpec.class); public XMLRecordSpec(RecordType recordType) { super(recordType); } public String getRecordXPath() { return this.recordXPath; } public static RecordSpec createXMLRecordSpec(final Element recordSpecElement) { RecordType recordType=RecordType.toRecordType(recordSpecElement.getAttribute(RecordSpec.RECORD_TYPE_ATTRIB_NAME)); XMLRecordSpec recordSpec=new XMLRecordSpec(recordType); String recordXPath=recordSpecElement.getAttribute(XMLRecordSpec.RECORD_XPATH_ATTRIB_NAME); if(recordXPath!=null && !"".equals(recordXPath.trim())) recordSpec.recordXPath=recordXPath.trim(); else throw new FileSpecException("Record Spec in XML File Spec should have attribute record-xpath."); return (RecordSpec)recordSpec; } public String toString() { StringBuffer stringValue=new StringBuffer("{XMLRecordSpec "); stringValue.append("[recordType = " + super.recordType.toString() + "]"); stringValue.append("[recordXPath = " + this.recordXPath + "]"); stringValue.append("}"); return stringValue.toString(); } } |
Update of /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/io In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv14982 Modified Files: FileReader.java FileSpec.java Removed Files: biller-file-spec.xml FixedWidthFlatFileFieldSpec.java FixedWidthFlatFileFileSpec.java FixedWidthFlatFileReader.java FixedWidthFlatFileRecordSpec.java payment-file-spec.xml payment.pmt XMLFileReader.java XMLFileSpec.java XMLRecordSpec.java Log Message: no message --- XMLFileSpec.java DELETED --- --- payment.pmt DELETED --- --- FixedWidthFlatFileFieldSpec.java DELETED --- --- FixedWidthFlatFileReader.java DELETED --- --- XMLFileReader.java DELETED --- --- biller-file-spec.xml DELETED --- Index: FileReader.java =================================================================== RCS file: /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/io/FileReader.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** FileReader.java 3 Jun 2006 04:20:15 -0000 1.5 --- FileReader.java 3 Jun 2006 13:14:41 -0000 1.6 *************** *** 12,15 **** --- 12,17 ---- import java.io.File; + import org.jmonks.batchserver.io.xml.XMLFileReader; + import org.jmonks.batchserver.io.flat.FixedWidthFlatFileReader; Index: FileSpec.java =================================================================== RCS file: /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/io/FileSpec.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** FileSpec.java 3 Jun 2006 04:20:15 -0000 1.4 --- FileSpec.java 3 Jun 2006 13:14:41 -0000 1.5 *************** *** 25,28 **** --- 25,30 ---- import org.w3c.dom.Element; import org.xml.sax.SAXException; + import org.jmonks.batchserver.io.xml.XMLFileSpec; + import org.jmonks.batchserver.io.flat.FixedWidthFlatFileFileSpec; /** --- FixedWidthFlatFileFileSpec.java DELETED --- --- FixedWidthFlatFileRecordSpec.java DELETED --- --- XMLRecordSpec.java DELETED --- --- payment-file-spec.xml DELETED --- |
From: Suresh <sur...@us...> - 2006-06-03 13:14:47
|
Update of /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/io/flat In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv14982/flat Added Files: FixedWidthFlatFileFieldSpec.java FixedWidthFlatFileFileSpec.java FixedWidthFlatFileReader.java FixedWidthFlatFileRecordSpec.java sample-fixed-width-file-spec.xml sample-fixed-width-file.dat Log Message: no message --- NEW FILE: FixedWidthFlatFileReader.java --- /* * FixedWidthFlatFileReader.java * * Created on May 26, 2006, 2:15 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.flat; import java.io.BufferedReader; import java.io.FileNotFoundException; import java.io.IOException; 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.*; /** * * @author Suresh Pragada */ public class FixedWidthFlatFileReader extends FileReader { protected String absoluteFilePath=null; protected FileSpec fileSpec=null; private BufferedReader reader=null; private static Logger logger=Logger.getLogger(FixedWidthFlatFileReader.class); public FixedWidthFlatFileReader(String absoluteFilePath,FileSpec fileSpec) { this.absoluteFilePath=absoluteFilePath; this.fileSpec=fileSpec; try { reader=new BufferedReader(new java.io.FileReader(this.absoluteFilePath)); } catch(FileNotFoundException exception) { reader=null; exception.printStackTrace(); logger.fatal("File could not be found to create the reader. Message = " + exception.getMessage(),exception); throw new FileParseException("File could not be found to create the reader. Message = " + exception.getMessage()); } catch(IOException exception) { reader=null; exception.printStackTrace(); logger.fatal("IO Exception while initializing the file reader. Message = " + exception.getMessage(),exception); throw new FileParseException("IO Exception while initializing the file reader. Message = " + exception.getMessage()); } } public ReaderRecord getNextRecord() { if(this.reader==null) return null; else { try { String recordString=this.reader.readLine(); if(recordString==null) { this.reader.close(); this.reader=null; return null; } else { ReaderRecord record=this.parseRecord(recordString); return record; } } catch(IOException exception) { logger.info("IOException while retrieving the next record. Message = " + exception.getMessage(),exception); throw new FileParseException("IO Exception while retrieving the next record. Message = " + exception.getMessage()); } } } private ReaderRecord parseRecord(String recordString) { FixedWidthFlatFileReaderRecord record=null; List recordSpecList=this.fileSpec.getRecordSpecs(); for(Iterator recordSpecIterator=recordSpecList.iterator();recordSpecIterator.hasNext();) { FixedWidthFlatFileRecordSpec recordSpec=(FixedWidthFlatFileRecordSpec)recordSpecIterator.next(); if(recordSpec.isMatch(recordString)) { List fieldSpecList=recordSpec.getFieldSpecs(); record=new FixedWidthFlatFileReaderRecord(recordSpec.getRecordType(),fieldSpecList.size()); for(Iterator fieldSpecIterator=fieldSpecList.iterator();fieldSpecIterator.hasNext();) { FixedWidthFlatFileFieldSpec fieldSpec=(FixedWidthFlatFileFieldSpec)fieldSpecIterator.next(); String fieldValue=null; try { fieldValue=recordString.substring(fieldSpec.getStartPosition(),fieldSpec.getEndPosition()); } catch(IndexOutOfBoundsException exception) { exception.printStackTrace(); logger.fatal("Could not retrieve the field " + fieldSpec.getFieldName() + " from the record string " + recordString + " from the positions start = " + fieldSpec.getStartPosition() + " end = " + fieldSpec.getEndPosition()); } record.writeField(fieldSpec.getFieldName(),fieldValue); } break; } if(!recordSpecIterator.hasNext()) throw new FileParseException("Record " + recordString + " cannot be matched with any configured record specs."); } return record; } public class FixedWidthFlatFileReaderRecord extends ReaderRecord { private Map fieldMap=null; private FixedWidthFlatFileReaderRecord(RecordType recordType,int fieldCount) { super(recordType); fieldMap=new HashMap(fieldCount); } public Object readField(String fieldName) { return this.fieldMap.get(fieldName); } private void writeField(String fieldName,String fieldValue) { this.fieldMap.put(fieldName,fieldValue); } } } --- NEW FILE: FixedWidthFlatFileFieldSpec.java --- /* * FixedWidthFlatFileFieldSpec.java * * Created on May 26, 2006, 2:43 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.flat; import org.apache.log4j.Logger; import org.w3c.dom.Element; import org.jmonks.batchserver.io.*; /** * * @author Suresh Pragada */ public class FixedWidthFlatFileFieldSpec extends FieldSpec { 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) { super(fieldName); } 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); FieldSpec fieldSpec=new FixedWidthFlatFileFieldSpec(fieldName); 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("[startPosition = " + this.startPosition + "]"); stringValue.append("[endPosition = " + this.endPosition+ "]"); stringValue.append("}"); return stringValue.toString(); } } --- 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.flat; import java.util.Iterator; import org.apache.log4j.Logger; import org.w3c.dom.Element; import org.w3c.dom.NodeList; import org.jmonks.batchserver.io.*; /** * * @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(final String fileSpecPath,final Element fileSpecElement) { FixedWidthFlatFileFileSpec fileSpec=new FixedWidthFlatFileFileSpec(fileSpecPath,FileType.FIXED_WIDTH_FLAT_FILE); NodeList recordSpecNodeList=fileSpecElement.getElementsByTagName(RecordSpec.RECORD_SPEC_TAG_NAME); for(int i=0;i<recordSpecNodeList.getLength();i++) { RecordSpec recordSpec=FixedWidthFlatFileRecordSpec.createFixedWidthFlatFileRecordSpec((Element)recordSpecNodeList.item(i)); fileSpec.addRecordSpec(recordSpec); } return (FileSpec)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(); } } --- NEW FILE: FixedWidthFlatFileRecordSpec.java --- /* * FixedWidthFlatFileRecordSpec.java * * Created on May 26, 2006, 11:33 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.flat; import java.util.Iterator; import org.w3c.dom.Element; import org.w3c.dom.NodeList; import org.jmonks.batchserver.io.*; /** * * @author Suresh Pragada */ 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 boolean isMatch(String recordString) { if(recordString==null) throw new IllegalArgumentException("Record string cannot be null to match record spec."); return recordString.startsWith(this.startsWith); } public static RecordSpec createFixedWidthFlatFileRecordSpec(final Element recordSpecElement) { RecordType recordType=RecordType.toRecordType(recordSpecElement.getAttribute(RecordSpec.RECORD_TYPE_ATTRIB_NAME)); FixedWidthFlatFileRecordSpec recordSpec=new FixedWidthFlatFileRecordSpec(recordType); String startsWith=recordSpecElement.getAttribute(FixedWidthFlatFileRecordSpec.STARTS_WITH_ATTRIB_NAME); if(startsWith!=null && !"".equals(startsWith.trim())) recordSpec.startsWith=startsWith.trim(); else throw new FileSpecException("Record Spec in Fixed Width File Spec should have starts-with attribute."); 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)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(); } } --- NEW FILE: sample-fixed-width-file-spec.xml --- <?xml version="1.0" encoding="UTF-8"?> <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"/> <field-spec field-name="field3" start-pos="22" end-pos="31"/> <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> <!-- <record-spec record-type="detail" delimiter="|"> <field-spec field-name="pmtId" index="1"/> </record-spec> --> </file-spec> --- NEW FILE: sample-fixed-width-file.dat --- 120060526 512345678910000012.0034343434347878787878 512345678920000013.0034343434347878787878 512345678930000014.0034343434347878787878 512345678940000015.0034343434347878787878 512345678950000016.0034343434347878787878 60000000.00 |
From: Suresh <sur...@us...> - 2006-06-03 13:13:41
|
Update of /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/io/xml In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv14527/xml Log Message: Directory /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/io/xml added to the repository |
From: Suresh <sur...@us...> - 2006-06-03 13:13:26
|
Update of /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/io/flat In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv14487/flat Log Message: Directory /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/io/flat added to the repository |
From: Suresh <sur...@us...> - 2006-06-03 04:20:18
|
Update of /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/io In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv25505 Modified Files: FileReader.java FileSpec.java FileType.java FixedWidthFlatFileFileSpec.java FixedWidthFlatFileReader.java FixedWidthFlatFileRecordSpec.java Added Files: XMLFileReader.java XMLFileSpec.java XMLRecordSpec.java Log Message: no message --- NEW FILE: XMLFileSpec.java --- /* * XMLFileSpec.java * * Created on June 2, 2006, 10:42 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 XMLFileSpec extends FileSpec { protected String rootElement=null; public static final String ROOT_ELEMENT_ATTRIB_NAME = "root-element"; private static Logger logger=Logger.getLogger(XMLFileSpec.class); public XMLFileSpec(String fileSpecPath,FileType fileType) { super(fileSpecPath,fileType); } public String getRootElement() { return this.rootElement; } public static FileSpec createXMLFileSpec(final String fileSpecPath,final Element fileSpecElement) { XMLFileSpec fileSpec=new XMLFileSpec(fileSpecPath,FileType.XML_FILE); String rootElement=fileSpecElement.getAttribute(XMLFileSpec.ROOT_ELEMENT_ATTRIB_NAME); if(rootElement!=null && !"".equals(rootElement.trim())) fileSpec.rootElement=rootElement; else throw new FileSpecException("XML FileSpec requires attribute root-element in element file-spec."); NodeList recordSpecNodeList=fileSpecElement.getElementsByTagName(RecordSpec.RECORD_SPEC_TAG_NAME); for(int i=0;i<recordSpecNodeList.getLength();i++) { RecordSpec recordSpec=XMLRecordSpec.createXMLRecordSpec((Element)recordSpecNodeList.item(i)); fileSpec.addRecordSpec(recordSpec); } return fileSpec; } public String toString() { StringBuffer stringValue=new StringBuffer("{XMLFileSpec "); stringValue.append("[fileType = " + super.fileType.toString() + "]"); stringValue.append("[rootElement = " + this.rootElement + "]"); stringValue.append("[recordSpecList = "); for(Iterator iterator=recordSpecList.iterator();iterator.hasNext();) stringValue.append(((XMLRecordSpec)iterator.next()).toString()); stringValue.append("]}"); return stringValue.toString(); } } Index: FileReader.java =================================================================== RCS file: /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/io/FileReader.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** FileReader.java 2 Jun 2006 22:27:22 -0000 1.4 --- FileReader.java 3 Jun 2006 04:20:15 -0000 1.5 *************** *** 46,49 **** --- 46,53 ---- return null; // Create Demlited Flat file reader. } + else if(fileSpec.getFileType()==FileType.XML_FILE) + { + return new XMLFileReader(absoluteFilePath,fileSpec); + } else { Index: FixedWidthFlatFileReader.java =================================================================== RCS file: /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/io/FixedWidthFlatFileReader.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** FixedWidthFlatFileReader.java 2 Jun 2006 22:27:22 -0000 1.5 --- FixedWidthFlatFileReader.java 3 Jun 2006 04:20:15 -0000 1.6 *************** *** 127,131 **** private Map fieldMap=null; ! protected FixedWidthFlatFileReaderRecord(RecordType recordType,int fieldCount) { super(recordType); --- 127,131 ---- private Map fieldMap=null; ! private FixedWidthFlatFileReaderRecord(RecordType recordType,int fieldCount) { super(recordType); *************** *** 138,142 **** } ! protected void writeField(String fieldName,String fieldValue) { this.fieldMap.put(fieldName,fieldValue); --- 138,142 ---- } ! private void writeField(String fieldName,String fieldValue) { this.fieldMap.put(fieldName,fieldValue); --- NEW FILE: XMLFileReader.java --- /* * XMLFileReader.java * * Created on June 2, 2006, 11:05 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 org.apache.log4j.Logger; /** * * @author Suresh Pragada */ public class XMLFileReader extends FileReader { protected String absoluteFilePath=null; protected FileSpec fileSpec=null; private static Logger logger=Logger.getLogger(XMLFileReader.class); public XMLFileReader(String absoluteFilePath,FileSpec fileSpec) { this.absoluteFilePath=absoluteFilePath; this.fileSpec=fileSpec; } public ReaderRecord getNextRecord() { return null; } public class XMLReaderRecord extends ReaderRecord { private XMLReaderRecord(RecordType recordType) { super(recordType); } public Object readField(String fieldName) { return null; } public String readElement(String elementName) { return null; } } } Index: FileSpec.java =================================================================== RCS file: /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/io/FileSpec.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** FileSpec.java 1 Jun 2006 22:11:41 -0000 1.3 --- FileSpec.java 3 Jun 2006 04:20:15 -0000 1.4 *************** *** 51,54 **** --- 51,55 ---- protected FileSpec(String fileSpecPath,FileType fileType) { + this.fileSpecPath=fileSpecPath; this.fileType=fileType; recordSpecList=new ArrayList(); *************** *** 113,116 **** --- 114,119 ---- else if(fileType==FileType.DELIMITED_FLAT_FILE) return null; //DelimitedFlatFileFileSpec.createDelimitedFlatFileFileSpec(fileSpecPath,fileSpecElement); + else if(fileType==FileType.XML_FILE) + return XMLFileSpec.createXMLFileSpec(fileSpecPath,fileSpecElement); else throw new FileSpecException("Configured file type in the file spec is not recognizable."); Index: FixedWidthFlatFileFileSpec.java =================================================================== RCS file: /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/io/FixedWidthFlatFileFileSpec.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** FixedWidthFlatFileFileSpec.java 1 Jun 2006 22:11:41 -0000 1.1 --- FixedWidthFlatFileFileSpec.java 3 Jun 2006 04:20:15 -0000 1.2 *************** *** 29,42 **** } ! 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; } --- 29,42 ---- } ! public static FileSpec createFixedWidthFlatFileFileSpec(final String fileSpecPath,final Element fileSpecElement) { ! FixedWidthFlatFileFileSpec fileSpec=new FixedWidthFlatFileFileSpec(fileSpecPath,FileType.FIXED_WIDTH_FLAT_FILE); ! NodeList recordSpecNodeList=fileSpecElement.getElementsByTagName(RecordSpec.RECORD_SPEC_TAG_NAME); ! for(int i=0;i<recordSpecNodeList.getLength();i++) { ! RecordSpec recordSpec=FixedWidthFlatFileRecordSpec.createFixedWidthFlatFileRecordSpec((Element)recordSpecNodeList.item(i)); fileSpec.addRecordSpec(recordSpec); } ! return (FileSpec)fileSpec; } Index: FileType.java =================================================================== RCS file: /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/io/FileType.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** FileType.java 1 Jun 2006 22:11:41 -0000 1.2 --- FileType.java 3 Jun 2006 04:20:15 -0000 1.3 *************** *** 30,33 **** --- 30,35 ---- else if(FileType.DELIMITED_FLAT_FILE.toString().equalsIgnoreCase(fileType)) return FileType.DELIMITED_FLAT_FILE; + else if(FileType.XML_FILE.toString().equalsIgnoreCase(fileType)) + return FileType.XML_FILE; else return null; *************** *** 41,43 **** --- 43,46 ---- public static final FileType FIXED_WIDTH_FLAT_FILE = new FileType("fixed-width-flat"); public static final FileType DELIMITED_FLAT_FILE = new FileType("delimited-flat"); + public static final FileType XML_FILE = new FileType("xml"); } Index: FixedWidthFlatFileRecordSpec.java =================================================================== RCS file: /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/io/FixedWidthFlatFileRecordSpec.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** FixedWidthFlatFileRecordSpec.java 2 Jun 2006 22:27:22 -0000 1.4 --- FixedWidthFlatFileRecordSpec.java 3 Jun 2006 04:20:15 -0000 1.5 *************** *** 46,53 **** { RecordType recordType=RecordType.toRecordType(recordSpecElement.getAttribute(RecordSpec.RECORD_TYPE_ATTRIB_NAME)); ! RecordSpec recordSpec=new FixedWidthFlatFileRecordSpec(recordType); String startsWith=recordSpecElement.getAttribute(FixedWidthFlatFileRecordSpec.STARTS_WITH_ATTRIB_NAME); if(startsWith!=null && !"".equals(startsWith.trim())) ! ((FixedWidthFlatFileRecordSpec)recordSpec).startsWith=startsWith.trim(); else throw new FileSpecException("Record Spec in Fixed Width File Spec should have starts-with attribute."); --- 46,53 ---- { RecordType recordType=RecordType.toRecordType(recordSpecElement.getAttribute(RecordSpec.RECORD_TYPE_ATTRIB_NAME)); ! FixedWidthFlatFileRecordSpec recordSpec=new FixedWidthFlatFileRecordSpec(recordType); String startsWith=recordSpecElement.getAttribute(FixedWidthFlatFileRecordSpec.STARTS_WITH_ATTRIB_NAME); if(startsWith!=null && !"".equals(startsWith.trim())) ! recordSpec.startsWith=startsWith.trim(); else throw new FileSpecException("Record Spec in Fixed Width File Spec should have starts-with attribute."); *************** *** 58,62 **** recordSpec.addFieldSpec(fieldSpec); } ! return recordSpec; } --- 58,62 ---- recordSpec.addFieldSpec(fieldSpec); } ! return (RecordSpec)recordSpec; } --- NEW FILE: XMLRecordSpec.java --- /* * XMLRecordSpec.java * * Created on June 2, 2006, 10:54 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 org.apache.log4j.Logger; import org.w3c.dom.Element; import org.w3c.dom.NodeList; /** * * @author Suresh Pragada */ public class XMLRecordSpec extends RecordSpec { protected String recordXPath=null; public static final String RECORD_XPATH_ATTRIB_NAME = "record-xpath"; private static Logger logger=Logger.getLogger(XMLRecordSpec.class); public XMLRecordSpec(RecordType recordType) { super(recordType); } public String getRecordXPath() { return this.recordXPath; } public static RecordSpec createXMLRecordSpec(final Element recordSpecElement) { RecordType recordType=RecordType.toRecordType(recordSpecElement.getAttribute(RecordSpec.RECORD_TYPE_ATTRIB_NAME)); XMLRecordSpec recordSpec=new XMLRecordSpec(recordType); String recordXPath=recordSpecElement.getAttribute(XMLRecordSpec.RECORD_XPATH_ATTRIB_NAME); if(recordXPath!=null && !"".equals(recordXPath.trim())) recordSpec.recordXPath=recordXPath.trim(); else throw new FileSpecException("Record Spec in XML File Spec should have attribute record-xpath."); return (RecordSpec)recordSpec; } public String toString() { StringBuffer stringValue=new StringBuffer("{XMLRecordSpec "); stringValue.append("[recordType = " + super.recordType.toString() + "]"); stringValue.append("[recordXPath = " + this.recordXPath + "]"); stringValue.append("}"); return stringValue.toString(); } } |
Update of /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/io In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv13799 Modified Files: FileReader.java FixedWidthFlatFileReader.java FixedWidthFlatFileRecordSpec.java Added Files: biller-file-spec.xml Log Message: no message Index: FileReader.java =================================================================== RCS file: /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/io/FileReader.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** FileReader.java 2 Jun 2006 21:02:06 -0000 1.3 --- FileReader.java 2 Jun 2006 22:27:22 -0000 1.4 *************** *** 35,39 **** throw new IllegalArgumentException("Absolute file path to read the file spec cannot be null."); else if(!(new File(absoluteFileSpecPath).exists() && new File(absoluteFileSpecPath).isFile())) ! throw new IllegalArgumentException("Absolute file path to read the file spec should exist and should be a file. Given absolute file spec path = " + absoluteFilePath); FileSpec fileSpec=FileSpec.createFileSpec(absoluteFileSpecPath); --- 35,39 ---- throw new IllegalArgumentException("Absolute file path to read the file spec cannot be null."); else if(!(new File(absoluteFileSpecPath).exists() && new File(absoluteFileSpecPath).isFile())) ! throw new IllegalArgumentException("Absolute file path to read the file spec should exist and should be a file. Given absolute file spec path = " + absoluteFileSpecPath); FileSpec fileSpec=FileSpec.createFileSpec(absoluteFileSpecPath); Index: FixedWidthFlatFileReader.java =================================================================== RCS file: /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/io/FixedWidthFlatFileReader.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** FixedWidthFlatFileReader.java 2 Jun 2006 21:02:06 -0000 1.4 --- FixedWidthFlatFileReader.java 2 Jun 2006 22:27:22 -0000 1.5 *************** *** 12,19 **** import java.io.BufferedReader; ! import java.io.File; ! import java.io.FileInputStream; import java.io.IOException; - import java.io.InputStreamReader; import java.util.HashMap; import java.util.Iterator; --- 12,17 ---- import java.io.BufferedReader; ! import java.io.FileNotFoundException; import java.io.IOException; import java.util.HashMap; import java.util.Iterator; *************** *** 43,47 **** try { ! reader=new BufferedReader(new InputStreamReader(new FileInputStream(new File(this.absoluteFilePath)))); } catch(IOException exception) --- 41,52 ---- try { ! reader=new BufferedReader(new java.io.FileReader(this.absoluteFilePath)); ! } ! catch(FileNotFoundException exception) ! { ! reader=null; ! exception.printStackTrace(); ! logger.fatal("File could not be found to create the reader. Message = " + exception.getMessage(),exception); ! throw new FileParseException("File could not be found to create the reader. Message = " + exception.getMessage()); } catch(IOException exception) *************** *** 65,68 **** --- 70,74 ---- if(recordString==null) { + this.reader.close(); this.reader=null; return null; --- NEW FILE: biller-file-spec.xml --- <?xml version="1.0" encoding="UTF-8"?> <file-spec file-type="xml" root-element="biller"> <record-spec record-type="header" element-xpath="/biller/header"/> <record-spec record-type="detail" element-xpath="/biller/billerinfo"/> <record-spec record-type="trailor" element-xpath="/biller/trailor"/> </file-spec> Index: FixedWidthFlatFileRecordSpec.java =================================================================== RCS file: /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/io/FixedWidthFlatFileRecordSpec.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** FixedWidthFlatFileRecordSpec.java 2 Jun 2006 21:02:06 -0000 1.3 --- FixedWidthFlatFileRecordSpec.java 2 Jun 2006 22:27:22 -0000 1.4 *************** *** 48,52 **** RecordSpec recordSpec=new FixedWidthFlatFileRecordSpec(recordType); String startsWith=recordSpecElement.getAttribute(FixedWidthFlatFileRecordSpec.STARTS_WITH_ATTRIB_NAME); ! if(startsWith!=null && startsWith.trim().equals("")) ((FixedWidthFlatFileRecordSpec)recordSpec).startsWith=startsWith.trim(); else --- 48,52 ---- RecordSpec recordSpec=new FixedWidthFlatFileRecordSpec(recordType); String startsWith=recordSpecElement.getAttribute(FixedWidthFlatFileRecordSpec.STARTS_WITH_ATTRIB_NAME); ! if(startsWith!=null && !"".equals(startsWith.trim())) ((FixedWidthFlatFileRecordSpec)recordSpec).startsWith=startsWith.trim(); else |
From: Suresh <sur...@us...> - 2006-06-02 21:02:13
|
Update of /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/io In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv8745 Modified Files: FileParseException.java FileReader.java FixedWidthFlatFileReader.java FixedWidthFlatFileRecordSpec.java Record.java RecordSpec.java Added Files: ReaderRecord.java WriterRecord.java Removed Files: FileIO.java Log Message: no message Index: FileParseException.java =================================================================== RCS file: /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/io/FileParseException.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** FileParseException.java 30 May 2006 17:09:43 -0000 1.1 --- FileParseException.java 2 Jun 2006 21:02:06 -0000 1.2 *************** *** 19,24 **** /** Creates a new instance of FileParseException */ ! public FileParseException() { } --- 19,25 ---- /** Creates a new instance of FileParseException */ ! public FileParseException(String message) { + super(message); } Index: Record.java =================================================================== RCS file: /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/io/Record.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** Record.java 26 May 2006 22:22:26 -0000 1.1 --- Record.java 2 Jun 2006 21:02:06 -0000 1.2 *************** *** 21,34 **** * @since 1.0 */ ! public class Record { private RecordType recordType=null; - private Map fieldMap=null; /** Creates a new instance of Record */ public Record(RecordType recordType) { this.recordType=recordType; - fieldMap=new HashMap(); } --- 21,32 ---- * @since 1.0 */ ! public abstract class Record { private RecordType recordType=null; /** Creates a new instance of Record */ public Record(RecordType recordType) { this.recordType=recordType; } *************** *** 38,50 **** } - public void setField(String fieldName,String fieldValue) - { - this.fieldMap.put(fieldName,fieldValue); - } - - public Object getField(String fieldName) - { - return this.fieldMap.get(fieldName); - } - } --- 36,38 ---- Index: FixedWidthFlatFileReader.java =================================================================== RCS file: /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/io/FixedWidthFlatFileReader.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** FixedWidthFlatFileReader.java 2 Jun 2006 04:40:07 -0000 1.3 --- FixedWidthFlatFileReader.java 2 Jun 2006 21:02:06 -0000 1.4 *************** *** 16,19 **** --- 16,23 ---- import java.io.IOException; import java.io.InputStreamReader; + import java.util.HashMap; + import java.util.Iterator; + import java.util.List; + import java.util.Map; import org.apache.log4j.Logger; *************** *** 24,61 **** public class FixedWidthFlatFileReader extends FileReader { private BufferedReader reader=null; private static Logger logger=Logger.getLogger(FixedWidthFlatFileReader.class); ! public void initialize() { try { ! reader=new BufferedReader(new InputStreamReader(new FileInputStream(new File(super.filePath)))); } catch(IOException exception) { exception.printStackTrace(); logger.fatal("IO Exception while initializing the file reader. Message = " + exception.getMessage(),exception); ! throw FileParseException("IO Exception while initializing the file reader. Message = " + exception.getMessage()); } } ! public Record getNextRecord() ! { ! String record=reader.readLine(); ! return null; ! } ! ! public boolean hasMoreRecords() { } ! ! public boolean hasMoreRecords() { ! } ! ! public void initialize(File inputFile, FileSpec fileSpec) { } } --- 28,139 ---- public class FixedWidthFlatFileReader extends FileReader { + protected String absoluteFilePath=null; + + protected FileSpec fileSpec=null; + private BufferedReader reader=null; private static Logger logger=Logger.getLogger(FixedWidthFlatFileReader.class); ! public FixedWidthFlatFileReader(String absoluteFilePath,FileSpec fileSpec) { + this.absoluteFilePath=absoluteFilePath; + this.fileSpec=fileSpec; + try { ! reader=new BufferedReader(new InputStreamReader(new FileInputStream(new File(this.absoluteFilePath)))); } catch(IOException exception) { + reader=null; exception.printStackTrace(); logger.fatal("IO Exception while initializing the file reader. Message = " + exception.getMessage(),exception); ! throw new FileParseException("IO Exception while initializing the file reader. Message = " + exception.getMessage()); } } ! public ReaderRecord getNextRecord() { + if(this.reader==null) + return null; + else + { + try + { + String recordString=this.reader.readLine(); + if(recordString==null) + { + this.reader=null; + return null; + } + else + { + ReaderRecord record=this.parseRecord(recordString); + return record; + } + } + catch(IOException exception) + { + logger.info("IOException while retrieving the next record. Message = " + exception.getMessage(),exception); + throw new FileParseException("IO Exception while retrieving the next record. Message = " + exception.getMessage()); + } + } } ! ! private ReaderRecord parseRecord(String recordString) { ! FixedWidthFlatFileReaderRecord record=null; ! List recordSpecList=this.fileSpec.getRecordSpecs(); ! for(Iterator recordSpecIterator=recordSpecList.iterator();recordSpecIterator.hasNext();) ! { ! FixedWidthFlatFileRecordSpec recordSpec=(FixedWidthFlatFileRecordSpec)recordSpecIterator.next(); ! if(recordSpec.isMatch(recordString)) ! { ! List fieldSpecList=recordSpec.getFieldSpecs(); ! record=new FixedWidthFlatFileReaderRecord(recordSpec.getRecordType(),fieldSpecList.size()); ! for(Iterator fieldSpecIterator=fieldSpecList.iterator();fieldSpecIterator.hasNext();) ! { ! FixedWidthFlatFileFieldSpec fieldSpec=(FixedWidthFlatFileFieldSpec)fieldSpecIterator.next(); ! String fieldValue=null; ! try ! { ! fieldValue=recordString.substring(fieldSpec.getStartPosition(),fieldSpec.getEndPosition()); ! } ! catch(IndexOutOfBoundsException exception) ! { ! exception.printStackTrace(); ! logger.fatal("Could not retrieve the field " + fieldSpec.getFieldName() + " from the record string " + ! recordString + " from the positions start = " + fieldSpec.getStartPosition() + " end = " + fieldSpec.getEndPosition()); ! } ! record.writeField(fieldSpec.getFieldName(),fieldValue); ! } ! break; ! } ! if(!recordSpecIterator.hasNext()) ! throw new FileParseException("Record " + recordString + " cannot be matched with any configured record specs."); ! } ! return record; ! } ! ! public class FixedWidthFlatFileReaderRecord extends ReaderRecord { + private Map fieldMap=null; + + protected FixedWidthFlatFileReaderRecord(RecordType recordType,int fieldCount) + { + super(recordType); + fieldMap=new HashMap(fieldCount); + } + + public Object readField(String fieldName) + { + return this.fieldMap.get(fieldName); + } + + protected void writeField(String fieldName,String fieldValue) + { + this.fieldMap.put(fieldName,fieldValue); + } } } Index: RecordSpec.java =================================================================== RCS file: /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/io/RecordSpec.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** RecordSpec.java 1 Jun 2006 22:11:41 -0000 1.3 --- RecordSpec.java 2 Jun 2006 21:02:06 -0000 1.4 *************** *** 47,49 **** --- 47,54 ---- return fieldSpecList; } + + public RecordType getRecordType() + { + return this.recordType; + } } --- NEW FILE: WriterRecord.java --- /* * WriterRecord.java * * Created on June 2, 2006, 11:26 AM * * 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 org.apache.xml.resolver.apps.resolver; /** * * @author Suresh Pragada */ public abstract class WriterRecord extends Record { /** Creates a new instance of WriterRecord */ public WriterRecord(RecordType recordType) { super(recordType); } public abstract void writeField(String fieldName,Object fieldValue); } --- FileIO.java DELETED --- --- NEW FILE: ReaderRecord.java --- /* * ReaderRecord.java * * Created on June 2, 2006, 11:24 AM * * 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; /** * * @author Suresh Pragada */ public abstract class ReaderRecord extends Record { /** Creates a new instance of ReaderRecord */ public ReaderRecord(RecordType recordType) { super(recordType); } public abstract Object readField(String fieldName); } Index: FixedWidthFlatFileRecordSpec.java =================================================================== RCS file: /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/io/FixedWidthFlatFileRecordSpec.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** FixedWidthFlatFileRecordSpec.java 1 Jun 2006 22:11:41 -0000 1.2 --- FixedWidthFlatFileRecordSpec.java 2 Jun 2006 21:02:06 -0000 1.3 *************** *** 36,44 **** } 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++) --- 36,55 ---- } + public boolean isMatch(String recordString) + { + if(recordString==null) + throw new IllegalArgumentException("Record string cannot be null to match record spec."); + return recordString.startsWith(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); ! String startsWith=recordSpecElement.getAttribute(FixedWidthFlatFileRecordSpec.STARTS_WITH_ATTRIB_NAME); ! if(startsWith!=null && startsWith.trim().equals("")) ! ((FixedWidthFlatFileRecordSpec)recordSpec).startsWith=startsWith.trim(); ! else ! throw new FileSpecException("Record Spec in Fixed Width File Spec should have starts-with attribute."); NodeList fieldSpecNodeList=recordSpecElement.getElementsByTagName(FieldSpec.FIELD_SPEC_TAG_NAME); for(int i=0;i<fieldSpecNodeList.getLength();i++) Index: FileReader.java =================================================================== RCS file: /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/io/FileReader.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** FileReader.java 2 Jun 2006 04:40:07 -0000 1.2 --- FileReader.java 2 Jun 2006 21:02:06 -0000 1.3 *************** *** 15,28 **** /** * * @author Suresh Pragada */ ! public interface FileReader { ! void initialize(File inputFile,FileSpec fileSpec); ! ! Record getNextRecord(); ! boolean hasMoreRecords(); } --- 15,53 ---- + + /** * * @author Suresh Pragada */ ! public abstract class FileReader { ! public abstract ReaderRecord getNextRecord(); ! public static FileReader getFileReader(String absoluteFilePath,String absoluteFileSpecPath) ! { ! if(absoluteFilePath==null) ! throw new IllegalArgumentException("Absolute file path to create the reader cannot be null."); ! else if(!(new File(absoluteFilePath).exists() && new File(absoluteFilePath).isFile())) ! throw new IllegalArgumentException("Absolute file path to create the reader should exist and should be a file. Given absolute file path = " + absoluteFilePath); ! ! if(absoluteFileSpecPath==null) ! throw new IllegalArgumentException("Absolute file path to read the file spec cannot be null."); ! else if(!(new File(absoluteFileSpecPath).exists() && new File(absoluteFileSpecPath).isFile())) ! throw new IllegalArgumentException("Absolute file path to read the file spec should exist and should be a file. Given absolute file spec path = " + absoluteFilePath); ! ! FileSpec fileSpec=FileSpec.createFileSpec(absoluteFileSpecPath); ! if(fileSpec.getFileType()==FileType.FIXED_WIDTH_FLAT_FILE) ! { ! return new FixedWidthFlatFileReader(absoluteFilePath,fileSpec); ! } ! else if(fileSpec.getFileType()==FileType.DELIMITED_FLAT_FILE) ! { ! return null; // Create Demlited Flat file reader. ! } ! else ! { ! throw new FileSpecException("Unsupported file type in the file spec = " + fileSpec.getFileType().toString()); ! } ! } } |
From: Suresh <sur...@us...> - 2006-06-02 04:40:53
|
Update of /cvsroot/batchserver/batchserver/test/org/jmonks/batchserver/io In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv2392 Added Files: FileSpecTest.java Log Message: no message --- NEW FILE: FileSpecTest.java --- /* * FileSpecTest.java * JUnit based test * * Created on June 1, 2006, 8:02 PM */ package org.jmonks.batchserver.io; import junit.framework.*; 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; /** * * @author Suresh Pragada */ public class FileSpecTest extends TestCase { public FileSpecTest(String testName) { super(testName); } protected void setUp() throws Exception { } protected void tearDown() throws Exception { } public static Test suite() { TestSuite suite = new TestSuite(FileSpecTest.class); return suite; } /** * Test of createFileSpec method, of class org.jmonks.batchserver.io.FileSpec. */ public void testCreateFileSpec() { System.out.println("testCreateFileSpec"); FileSpec fileSpec=FileSpec.createFileSpec("C:\\workspace\\workarea\\openapp\\batchserver\\src\\org\\jmonks\\batchserver\\io\\payment-file-spec.xml"); assertNotNull(fileSpec); System.out.println(fileSpec.toString()); } } |
From: Suresh <sur...@us...> - 2006-06-02 04:40:30
|
Update of /cvsroot/batchserver/batchserver/test/org/jmonks/batchserver/io In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv2331/io Log Message: Directory /cvsroot/batchserver/batchserver/test/org/jmonks/batchserver/io added to the repository |
Update of /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/io In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv2270 Modified Files: FieldSpec.java FileIO.java FileReader.java FixedWidthFlatFileFieldSpec.java FixedWidthFlatFileReader.java payment-file-spec.xml Log Message: no message Index: FileIO.java =================================================================== RCS file: /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/io/FileIO.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** FileIO.java 26 May 2006 22:22:26 -0000 1.1 --- FileIO.java 2 Jun 2006 04:40:07 -0000 1.2 *************** *** 24,28 **** { ! return FileReader.getFileReader(filePath,fileSpecPath); } } --- 24,48 ---- { ! FileReader fileReader=null; ! FileSpec fileSpec=FileSpec.createFileSpec(fileSpecPath); ! if(fileSpec.getFileType()==FileType.FIXED_WIDTH_FLAT_FILE) ! { ! fileReader=new FixedWidthFlatFileReader(); ! } ! else if(fileSpec.getFileType()==FileType.DELIMITED_FLAT_FILE) ! { ! fileReader=null; // Create Demlited Flat file reader. ! fileReader.filePath=filePath; ! fileReader.fileSpec=fileSpec; ! } ! else ! { ! // Throw an exception. ! } ! ! fileReader.filePath=filePath; ! fileReader.fileSpec=fileSpec; ! fileReader.initialize(); ! return fileReader; } } Index: FileReader.java =================================================================== RCS file: /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/io/FileReader.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** FileReader.java 26 May 2006 22:22:26 -0000 1.1 --- FileReader.java 2 Jun 2006 04:40:07 -0000 1.2 *************** *** 11,14 **** --- 11,16 ---- package org.jmonks.batchserver.io; + import java.io.File; + *************** *** 17,53 **** * @author Suresh Pragada */ ! public abstract class FileReader { ! protected String filePath=null; ! ! protected FileSpec fileSpec=null; ! public static FileReader getFileReader(String filePath,String fileSpecPath) ! { ! FileReader fileReader=null; ! /** ! * Create the fileSpec. ! */ ! FileSpec fileSpec=FileSpec.createFileSpec(fileSpecPath); ! if(fileSpec.getFileType()==FileType.FIXED_WIDTH_FLAT_FILE) ! { ! fileReader=new FixedWidthFlatFileReader(); ! fileReader.filePath=filePath; ! fileReader.fileSpec=fileSpec; ! } ! else if(fileSpec.getFileType()==FileType.DELIMITED_FLAT_FILE) ! { ! fileReader=null; // Create Demlited Flat file reader. ! fileReader.filePath=filePath; ! fileReader.fileSpec=fileSpec; ! } ! else ! { ! // Throw an exception. ! } ! return fileReader; ! } ! protected abstract void initialize(); ! public abstract Record getNextRecord(); } --- 19,28 ---- * @author Suresh Pragada */ ! public interface FileReader { ! void initialize(File inputFile,FileSpec fileSpec); ! Record getNextRecord(); ! boolean hasMoreRecords(); } Index: FixedWidthFlatFileReader.java =================================================================== RCS file: /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/io/FixedWidthFlatFileReader.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** FixedWidthFlatFileReader.java 1 Jun 2006 22:11:41 -0000 1.2 --- FixedWidthFlatFileReader.java 2 Jun 2006 04:40:07 -0000 1.3 *************** *** 11,14 **** --- 11,21 ---- package org.jmonks.batchserver.io; + import java.io.BufferedReader; + import java.io.File; + import java.io.FileInputStream; + import java.io.IOException; + import java.io.InputStreamReader; + import org.apache.log4j.Logger; + /** * *************** *** 17,27 **** public class FixedWidthFlatFileReader extends FileReader { public void initialize() { ! } public Record getNextRecord() { return null; } } --- 24,61 ---- public class FixedWidthFlatFileReader extends FileReader { + private BufferedReader reader=null; + + private static Logger logger=Logger.getLogger(FixedWidthFlatFileReader.class); + public void initialize() { ! try ! { ! reader=new BufferedReader(new InputStreamReader(new FileInputStream(new File(super.filePath)))); ! } ! catch(IOException exception) ! { ! exception.printStackTrace(); ! logger.fatal("IO Exception while initializing the file reader. Message = " + exception.getMessage(),exception); ! throw FileParseException("IO Exception while initializing the file reader. Message = " + exception.getMessage()); ! } } + public Record getNextRecord() { + String record=reader.readLine(); return null; } + + public boolean hasMoreRecords() + { + } + + public boolean hasMoreRecords() + { + } + + public void initialize(File inputFile, FileSpec fileSpec) + { + } } Index: FixedWidthFlatFileFieldSpec.java =================================================================== RCS file: /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/io/FixedWidthFlatFileFieldSpec.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** FixedWidthFlatFileFieldSpec.java 1 Jun 2006 22:11:41 -0000 1.2 --- FixedWidthFlatFileFieldSpec.java 2 Jun 2006 04:40:07 -0000 1.3 *************** *** 33,39 **** * Creates a new instance of FixedWidthFlatFileFieldSpec */ ! protected FixedWidthFlatFileFieldSpec(String fieldName,Class fieldType) { ! super(fieldName,fieldType); } --- 33,39 ---- * Creates a new instance of FixedWidthFlatFileFieldSpec */ ! protected FixedWidthFlatFileFieldSpec(String fieldName) { ! super(fieldName); } *************** *** 51,66 **** { 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)); --- 51,55 ---- { String fieldName=fieldSpecElement.getAttribute(FieldSpec.FIELD_NAME_ATTRIB_NAME); ! FieldSpec fieldSpec=new FixedWidthFlatFileFieldSpec(fieldName); int startPosition=Integer.parseInt(fieldSpecElement.getAttribute(FixedWidthFlatFileFieldSpec.START_POSITION_ATTRIB_NAME)); *************** *** 77,81 **** 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+ "]"); --- 66,69 ---- Index: FieldSpec.java =================================================================== RCS file: /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/io/FieldSpec.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** FieldSpec.java 1 Jun 2006 22:11:41 -0000 1.3 --- FieldSpec.java 2 Jun 2006 04:40:07 -0000 1.4 *************** *** 10,15 **** package org.jmonks.batchserver.io; ! ! import org.w3c.dom.Element; /** --- 10,14 ---- package org.jmonks.batchserver.io; ! import org.apache.log4j.Logger; /** *************** *** 21,37 **** 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 */ ! public FieldSpec(String fieldName,Class fieldType) { this.fieldName=fieldName; - this.fieldType=fieldType; } --- 20,32 ---- protected String fieldName=null; public static final String FIELD_SPEC_TAG_NAME = "field-spec"; public static final String FIELD_NAME_ATTRIB_NAME = "field-name"; ! private static Logger logger=Logger.getLogger(FieldSpec.class); ! public FieldSpec(String fieldName) { this.fieldName=fieldName; } *************** *** 40,48 **** return this.fieldName; } ! ! public Class getFieldType() ! { ! return this.fieldType; ! } ! } --- 35,38 ---- return this.fieldName; } ! } Index: payment-file-spec.xml =================================================================== RCS file: /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/io/payment-file-spec.xml,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** payment-file-spec.xml 26 May 2006 22:22:26 -0000 1.1 --- payment-file-spec.xml 2 Jun 2006 04:40:07 -0000 1.2 *************** *** 2,19 **** <file-spec file-type="fixed-width-flat"> ! <record-spec record-type="header" start-with="1"> ! <field-spec field-name="timestamp" field-type="java.lang.String" start-pos="2" end-pos="9"/> </record-spec> <record-spec record-type="detail" starts-with="5"> ! <field-spec field-name="pmtId" field-type="java.lang.Long" start-pos="2" end-pos="11"/> ! <field-spec field-name="pmtAmt" field-type="java.lang.Double" start-pos="12" end-pos="21"/> ! <field-spec field-name="mpaId" field-type="java.lang.Long" start-pos="22" end-pos="31"/> ! <field-spec field-name="pmId" field-type="java.lang.Long" start-pos="32" end-pos="41"/> </record-spec> ! <record-spec record-type="trailor" start-with="6"> ! <field-spec field-name="grandAmount" field-type="java.lang.Double" start-pos="2" end-pos="9"/> </record-spec> <!-- <record-spec record-type="detail" delimiter="|"> ! <field-spec field-name="pmtId" field-type="java.lang.Long" index="1"/> </record-spec> --> </file-spec> --- 2,19 ---- <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="pmtId" start-pos="2" end-pos="11"/> ! <field-spec field-name="pmtAmt" start-pos="12" end-pos="21"/> ! <field-spec field-name="mpaId" start-pos="22" end-pos="31"/> ! <field-spec field-name="pmId" start-pos="32" end-pos="41"/> </record-spec> ! <record-spec record-type="trailor" starts-with="6"> ! <field-spec field-name="grandAmount" start-pos="2" end-pos="9"/> </record-spec> <!-- <record-spec record-type="detail" delimiter="|"> ! <field-spec field-name="pmtId" index="1"/> </record-spec> --> </file-spec> |
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 ---- |
From: Suresh <sur...@us...> - 2006-05-30 17:09:46
|
Update of /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/io In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv4983 Modified Files: FieldSpec.java FileSpec.java RecordSpec.java Added Files: FileParseException.java FileSpecException.java FixedWidthFlatFileFieldSpec.java FixedWidthFlatFileRecordSpec.java Removed Files: FixedWidthFieldSpec.java Log Message: no message --- NEW FILE: FileSpecException.java --- /* * FileSpecException.java * * Created on May 26, 2006, 11:36 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; /** * * @author Suresh Pragada * @version 1.0 * @since 1.0 */ public class FileSpecException extends RuntimeException { /** Creates a new instance of FileSpecException */ public FileSpecException() { } } --- NEW FILE: FileParseException.java --- /* * FileParseException.java * * Created on May 26, 2006, 11:42 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; /** * * @author Suresh Pragada */ public class FileParseException extends RuntimeException { /** Creates a new instance of FileParseException */ public FileParseException() { } } --- FixedWidthFieldSpec.java DELETED --- --- NEW FILE: FixedWidthFlatFileFieldSpec.java --- /* * FixedWidthFlatFileFieldSpec.java * * Created on May 26, 2006, 2:43 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 org.w3c.dom.Element; /** * * @author Suresh Pragada */ public class FixedWidthFlatFileFieldSpec extends FieldSpec { 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; } } Index: RecordSpec.java =================================================================== RCS file: /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/io/RecordSpec.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** RecordSpec.java 26 May 2006 22:22:26 -0000 1.1 --- RecordSpec.java 30 May 2006 17:09:43 -0000 1.2 *************** *** 13,16 **** --- 13,17 ---- import java.util.ArrayList; import java.util.List; + import org.w3c.dom.Element; /** *************** *** 25,29 **** /** Creates a new instance of RecordSpec */ ! public RecordSpec(RecordType recordType) { this.recordType=recordType; --- 26,30 ---- /** Creates a new instance of RecordSpec */ ! protected RecordSpec(RecordType recordType) { this.recordType=recordType; *************** *** 41,43 **** --- 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; + } } Index: FileSpec.java =================================================================== RCS file: /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/io/FileSpec.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** FileSpec.java 26 May 2006 22:22:26 -0000 1.1 --- FileSpec.java 30 May 2006 17:09:43 -0000 1.2 *************** *** 13,20 **** import java.util.ArrayList; import java.util.List; /** * ! * @author Suresh Pragada */ public class FileSpec --- 13,23 ---- import java.util.ArrayList; import java.util.List; + import org.apache.log4j.Logger; /** * ! * @author Suresh Pragada ! * @version 1.0 ! * @since 1.0 */ public class FileSpec *************** *** 26,30 **** private List recordSpecList=null; ! /** Creates a new instance of FileSpec */ protected FileSpec() { --- 29,37 ---- private List recordSpecList=null; ! private static Logger logger=Logger.getLogger(FileSpec.class); ! ! /** ! * Creates a new instance of FileSpec ! */ protected FileSpec() { *************** *** 32,35 **** --- 39,49 ---- } + /** + * Adds the record spec object to the record spec list. + * + * @param recordSpec Record spec. + * + * @return Returns true, if record spec is added, false otherwise. + */ public boolean addRecordSpec(RecordSpec recordSpec) { *************** *** 37,46 **** return true; } ! public List getRecordSpec() { return this.recordSpecList; } ! public FileType getFileType() { --- 51,70 ---- return true; } ! ! /** ! * Gets the record spec's list. ! * ! * @return Returns record spec's list. ! */ public List getRecordSpec() { return this.recordSpecList; } ! ! /** ! * Gets the file type. ! * ! * @return Returns the file type. ! */ public FileType getFileType() { *************** *** 48,53 **** --- 72,82 ---- } + /** + * Constructs the file spcification object from the file represented by + * given the file specification path. + */ public static FileSpec createFileSpec(String fileSpecPath) { + FileSpec fileSpec=null; return null; } --- NEW FILE: FixedWidthFlatFileRecordSpec.java --- /* * FixedWidthFlatFileRecordSpec.java * * Created on May 26, 2006, 11:33 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 org.w3c.dom.Element; /** * * @author Suresh Pragada */ 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; } } Index: FieldSpec.java =================================================================== RCS file: /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/io/FieldSpec.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** FieldSpec.java 26 May 2006 22:22:26 -0000 1.1 --- FieldSpec.java 30 May 2006 17:09:43 -0000 1.2 *************** *** 11,14 **** --- 11,16 ---- package org.jmonks.batchserver.io; + import org.w3c.dom.Element; + /** * *************** *** 37,39 **** --- 39,46 ---- return this.fieldType; } + + public static FieldSpec createFieldSpec(final FileType fileType,final RecordType recordType,final Element fieldSpecElement) + { + return null; + } } |
From: Suresh <sur...@us...> - 2006-05-26 22:22:30
|
Update of /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/io In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv23292 Added Files: FieldSpec.java FileIO.java FileReader.java FileSpec.java FileType.java FixedWidthFieldSpec.java FixedWidthFlatFileReader.java payment-file-spec.xml payment.pmt Record.java RecordSpec.java RecordType.java Log Message: no message --- NEW FILE: FixedWidthFieldSpec.java --- /* * FixedWidthFieldSpec.java * * Created on May 26, 2006, 2:43 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; /** * * @author Suresh Pragada */ public class FixedWidthFieldSpec { private int startPosition=0; private int endPosition=0; /** Creates a new instance of FixedWidthFieldSpec */ public FixedWidthFieldSpec() { } } --- NEW FILE: RecordType.java --- /* * RecordType.java * * Created on May 26, 2006, 11:14 AM * * 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; /** * * @author Suresh Pragada */ public final class RecordType { private String type=null; /** Creates a new instance of RecordType */ private RecordType(String type) { this.type=type; } public String toString() { return type; } public static final RecordType HEADER = new RecordType("HEADER"); public static final RecordType DETAIL = new RecordType("DETAIL"); public static final RecordType TRAILOR = new RecordType("TRAILOR"); } --- NEW FILE: Record.java --- /* * Record.java * * Created on May 26, 2006, 11:04 AM * * 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.HashMap; import java.util.Map; /** * * @author Suresh Pragada * @version 1.0 * @since 1.0 */ public class Record { private RecordType recordType=null; private Map fieldMap=null; /** Creates a new instance of Record */ public Record(RecordType recordType) { this.recordType=recordType; fieldMap=new HashMap(); } public RecordType getRecordType() { return this.recordType; } public void setField(String fieldName,String fieldValue) { this.fieldMap.put(fieldName,fieldValue); } public Object getField(String fieldName) { return this.fieldMap.get(fieldName); } } --- NEW FILE: FixedWidthFlatFileReader.java --- /* * FixedWidthFlatFileReader.java * * Created on May 26, 2006, 2:15 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; /** * * @author Suresh Pragada */ public class FixedWidthFlatFileReader extends FileReader { public Record getNextRecord() { if() return null; } } --- NEW FILE: RecordSpec.java --- /* * RecordSpec.java * * Created on May 26, 2006, 2:21 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.ArrayList; import java.util.List; /** * * @author Suresh Pragada */ public class RecordSpec { private RecordType recordType=null; private List fieldSpecList=null; /** Creates a new instance of RecordSpec */ public RecordSpec(RecordType recordType) { this.recordType=recordType; fieldSpecList=new ArrayList(); } public boolean addFieldSpec(FieldSpec fieldSpec) { this.fieldSpecList.add(fieldSpec); return true; } public List getFieldSpecs() { return fieldSpecList; } } --- NEW FILE: payment.pmt --- 120060526 512345678910000012.0034343434347878787878 512345678920000013.0034343434347878787878 512345678930000014.0034343434347878787878 512345678940000015.0034343434347878787878 512345678950000016.0034343434347878787878 60000000.00 --- NEW FILE: FileSpec.java --- /* * FileSpec.java * * Created on May 26, 2006, 2:18 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.ArrayList; import java.util.List; /** * * @author Suresh Pragada */ public class FileSpec { private String fileSpecPath=null; private FileType fileType=null; private List recordSpecList=null; /** Creates a new instance of FileSpec */ protected FileSpec() { recordSpecList=new ArrayList(); } public boolean addRecordSpec(RecordSpec recordSpec) { this.recordSpecList.add(recordSpec); return true; } public List getRecordSpec() { return this.recordSpecList; } public FileType getFileType() { return this.fileType; } public static FileSpec createFileSpec(String fileSpecPath) { return null; } } --- NEW FILE: FileIO.java --- /* * FileIO.java * * Created on May 26, 2006, 9:33 AM * * 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; /** * * @author Suresh Pragada */ public final class FileIO { private FileIO() { } public static FileReader readFile(String filePath,String fileSpecPath) { return FileReader.getFileReader(filePath,fileSpecPath); } } --- NEW FILE: FileType.java --- /* * FileType.java * * Created on May 26, 2006, 3: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; /** * * @author Suresh Pragada */ public final class FileType { private String fileType=null; /** Creates a new instance of FileType */ private FileType(String fileType) { this.fileType=fileType; } public String toString() { return fileType; } public static final FileType FIXED_WIDTH_FLAT_FILE = new FileType("fixed-width-flat"); public static final FileType DELIMITED_FLAT_FILE = new FileType("delimited-flat"); } --- NEW FILE: FieldSpec.java --- /* * FieldSpec.java * * Created on May 26, 2006, 2:25 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; /** * * @author Suresh Pragada */ public class FieldSpec { private String fieldName=null; private Class fieldType=null; /** Creates a new instance of FieldSpec */ public FieldSpec(String fieldName,Class fieldType) { this.fieldName=fieldName; this.fieldType=fieldType; } public String getFieldName() { return this.fieldName; } public Class getFieldType() { return this.fieldType; } } --- NEW FILE: FileReader.java --- /* * FileReader.java * * Created on May 26, 2006, 9:37 AM * * 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; /** * * @author Suresh Pragada */ public abstract class FileReader { protected String filePath=null; protected FileSpec fileSpec=null; public static FileReader getFileReader(String filePath,String fileSpecPath) { FileReader fileReader=null; /** * Create the fileSpec. */ FileSpec fileSpec=FileSpec.createFileSpec(fileSpecPath); if(fileSpec.getFileType()==FileType.FIXED_WIDTH_FLAT_FILE) { fileReader=new FixedWidthFlatFileReader(); fileReader.filePath=filePath; fileReader.fileSpec=fileSpec; } else if(fileSpec.getFileType()==FileType.DELIMITED_FLAT_FILE) { fileReader=null; // Create Demlited Flat file reader. fileReader.filePath=filePath; fileReader.fileSpec=fileSpec; } else { // Throw an exception. } return fileReader; } protected abstract void initialize(); public abstract Record getNextRecord(); } --- NEW FILE: payment-file-spec.xml --- <?xml version="1.0" encoding="UTF-8"?> <file-spec file-type="fixed-width-flat"> <record-spec record-type="header" start-with="1"> <field-spec field-name="timestamp" field-type="java.lang.String" start-pos="2" end-pos="9"/> </record-spec> <record-spec record-type="detail" starts-with="5"> <field-spec field-name="pmtId" field-type="java.lang.Long" start-pos="2" end-pos="11"/> <field-spec field-name="pmtAmt" field-type="java.lang.Double" start-pos="12" end-pos="21"/> <field-spec field-name="mpaId" field-type="java.lang.Long" start-pos="22" end-pos="31"/> <field-spec field-name="pmId" field-type="java.lang.Long" start-pos="32" end-pos="41"/> </record-spec> <record-spec record-type="trailor" start-with="6"> <field-spec field-name="grandAmount" field-type="java.lang.Double" start-pos="2" end-pos="9"/> </record-spec> <!-- <record-spec record-type="detail" delimiter="|"> <field-spec field-name="pmtId" field-type="java.lang.Long" index="1"/> </record-spec> --> </file-spec> |
From: Suresh <sur...@us...> - 2006-05-26 22:21:37
|
Update of /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/io In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv22872/io Log Message: Directory /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/io added to the repository |
From: Suresh <sur...@us...> - 2006-05-24 14:34:26
|
Update of /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/framework/common In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv15837/jmonks/batchserver/framework/common Modified Files: ErrorCode.java Log Message: no message Index: ErrorCode.java =================================================================== RCS file: /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/framework/common/ErrorCode.java,v retrieving revision 1.17 retrieving revision 1.18 diff -C2 -d -r1.17 -r1.18 *** ErrorCode.java 24 May 2006 03:17:40 -0000 1.17 --- ErrorCode.java 24 May 2006 14:33:59 -0000 1.18 *************** *** 157,160 **** --- 157,164 ---- public static final ErrorCode JOB_CONNECTOR_CONFIGURATION_ERROR = new ErrorCode(1008,"Repository configuration in framework configuration is not defined properly."); /** + * Represents the unknown configuration error. + */ + public static final ErrorCode UNKNOWN_CONFIGURATION_ERROR = new ErrorCode(1009,"Configuration error related to unknown component."); + /** * Represents error because of the exception in basic job processor. */ |
From: Suresh <sur...@us...> - 2006-05-24 14:34:26
|
Update of /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/framework In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv15837/jmonks/batchserver/framework Modified Files: Main.java Log Message: no message Index: Main.java =================================================================== RCS file: /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/framework/Main.java,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** Main.java 24 May 2006 03:17:40 -0000 1.11 --- Main.java 24 May 2006 14:33:59 -0000 1.12 *************** *** 12,15 **** --- 12,16 ---- import org.jmonks.batchserver.framework.controller.JobController; import org.jmonks.batchserver.framework.management.JobManagementAgent; + import org.jmonks.batchserver.framework.repository.Repository; *************** *** 102,108 **** returnCode=jobController.process(); /** ! * Save the statistics */ ! } else --- 103,111 ---- returnCode=jobController.process(); /** ! * Save the statistics into repository */ ! JobStatistics jobStatistics=jobController.getJobStatistics(); ! logger.info(jobStatistics); ! Repository.getRepository().logStatistics(jobStatistics); } else |