Introduction

Following is a very brief introduction to the RecordEditor and the Examples provided.


Layouts

This package uses Layouts to describe a record or Line. The system uses a 3 level definition of each record as follows.

Layout :: 1 or more Records
Record :: 1 or more Fields


Field Java Class
Layout net.sf.RecordEditor.record.LayoutDetail
Record net.sf.RecordEditor.record.RecordDetail
Field net.sf.RecordEditor.record.types.FieldDetails


Line class

Java class net.sf.RecordEditor.record.Line represents one line (or data record) in the file. The main methods are


Type interface

Java classes that implement the interface net.sf.RecordEditor.record.types.Type are used to convert a field's value between the external representation and a Java String representation for display on the screen.


TypeManager

The TypeManager is used store the Type's and CellFormat's. You can use the static method getSystemTypeManager to get the system TypeManager. The method register is used to define new Types to the system.

   1:        TypeManager typeManager = TypeManager.getSystemTypeManager();


Examples

The examples are in the directory <install_directory>/src package net.sf.RecordEditor.examples.

Before you do anything else, you must update the constants in net.sf.RecordEditor.examples.Constants

All the examples require JRecord.jar and RecordEdit.jar to be added to the java class path. These jars will be in <install_directory>/lib directory.

Example class's CobolCopybookReader.java and CopybookToLayout.java + example programs XmplEditViaCobol.java and XmplEditSpecificFile3.java requires JRecord.jar, RecordEdit.jar and LayoutEdit.jar to be added to the java class path.


Java Class Purpose
CobolCopybookReader.java A Cobol Copybook Interface.
Constants.java Constants used by the examples. You may need to Update this file.
FileToVelocity.java This class will format
  • a Record oriented File (i.e. a file of Lines) using a velocity Template.
  • Selected files in a directory using velocity

For example if a Record-Layout of "ams Receipt" then the following classes will be generated
Java Class Purpose
AmsReceipt A class (extends Line) to access lines using the supplied RecordLayout
AmsReceiptProvider Class to create `AmsReceipt` Lines
AmsReceiptProcess Class to process files of Record-Layout "ams Receipt".

FormatComboExample
Example of a Format
LineDTAR0020.java
Sample hand coded line example
TypeCheckBoxYN.java
Sample Type and Cell_Format interfaces
TypeComboExample.java
Sample Type and Cell_Format interfaces
CopybookToLayout.java
Converts a XML/Cobol Copybook to a Layout
XmplDecider.java
Example of using Record Deciders (java classes that decide which layout to use)
XmplEditFormat1
Example of adding a Format to the RecordEditor
XmplEditSpecificFile1.java
Edit a specified file with the RecordEditor
XmplEditSpecificFile2.java
This is an example of editing a specific file using the Record Frame (i.e. one record per frame)
XmplEditSpecificFile3.java
This is an example of editing a specific file using your own JTable
XmplEditSuppliedData.java
This is an example of editing program supplied data with the RecordEditor
XmplEditType1.java
Example of defining your own Types
XmplFileStructure1.java
This is a example of introducing a new file structure (Mainframe VB with a maximum block size of 9040)
XmplFileStructure2.java
This is a example of introducing a new file structure. In this case this file structure is for Comma / Tab delimited files with the Column names on the second line of the file
XmplFileToVelocity1.java
This is an example of formatting selected files from a directory using Velocity (via FileToVelocity.java).
XmplLineBuilder.java
This class takes a Record-Layout and generates 3 java class's (using Velocity):
  • A specific Line class to access records using this Record-Layout
  • A LineProvider class for the line class generated
  • A class to process files of the supplied record layout

XmplLineIO1.java
Demonstrates Reading a file using RecordEditor's Line Based Routines. See "Reading a File" for more details.
XmplLineIO2.java
Demonstrates Reading and writing files using RecordEditor's Line Based Routines. It also illustrates LineIOProvider and LineProvider.
XmplLineIO2.java
Demonstrates Reading files using the CobolCopybookReader interface.
XmplLineIoVLR1.java
Example of reading a Standard Variable length record file (VB file on the mainframe).


Reading and Writing Files

The package provides standard classes for reading, writing Fixed formatting data files


Reading a File

The example program XmplLineIO1 provides a simple example of processing a file using the RecordEditor's IO routines.


Reading using User-Defined-Lines

The example program XmplLineIO2 illustrates the following points:


Generating Interfaces to files

The XmplLineBuilder can be used to generate interfaces classes to Cobol like files.

The main method is genType. It has the following parameters:
typeNametype name to be generated
extendProcesswhat class the generated process class should extend
arrayslist of arrays to watch for
getAndSetwether to generate getters and setters
defineFieldswether to define all the fields

This method builds 3 classes:

LineThe program builds a Line class specifically for the supplied Record Layout with optional Getter's and Setter's.
LineProviderA line provider for the Generated Line class
ProcessA class to process files of the supplied Record Layout.

There are examples of generated java programs in package net.sf.RecordEditor.examples.genCode


Record Layout Generate Line Generated Line Provider Generated Process Class
ams PO Download AmsPoDownload AmsPoDownloadProvider AmsPoDownloadProcess
ams Receipt AmsReceipt AmsReceiptProvider AmsReceiptProcess
EDI PO EdiPo EdiPoProvider EdiPoProcess


Formatting files with Velocity

The class FileToVelocity can format a file/files in a directory using Velocity. There are examples of its use in XmplFileToVelocity1.

Methods in FileToVelocity

Calling FileToVelocity

The following is an example of using FileToVelocity (taken from XmplFileToVelocity1).

Sample Velocity Templates

If you use a LineIOprovider and your own Line class, you can use Getter's & Setter's to access the various fields.

Alternatively if you use the generic Line class, you must use the generic getField to get a fields value:

Finally you can also use getField(String fieldname) of Line class to retrieve field values:


Extending the Record Editor

The RecordEditor can be extended in a number of ways:

All these examples require you update a Table in the Layout Editor


Editting a Table in the LayoutEditor

After starting the LayoutEdit, the menu screen is displayed:

Click on the second option Edit Tables and the Table edit screen is displayed:

You can select a table to be updated by clicking on the Table in the list on the left.


Type Interface

A `Type` acts as an interface between the fields storage in the data record and how it is displayed on the screen. It contains methods to extract a field from the data record (getField) and store it back in the data record


CellFormat Interface

A `CellFormat` provides TableCellRenderer's and TableCellEditor's to the RecordEditor. A CellFormat added to the system as part of a Type or as a separately as Formats.


TypeManager

The TypeManager is used store the Type's and CellFormat's. You can use the static method getSystemTypeManager to get the system TypeManager.

   1:        TypeManager typeManager = TypeManager.getSystemTypeManager();
   2:

Initially the TypeManager allows user types and user Cell Formats to have Id's of 1000 -> 1050. You can increase the number of User Types/Cell Formats via the setSystemTypeManager method.

   1:        TypeManager.setSystemTypeManager(new TypeManager(true, 200, 100));

You can define a type to a TypeManager by

   1:            typeManager.registerType(1000, checkBox);
   2:

Alternatively you can also assign a CellFormat to a Type as well by

   1:            typeManager.registerType(1000, checkBox, checkBox);
   2:


Adding a Type to the RecordEditor

Create the Type (new method)

Jave code for US Date Type

Following is the java code to implement a US Style MM/DD/YY date.

   1:package net.sf.RecordEditor.examples;
   2:
   3:import net.sf.JRecord.Types.TypeChar;;
   4:import net.sf.RecordEditor.record.types.TypeDateWrapper;
   5:
   6:/**
   7: * provide a US style date (mm/dd/yy)
   8: *
   9: * @author Bruce Martin
  10: *
  11: */
  12:public class USdate8 extends TypeDateWrapper {
  13:
  14:    /**
  15:     * provide a US style date (mm/dd/yy)
  16:     */
  17:    public USdate8() {
  18:        super(new TypeChar(true), "MM/dd/yy");
  19:    }
  20:}

Following is the code to provide a special Date Editor

   1:package net.sf.RecordEditor.examples;
   2:
   3:import net.sf.RecordEditor.record.format.DateFormat;
   4:
   5:/**
   6: * US date cell format (MM/DD/YY)
   7: *
   8: * @author Bruce Martin
   9: *
  10: */
  11:public class USdateFormat8 extends DateFormat {
  12:
  13:    /**
  14:     * US date cell format (MM/DD/YY)
  15:     */
  16:    public USdateFormat8() {
  17:        super(true, "MM/dd/yy");
  18:    }
  19:}
  20:

You now need to bundle this Type as a Java Jar file.

Defining a Type to the RecordEditor

Start the Edit RecordEditor Startup Properties and go to the User Types tag and entor the new Type as in the diagram below:

The next step is to define where your type is found, so go to the User Jars tag an enter your new jar as below

You can now use the new Type in both the RecordEditor and the LayoutEditor.

Create the Type (old method)

The first step is the type (examples are TypeCheckBoxYN.Java and TypeComboExample.Java)

   3:    public class TypeCheckBoxYN implements Type, CellFormat {
   4:
        ....    Type Code goes here    .....
   5:
   6:    }

Defining a Type to the RecordEditor

There are 2 ways to define a Type to the RecordEditor

  1. Via the Edit RecordEditor Startup Properties program

  2. Via the old method

Define the Type in the LayoutEditor  Next step is to define the Type to the RecordEditor. This is done in table 1, the Type table (go into LayoutEdit, take option 2 Edit Tables. See "Editting a Table in the LayoutEditor" for details). In the picture below, a new user type 1001 ~ Checkbox Y/N has been defined

Using the new Type  You should now be able to use the Type Checkbox Y/N in the field definition panel (Record Definition screen) as below.

Starting the RecordEditor with the new Type  The final step is to start the RecordEditor with the new Type. Please note that at line 9, the new type checkBox is defined as type number 1001, which is exactly the same as what it was defined in the LayoutEdit (see "Define the Type in the LayoutEditor").

This java code came from XmplType1.Java

Editing a File

Finally after starting the editor using the java code from "Starting the RecordEditor with the new Type", it should like (with Combobox's and Checkbox's).

or the record view


Adding a Format to the RecordEditor

This section goes through adding and then using a "Adding a Format to the RecordEditor" in the RecordEdit.

Writing a format

The following code was extracted from FormatComboExample.java

Define the Format in the LayoutEditor

Next step is to define the Format in the Format Table (go into LayoutEdit, take option 2 Edit Tables, finally click on Table 5 ~ Formats. See "Editting a Table in the LayoutEditor" for details) and enter the new format (in this case 1001 ~ ComboBox).

Using the new Format

You should now be able to use the format Combobox in Record field definitions.

Starting the RecordEditor with the new Type

The final step is to start the RecordEditor with the new Format. Please note

  1. On line 12, the Combo Items are registered against AMS PO Type which is the field Parameter in "Using the new Format"
  2. On line 15, the comboFormat is defined to the system with a key of 1001, which was also used in "Define the Format in the LayoutEditor".

Editing a File

Finally after starting the editor using the java code from "Starting the RecordEditor with the new Type"


Record Deciders

When there are more than one Record in a Layout, there has to be a way to decide which record should be used. One way of doing this is via a RecordDecider:

   1:public interface RecordDecider {
   2:
   3:    /**
   4:     * Get the prefered Layout
   5:     *
   6:     * @param line to decide what the prefered layout is
   7:     *
   8:     * @return the prefered layout
   9:     */
  10:    public abstract int getPreferedIndex(Line line);
  11:}

Once you have created a RecordDecider, you must register it and start the Editor as follows (example taken from XmplDecider.java):

   1:        CopyBookDbReader copybook = new CopyBookDbReader();
   2:
   3:        copybook.registerDecider("ProductExmpl", new XmplDecider());
   4:
   5:        new EditRec("", 1, copybook);


Adding a File Structure

To add a new file structure, you must:

  1. Create a Line-Reader (must extend class AbstractLineReader) and Line-Writer (must extend class AbstractLineWriter).
  2. Define the new File Structure in the File Structure Table. See "Editting a Table in the LayoutEditor" for details.
  3. Create a new LineIOProvider that uses the new Line-Reader and Line-Writer.
  4. Call the RecordEditor with the new LineIOProvider

Line Reader

To create a new file structure, you must create a new LineReader that extends the class AbstractLineReader and implements the abstract methods open, read and close.

Line Writer

You must also create a new LineWriter that extends the class AbstractLineWriter and implements the abstract methods open, write and close.

Defining the File Structure in the LayoutEditor

The next step is to add the new file structure to the File Structure table. See "Editting a Table in the LayoutEditor" for details.

Using the new File Structure

You should now be able to use the new file structure in the Record-Definition Extra panel:

Creating a LineIOProvider

Following is a sample LineIOProvider that will create the new LineReader's / LineReader's if the appropriate file structure is supplied.

Starting the RecordEditor

The following code starts the RecordEditor with the LineIOProvider from "Creating a LineIOProvider". This will introduce the new File Structures.

   1:        CopyBookDbReader copybook = new CopyBookDbReader();
   2:
   3:        new EditRec("", 1, new XmplFileStructure2(), copybook);
   4:

Examples

See XmplFileStructure1.java and XmplFileStructure2.java for examples.


Copybook Loader

If you already have record layouts (Copybooks in Cobol), you should look at the writing your own CopybookLoader. This will allow you to import the record layouts into the RecordEditor as well as use the layouts in the Cobol Editor program

CopybookLoader Interface

The CopybookLoader Interface describes a class to load a external Record Layout into the RecordEditor's internal DB.

Sample Copybook Loader

Following is a simple class to load a Record Layout (copybook) from a Tab delimited file.

Adding a Copybook Loader to the RecordEditor

There are 2 steps to defining your Copybook loader to the RecordEditor

  1. First you must add the code you have written to the RecordEditor (as a jar) via the Edit RecordEditor Startup Properties program.

  2. Next you must define your new Class on the Copybook Loaders tag

You should now ne able to import your layouts in to the RecordEditor + Edit your files using your Layouts in the Cobol Editor


Copybook Interface

The CopyBookInterface describes a class that acts as an interface between the external storage of layouts (copybooks in Cobol terminology) and the java representation LayoutDetail. By default the RecordEditor uses class CopyBookDbReader (which reads copybooks from a Database), but you could create your own. An alternate implementation of CopyBookInterface is CobolCopybookReader which read's Cobol Copybooks instead of a Database.

Using CobolCopybookReader in the RecordEditor

To start the RecordEditor with the CobolCopybookReader class (from XmplEditViaCobol.java):

   1:        try {
   2:            CobolCopybookReader copybook = new CobolCopybookReader();
   3:
   4:            new EditRec("", 1, copybook); // starting the record editor
   5:
   6:        } catch (Exception e) {

Using CobolCopybookReader to read Cobol Files

You can also use the CobolCopybookReader to read files (see line 8 below):


Options for starting the RecordEditor

The RecordEditor can also be started in a number of ways from Java programs. This section shows various ways of doing this.


Editing a Specific file

If you want to start the RecordEditor with a specific file, then the following code from XmplEditSpecificFile1.Java will do it.


Edit a File one Record at time

It is also possible to edit a file with the Single Record view (i.e. one line or record is displayed on the screen at a time with fields going down the screen). The following code from XmplEditSpecificFile2.Java does this.


Other Examples

XmplEditSpecificFile3.Java

Shows how to edit a file using your own JTable

XmplEditSuppliedData.Java

This example demonstrates calling the RecordEditor using program-generated data.


Index

C
  • Cobol
  • Editting using a Cobol Copybook (16)
  • Reading a file using a Cobol Copybook (17)
  • E
  • Editting
  • Editing a file one record at a time (19)
  • Editing a program Supplied Data (20)
  • Editing a Specific file (18)
  • Examples
  • G
  • Generating
  • Line's and LineProviders (11)
  • I
  • Interfaces
  • T
  • Type
  • Creating (new method) (14)
  • Creating (old method) (15)
  • Definition (12)
  • Introduction (9)
  • TypeManager class
  • Definition (13)
  • Introduction (10)
  • V
  • Velocity