Java Implementation


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

  • X12ToXML.java : the main routine for the Java application with an X12 interchange as source

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

  • EDIRecordReader.java (in package net.babelblaster.record) : the base class that handles reading EDI segments and converting to XML

  • X12RecordReader.java (in package net.babelblaster.record) : the class that handles reading X12 control segments

  • XMLToX12.java : the main routine for the Java application with an X12 interchange as target

  • X12TargetConverter.java (in package net.babelblaster.convert) : the class that drives conversion from XML to an X12 interchange

  • EDIRecordWriter.java (in package net.babelblaster.record) : the class that handles reading XML and building and writing EDI segments

  • X12RecordWriter.java (in package net.babelblaster.record) : the class that handles building and writing X12 control segments

  • DataCellX12N.java (in package net.babelblaster. cell ) : the class that handles the X12 Number data type

  • DataCellX12R.java (in package net.babelblaster.cell) : the class that handles the X12 Decimal data type

  • DataCellX12DT.java (in package net.babelblaster.cell) : the class that handles the X12 Date data type

  • DataCellX12TM.java (in package net.babelblaster.cell) : the class that handles the X12 Time data type

It is mildly interesting that both the XMLToX12 and X12ToXML converters directly read or manipulate three different XML documents in the same program. This is trivial since in the Document Object Model these are all three different objects. The APIs keep track for us of what belongs to whom.

We use only a few new features in this code that we haven't seen before. To get the Date and Time data elements for the ISA interchange and GS group header segments we use the java.util.Date and java.text.SimpleDateFormat classes. This excerpt from the writeISA method shows how we do this.

 //  Date <- Get date from system, and reformat to YYMMDD //  Time <- Get time from system, and reformat to HHMM Date CurrentTime = new Date(); SimpleDateFormat dtFormatter =     new SimpleDateFormat("yyyyMMddhhmm"); String sDateTime = dtFormatter.format(CurrentTime); sDate6 = sDateTime.substring(2,8); sDate8 = sDateTime.substring(0,8); sTime = sDateTime.substring(8); 

To parse the control segments in the X12RecordReader we use the string tokenizer in java.util.StringTokenizer. The code that precedes this excerpt creates a String representation of the data element separator. As a class member attribute it has a Java data type of byte. This code from the parseISA method loads the ISA array of String with the data elements from the ISA segment.

 //  Using language-specific string token routines, //  load class attributes ISA01 through ISA16 StringTokenizer st =     new StringTokenizer(ISASegment, sElementSeparator); for (i=0; i < 17; i++) {   ISA[i] = st.nextToken();   if (!st.hasMoreTokens() && ( i != 16 ))   {     throw new BlasterException(       TextConstants.sExceptionInsuffientElements +       "Expected: 16  Found: " + i + " in ISA \n" +       ISASegment);   } } 


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