The TargetConverter, derived from the Converter class, is the base class for the CSV, flat file, and EDI target converter classes developed in the next three chapters. The lists below summarize the major attributes and methods.
Attributes:
RecordWriter Object
Methods:
Constructor
processDocument (virtual)
processGroup
The processGroup method is listed here for completeness but will be developed in Chapter 8.
Similar to the SourceConverter's constructor, the TargetConverter's constructor is very basic.
Arguments: String File Description Document Name Call base class constructor Call loadFileDescriptionDocument from passed document |
You will note that in this constructor, unlike the SourceConverter constructor, we load the file description document. This is because of differences in how we will process EDI files in Chapter 9. An EDI interchange that we read may have several different documents in it and may need several different file description documents. So, we don't want to load the file description document in the base class constructor. However, when we write an EDI interchange we'll just accept one document type as input. This is the same model we follow for CSV and flat files. We'll load the file description document in the base class target converter.
As with the processFile method in the SourceConverter, this method is declared as a virtual method in the base class and implemented separately in each of the derived classes for our legacy formats. The general processing model is to read from multiple XML documents in multiple files and create a single output file in the legacy format. We'll also make our life somewhat easier by reading the files from a single directory rather than multiple directories. The listing below shows the general logic.
Arguments: DOM Document Input Document Root Element <- Call Input Document's getDocumentElement method Root Element Name <- Call Root Element's getTagName IF (Root Element Name != Root Element Name from Grammar Element) Return Error ENDIF Child Element <- Get Root Element's firstChild, skipping over non-Element Nodes DO for all Record Elements, starting with first child of Root Record Grammar Element <- Get Record Grammar Element from Document Grammar Element Call RecordWriter's parseRecord method, passing Record Element and Record Grammar Element Call RecordWriter's writeRecord method ENDDO |
That's the basic setup. Pretty simple, huh? Simple is good. Simple is robust, maintainable, and extensible.