Java Implementation


The Java implementation of the design is composed of the source files listed below.

  • CSVToXML.java : the main routine for the Java application with CSV as the source

  • CSVSourceConverter.java (in package net.babelblaster.convert) : the class that drives conversion from CSV to XML

  • CSVRecordReader.java (in package net.babelblaster.record) : the class that handles reading CSV records and converting them to XML

  • XMLToCSV.java : the main routine for the Java application with CSV as the target

  • CSVTargetConverter.java (in package net.babelblaster.convert) : the class that drives conversion from XML to CSV

  • CSVRecordWriter.java (in package net.babelblaster.record) : the class that handles reading XML and building and writing CSV records

  • DataCellAN.java (in package net.babelblaster. cell ) : the class that handles alphanumeric fields in legacy formats

  • DataCellReal.java (in package net.babelblaster.cell) : the class that handles real (or decimal) number fields in legacy formats

  • DataCellDateMMsDDsYYYY.java (in package net.babelblaster.cell) : the class that handles date fields in MM/DD/YYYY representation in legacy formats

Since we are focusing on the logical design, have already covered the basic DOM operations with Java, and discussed earlier some advanced DOM programming considerations, I won't have very many comments here or in the C++ section.

The Java implementation is portable, so we can't make assumptions about the directory path separator character. To get it we use the System class getProperty method on the file.separator property, as follows :

 sDirectorySeparator = System.getProperty("file.separator"); 

To create an output directory in the CSVSourceConverter's processFile method, we use the mkdir method of the File class.

 File FilePath = new File(sOutputDirectory); FilePath.mkdir(); 

To read an input directory in the XMLToCSV main program, we again use the File class, passing the input directory name in the constructor. We then call the list method, returning an array of strings with the file names. These are the local names within the directory, so we must prefix them with the directory path before opening them.

 InputDirectory = new File(sInputDirectoryName); FilesList = InputDirectory.list(); if (FilesList != null) { //  Get first file from input directory //  DO for all files in input directory for (i=0; i < FilesList.length; i++) {   //  Build input file name   sInputFileName = sInputDirectoryName + FilesList[i];   //  DOM Document <- Load input file, validating it if   //    requested   docInput = Builder.parse(new File(sInputFileName)); 


Using XML with Legacy Business Applications
Using XML with Legacy Business Applications
ISBN: 0321154940
EAN: 2147483647
Year: 2003
Pages: 181

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net