[Batchserver-cvs] batchserver/src/org/jmonks/batchserver/io XMLFileReader.java, NONE, 1.1 XMLFileSp
Brought to you by:
suresh_pragada
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(); } } |