Parallel to this thought I am thinking of providing simple selfPopulate solutions for populating CSV data to any Java Object.
I have my code ready with the implementation, of course it can be tweaked to get better optimization and modularity. I am using java reflection to populate POJO with CSV data. The rules for population and validations are driven through properties file. Here is a snapshot of propeties that are used. This section is used to provide column sequence in CSV and bean attributes. The attribute names need to same as that in bean (Case sensitive). selfPopulate method uses setXxx pattern to call setter methods for storing CSV column values. columnSequence=empNumber columnSequence=empFirstName columnSequence=empLastName columnSequence=deptName columnSequence=empCTC columnSequence=empAddressId #End of column sequence These are possible validation types. More can be added. I guess this can be pulled out of bean to some common place. #validation types validationType=optionalInteger validationType=mandatoryInteger validationType=optionalFloat validationType=mandatoryFloat validationType=optionalString validationType=mandatoryString validationType=void #End of Validation types This section is used to map columns with validation type. Notice that column sequence needs to be maintained so as to map appropriate validation type. I guess use of xml in place of properties file will make is more readable and easy to maintain. #validationSequence to validation type mapping validationSequence=mandatoryString validationSequence=mandatoryString validationSequence=optionalString validationSequence=optionalString validationSequence=mandatoryFloat validationSequence=optionalInteger #End of columnSequence to validation type mapping Regards Chetan -----Original Message----- From: Don Seiler [mailto:[EMAIL PROTECTED] Sent: Friday, May 27, 2005 9:20 PM To: Jakarta Commons Users List Subject: Re: CSV parsing/writing? On 09:43 Fri 27 May , Don Seiler wrote: > Anyway it would be the mechanism to reading/writing CSVRecord objects > from/to the actual file. The CSVRecord object would do the actual > parsing/serializing for each line, given the parameters in its parent > CSVFile. > > Obviously this is a very simplistic view of things. I've not a great > deal of experience dealing with events and listeners outside of swing. > With DOM are we still talking about using the SAX setup and having > everything go through XML at one point or another? I see an example of > a SAX/CSV parser at oreilly's website that sort of makes sense to me, > but I may have to give it about 10 more reads to fully sink in. Alright here goes. I can just write my CSVFile class, let whatever user apps add themselves as listeners to it. The user apps then call parse on that, CSVFile would then open the file and call functions on the listeners, passing them an array of Strings (or other possible selection) representing the values in that line. User app can then do whatever it wants it that data. This setup on its own has nothing to do with DOM or XML, which I don't believe it should. If the client app wants to turn it into DOM/XML/JAXP whatever they can then do that in their lineParsed() function (or whatever its called) that CSVFile would call with the registered listeners. Let me know if you think I've totaly misunderstood how to do this properly. -- Don Seiler [EMAIL PROTECTED] Public Key: http://pgp.mit.edu:11371/pks/lookup?op=get&search=0xFC87F041 Fingerprint: 0B56 50D5 E91E 4D4C 83B7 207C 76AC 5DA2 FC87 F041 --------------------------------- This message contains the information that may be privileged and is the property of the KPIT Cummins Infosystems LTD.It is intended only for the person to whom it is addressed. If you are not intended recipient, you are not authorized to read, print , retain copy, disseminate, distribute, or use this message or any part thereof. If you receive this message in error, please notify the sender immediately and delete all copies of this message. KPIT Cummins does not accept any liability for virus infected mails. --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
