OBOE Code Generator

As of 2007-08-15

Purpose:

The program produces either two different Java programs or two different XML PIXES processes to aid in OBOE program development. By reading in a rules file to generate an transaction set object the application produces all code to reference tables, segments, composites and data elements.

The generated code is skeletal. There is not quite enough logic to do anything useful but enough code to enable quick code development.

How To Run The Application:

From the command line: java com.americancoders.OBOECodeGenerator pJ|pP|bJ|bP envelope tsid [-useName] [outputFileName]

Parameter 1 - pJ, pP, bJ, or bP

The parsing programs (pJ or pP) are used when you want a program that to parse an incoming EDI and have reference variables to all the objects built from the parsed document. The generated program is be used to read incoming documents so you add logic to pull the data and store it in some type of datastore.
The building programs (bJ or bP) are used when you want a program that generates an an EDI message. The programs will generate an empty EDI object. The object is then used to generate either an EDI document.

Parameter 2 - envelope

Used to specify the envelope rules file. The code will enclude all of the segments and function groups and their segments. At this time specify either x12.envelope or EDIFact.envelope. Do not include the .xml file extension.

Parameter 3. tsid - required.

Specify the transaction set id to be used as the basis for the program.

Parameter 4. -useName (optional)

The parameter is switch to direct the generator to build the Java method names using the Object names. For instance, a method is generated for each segment. The method names will use the name attribute as found in the xml rules file. If the paramter is not used then the method names are generated from the object's id attribute.

Parameter 5. outputfilename (optional)

Specify where to place the generated code.

Note 1: If the parameter ends with ".java" the generator will build the class name from the output file name. For instance if you specify "test840.java" then the application will build a class and its constructor name as test840.

Note 2: If the outputfilename is not used or the name does not end with ".java" then the class name and constructor name are built from the type and tsid fields.

Creating a Message Parser in Java Code

The following code snippets show some of the Java program that can be generated. Using the following command line call:

java com.americancoders.util.OBOECodeGenerator pJ x12.envelope 840 p840.java
import com.americancoders.edi.*; import com.americancoders.edi.x12.*; import java.io.*; /** code template to parse *<br>class 840 Purchase Order *<br> * This Draft Standard for Trial Use contains the format and establishes * the data contents of the Request for Quotation Transaction Set * (840) for use within the context of an Electronic Data Interchange * (EDI) environment. The transaction set can be used to provide * potential buyers with the ability to solicit price, delivery * schedule, and other items from potential sellers of goods and * services. *@author OBOECodeGenerator */ public class p840 { /** constructor for class p840 *@param inFileName - String filename to be parsed *@throws OBOEException - most likely transactionset not found *@throws IOException - most likely input file not found */ public p840(String inFileName) throws OBOEException, IOException { File fileToParse = new File(inFileName); if (fileToParse.exists() == false) throw new OBOEException("File: "+ inFileName + " does not exist."); X12DocumentHandler dh = new X12DocumentHandler(); dh.startParsing(new FileReader(fileToParse)); X12Envelope env = (X12Envelope) dh.getEnvelope(); Table table; FunctionalGroup fg; TransactionSet ts; int fgCount = env.getFunctionalGroupCount(); int tsCount = -1; for (int fgPosition = 0; fgPosition < fgCount; fgPosition++) { fg = env.getFunctionalGroup(fgPosition); tsCount = fg.getTransactionSetCount(); for (int tsPosition = 0; tsPosition < tsCount; tsPosition++) { ts = fg.getTransactionSet(tsPosition); table = ts.getHeaderTable(); if (table != null) { extractSegmentSTfromTableHeader(table); extractSegmentBQTfromTableHeader(table); extractSegmentCURfromTableHeader(table);
... later in the code
/** extract data from segment CUR that is part of the TableHeader *<br>Currency used *<br>To specify the currency (dollars, pounds, francs, etc.) used in a transaction * @param inTable Table containing this segment *@throws OBOEException - most likely segment not found */ public void extractSegmentCURfromTableHeader(Table inTable) throws OBOEException { Segment segment = inTable.getSegment("CUR"); if (segment == null) return; DataElement de; de = segment.getDataElement(1); // 98 Entity Identifier Code if (de != null) de.get(); de = segment.getDataElement(2); // 100 Currency Code if (de != null) de.get(); de = segment.getDataElement(3); // 280 Exchange Rate if (de != null) de.get(); de = segment.getDataElement(4); // 98 Entity Identifier Code if (de != null) de.get(); de = segment.getDataElement(5); // 100 Currency Code if ...
    Notes:
  1. The import statement with the x12 package. This is here because the X12.envelope rules file was specified as the second paramter.
  2. The class name and constructor is p840 the output file name was specified.
  3. Constructor takes a String filename. Since this is a parser routine an input document will need to be parsed. The constructor assumes an Exception will be thrown. You may want to change that logic to fit your requirements.
  4. Constructor pulls each table object and calls a method associated with each segment defined within the table. If you know your application will not uses these segments you may want to remove the call and method logic.
  5. The segment methods show a path. In this example "extractSegmentCURfromTableHeader" shows the code gets there from the header table to the CUR segment. Likewise if a child segment would show its path also. Such as "extractSegmentDISfromTableDetailLoopPO1" shows a path from the Detail table to its PO1 loop to the PO1 DIS segment.
  6. Segment methods are passed its parent object. For example "extractSegmentCURfromTableHeader" is passed the Header table object and "extractSegmentDISfromTableDetailLoopPO1" is passed the PO1 loop object.
  7. The application test to see if the object exists in the segment container. For example "extractHeaderSegmentCUR"; tests to see if there is a CUR segment in the Header table object, if not it then the method simply exits
  8. At the de.get() statements is where you would place your application store logic.

Creating a Message Builder in Java Code

For another document describing how to create a build message program and using the API see
Working The OBOE API document.

The following code snippets show some of the Java program that can be generated. Using the following command line call:

java com.americancoders.util.OBOECodeGenerator bJ x12.envelope 840 b840.java
import com.americancoders.edi.*; import com.americancoders.edi.x12.*; /** code template to build *<br>class 840 Purchase Order *<br> * This Draft Standard for Trial Use contains the format and establishes * the data contents of the Request for Quotation Transaction Set * (840) for use within the context of an Electronic Data Interchange * (EDI) environment. The transaction set can be used to provide * potential buyers with the ability to solicit price, delivery * schedule, and other items from potential sellers of goods and * services. *@author OBOECodeGenerator */ public class b840 { /** constructor for class b840 *@throws OBOEException - most likely transactionset not found */ public b840() throws OBOEException { X12Envelope env = new X12Envelope(EnvelopeFactory.buildEnvelope("x12.envelope", "")); /** add code here to work with the headers and other envelope control segments */ Segment interchange_Control_Header = env.createInterchange_Header(); interchange_Control_Header.useDefault(); // Grade of Service Request not required Segment grade_of_Service_Request = env.createGrade_of_Service_Request(); grade_of_Service_Request.useDefault(); // Deferred Delivery Request not required Segment deferred_Delivery_Request = env.createDeferred_Delivery_Request(); deferred_Delivery_Request.useDefault(); FunctionalGroup fg = env.createFunctionalGroup(); /** add code here to work with the fg header and trailer segments */ Segment fgHeader = fg.getHeader(); fgHeader.useDefault(); fg.addSegment(fgHeader); Segment fgTrailer = fg.getTrailer(); fgTrailer.useDefault(); fg.addSegment(fgTrailer); env.addFunctionalGroup(fg); TransactionSet ts = TransactionSetFactory.buildTransactionSet("840"); fg.addTransactionSet(ts); Table table; table = ts.getHeaderTable(); buildSegmentSTforTableHeader(table); buildSegmentBQTforTableHeader(table); buildSegmentCURforTableHeader(table);
later on ...
/** builds segment DIS that is part of the TableHeader
*
Discount Detail used *
To specify the exact type and terms of various discount information * @param inTable table containing this segment * @return segment object DIS * @throws OBOEException - most likely segment not found */ public Segment buildSegmentDISforTableHeader(Table inTable) throws OBOEException { Segment segment = inTable.createSegment("DIS"); inTable.addSegment(segment); DataElement de; de = (DataElement) segment.buildDE(1); // 653 Discount Terms Type Code //de.set(""); de = (DataElement) segment.buildDE(2); // 654 Discount Base Qualifier //de.set(""); de = (DataElement) segment.buildDE(3); // 655 Discount Base Value //de.set(""); de = (DataElement) segment.buildDE(4); // 656 Discount Control Limit Qualifier //de.set(""); de = (DataElement) segment.buildDE(5); // 657 Discount Control Limit //de.set(""); de = (DataElement) segment.buildDE(6); // 657 Discount Control Limit //de.set("");//not required segment.useDefault(); return segment; }
    Notes:
  1. The class name and constructor is b840 because an outputfile name was specified.
  2. Constructor takes no parameter.
  3. Constructor builds each table object and calls a method associated with each loop and segment defined within the table. If you know your application will not uses these loops or segments you may want to remove the call and method logic.
  4. The segment methods show a path. In this example "buildSegmentDISforTableHeader" shows the code gets there from the header table to the DIS segment. Likewise if a subsegment would show its path also. Such as "buildSegmentDISforTableDetailPO1" shows a path from the Detail table to its PO1 loop to the PO1 DIS segment.
  5. Segment methods are passed its parent object. For example "buildSegmentDISforTableHeader" is passed the Header table object and "buildSegmentDISforTableDetailPO1" is passed the PO1 Loop object.
  6. Use the de.set method to populate the object with your outgoing data.

    Creating a Message Builder in PIXES Code

    For another document describing how to create a build message program and using the PIXES scripts see
    Working The OBOE API document.

    The following code snippets show some of the Java program that can be generated. Using the following command line call:

    java com.americancoders.util.OBOECodeGenerator bJ x12.envelope 840 b840.java

    Publish or Perish