Following is a very brief introduction to the RecordEditor and the Examples provided.
This package uses Layouts to describe a record or Line. The system uses a 3 level definition of each record as follows.
Field | Java Class |
---|---|
Layout | net.sf.RecordEditor.record.LayoutDetail |
Record | net.sf.RecordEditor.record.RecordDetail |
Field | net.sf.RecordEditor.record.types.FieldDetails |
Java class net.sf.RecordEditor.record.Line represents one line (or data record) in the file. The main methods are
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.
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();
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
For example if a Record-Layout of "ams Receipt" then the
following classes will be generated
| ||||||||
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):
| ||||||||
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).
|
The package provides standard classes for reading, writing Fixed formatting data files
The example program XmplLineIO1 provides a simple example of processing a file using the RecordEditor's IO routines.
The example program XmplLineIO2 illustrates the following points:
The XmplLineBuilder can be used to generate interfaces classes to Cobol like files.
The main method is genType. It has the following parameters:
typeName | type name to be generated |
extendProcess | what class the generated process class should extend |
arrays | list of arrays to watch for |
getAndSet | wether to generate getters and setters |
defineFields | wether to define all the fields |
This method builds 3 classes:
Line | The program builds a Line class specifically for the supplied Record Layout with optional Getter's and Setter's. |
LineProvider | A line provider for the Generated Line class |
Process | A 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 |
The class FileToVelocity can format a file/files in a directory using Velocity. There are examples of its use in XmplFileToVelocity1.
Methods in FileToVelocity
The following is an example of using FileToVelocity (taken from XmplFileToVelocity1).
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:
The RecordEditor can be extended in a number of ways:
All these examples require you update a Table in the Layout Editor
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.
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
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.
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:
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.
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.
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: }
There are 2 ways to define a Type to the RecordEditor
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
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
This section goes through adding and then using a "Adding a Format to the RecordEditor" in the RecordEdit.
The following code was extracted from FormatComboExample.java
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).
You should now be able to use the format Combobox in Record field definitions.
The final step is to start the RecordEditor with the new Format. Please note
Finally after starting the editor using the java code from "Starting the RecordEditor with the new Type"
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);
To add a new file structure, you must:
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.
You must also create a new LineWriter that extends the class AbstractLineWriter and implements the abstract methods open, write and close.
The next step is to add the new file structure to the
File Structure table. See "Editting a Table in the LayoutEditor" for details.
You should now be able to use the new file structure in the Record-Definition Extra panel:
Following is a sample LineIOProvider that will create the new LineReader's / LineReader's if the appropriate file structure is supplied.
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:
See XmplFileStructure1.java and XmplFileStructure2.java for examples.
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
The CopybookLoader Interface describes a class to load a external Record Layout into the RecordEditor's internal DB.
Following is a simple class to load a Record Layout (copybook) from a Tab delimited file.
There are 2 steps to defining your Copybook loader to the RecordEditor
You should now ne able to import your layouts in to the RecordEditor + Edit your files using your Layouts in the Cobol Editor
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.
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) {
You can also use the CobolCopybookReader to read files (see line 8 below):
The RecordEditor can also be started in a number of ways from Java programs. This section shows various ways of doing this.
If you want to start the RecordEditor with a specific file, then the following code from XmplEditSpecificFile1.Java will do it.
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.
XmplEditSpecificFile3.Java | Shows how to edit a file using your own JTable |
XmplEditSuppliedData.Java | This example demonstrates calling the RecordEditor using program-generated data. |