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