The Java implementation of the design is composed of the source files listed below.
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); } } |