X12TargetConverter Class (Extends TargetConverter)

Overview

The X12TargetConverter is again very similar to the CSV and flat file target converters, but again we add some complexities due to the grammar differences and the requirement to create the X12 control segments.

Attributes:

  • None

Methods:

  • Constructor

  • processDocument

  • writeHeaders

  • writeTrailers

Methods

Constructor

The constructor method sets up the X12TargetConverter object and the X12 RecordWriter object.

Logic for the X12TargetConverter Constructor Method
Arguments:
  Output Stream X12 Interchange Output file
  String File Description Document Name

Call base class constructor, passing File
    Description Document Name
Create X12RecordWriter object, passing:
    File Description DOM Document and Output Stream

processDocument

As was the case with the X12SourceConverter's processFile method, we aren't able to simply call the base TargetConverter class's processGroup method to perform the bulk of the required processing. Because of the way we have defined the grammar of X12 transaction sets, the first segment after the transaction set header isn't always required and we can't treat the document as just another group. We must include some of the same types of operations that we have in the main loop of the processGroup method, then call that method when we actually do need to process a group. We can use the processGroup method from the Target Converter base class.

Logic for the X12TargetConverter processDocument Method
Arguments:
  DOM Document Input Document

Returns:
  Error status or throws exception

Root Element <- Get Document's documentElement attribute
Root Element Name <- Get Root Element's tagName attribute
IF Root Element Name != Grammar Root Element Name
  Return error
ENDIF
Call X12RecordWriter's writeST method to write Transaction Set
    Header segment
Segment Grammar Node <- Get firstChild from Grammar Element
    skipping over non-Element Nodes
Segment Grammar Element <- Segment Grammar Node
Grammar Tag <- Call Segment Grammar's getAttribute for
    "ElementName"
Segment Element <- Get first childNode from Root Element,
    skipping over non-Element Nodes
DO until all child Elements of the Root have been processed
  Segment Name <- call Segment Element's getNodeName
  DO until Grammar Name = Segment Name
     Segment Grammar Element <- Get next Segment Element from
        Grammar, skipping over non-Element Nodes
    IF Segment Grammar Element is NULL
      Return error  //  This record is not part of the document
    ENDIF
    Grammar Name <- Call Segment Grammar's getAttribute for
        "ElementName"
  ENDDO
  Grammar Element Name <- Call Segment Grammar Element's
      getNodeName
  IF Grammar Element Name = "GroupDescription"
    Call processGroup, passing Record Element and Record Grammar
        Element
  ELSE
    Call X12RecordWriter parseRecord, passing Record Element and
        Record Grammar Element
    Call X12RecordWriter writeRecord, passing Record
        Grammar Element
  ENDIF
  Record Element <- Get Record Element's nextSibling, skipping
      over non-Element Nodes
ENDDO
Call X12RecordWriter's writeSE method to write Transaction Set
    Trailer Segment
Return success

writeHeaders

This method calls the X12RecordWriter's methods to write the interchange and group header control segments. This and the writeTrailers methods are included here because the main program knows nothing of the X12RecordWriter class. Its methods to write header and trailer segments can be invoked only by a call to one of the X12TargetConverter's methods.

Logic for the X12TargetConverter writeHeaders Method
Arguments:
  None

Returns:
  Status or throws exception

Call X12RecordWriter writeISA
Call X12RecordWriter writeGS
Return success

writeTrailers

This method calls the X12RecordWriter's methods to write the interchange and group trailer control segments.

Logic for the X12TargetConverter writeTrailers Method
Arguments:
  Integer Number of Included Transaction Sets

Returns:
  Status or throws exception

Call X12RecordWriter writeGE
Call X12RecordWriter writeIEA
Return success

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset