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.
1: public interface CopyBookInterface { 2: 3: 4: /** 5: * Register a record Decider for later use 6: * 7: * @param layoutName record layout name 8: * @param decider record decider 9: */ 10: public abstract void registerDecider(String layoutName, 11: RecordDecider decider); 12: 13: /** 14: * This method gets all the systems that have been defined 15: * 16: * @return ArrayList of Systems 17: * @throws Exception Error recieved 18: */ 19: public abstract ArrayList getSystems() throws Exception; 20: 21: /** 22: * Loads the various Layouts 23: * @param layouts record layouts 24: */ 25: public abstract void loadLayouts(final ArrayList layouts); 26: 27: 28: /** 29: * Get a group of records from the name 30: * 31: * @param lName Name of the Record Group being Request 32: * @return Group of records 33: */ 34: public LayoutDetail getLayout(String lName); 35: 36: 37: /** 38: * get the error message 39: * @return last error message 40: */ 41: public String getMessage(); 42: }
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):
14:package net.sf.RecordEditor.examples; 15: 16:import net.sf.RecordEditor.record.LayoutDetail; 17:import net.sf.RecordEditor.record.Line; 18:import net.sf.RecordEditor.record.LineProvider; 19:import net.sf.RecordEditor.record.io.AbsLineReader; 20:import net.sf.RecordEditor.record.io.LineIOProvider; 21: 22:/** 23: * 24: * Purpose: Provide examples for using 25: * 26: * LineProvider - LineProviders (DTAR0020provider) creates a 27: * Line (or extension of Line). If you want to use your 28: * own line in the record editor, you must pass a 29: * LineProvider (which will create your line rather than 30: * the RecordEditor's Line). 31: * 32: * LineIOProvider - LineIOProvider will return a LineReader / LineWrite 33: * appropriate to the File structure (avaiable via 34: * LayoutDetails.getFileStructure() 35: * 36: * AbsLineReader - Line-Readers are used to read "Line's" from a file 37: * System defined Line-Readers are: 38: * * TextLineReader - Read Text files 39: * * FixedLengthLineReader - read fixed record length binary 40: * files. 41: * * BinaryLineReader - reads a binary file with the 42: * the Line class calculating record lengths 43: * 44: * AbsLineWriter - Line-Writers write "Line's" to a file 45: * System defined Line-Readers are: 46: * * TextLineWriter writes "Line's" to a text file 47: * * BinaryLineWriter writes "Line's" to a binary file 48: * 49: * Line - Extending the Line class and using these extended 50: * classes 51: * 52: * @Author Bruce Martin 53: * Created on 10/09/2005 54: */ 55:public final class XmplLineIO3 { 56: 57: private static final double GST_CONVERSION 58: = 1.1; 59: private String installDir = Constants.RECORDEDIT_INSTALL_DIRECTORY; 60: private String salesFile = installDir + "SampleFiles\\DTAR020.bin"; 61: 62: private CobolCopybookReader copybook = new CobolCopybookReader(); 63: private LayoutDetail salesCopyBook = copybook.getLayout("DTAR020"); 64: private int fileStructure = salesCopyBook.getFileStructure(); 65: 66: private LineIOProvider ioProvider = new LineIOProvider(); 67: 68: private AbsLineReader reader = ioProvider.getLineReader(fileStructure, 69: new DTAR0020provider()); 70: 71: /** 72: * Example of LineReader / LineWrite classes 73: */ 74: private XmplLineIO3() { 75: super(); 76: 77: int lineNum = 0; 78: double gstExclusive; 79: LineDTAR0020 saleRecord; 80: 81: try { 82: reader.open(salesFile, salesCopyBook); 83: 84: while ((saleRecord = (LineDTAR0020) reader.read()) != null) { 85: lineNum += 1; 86: 87: System.out.print(saleRecord.getKeycode() 88: + "\t" + saleRecord.getQuantity() 89: + "\t" + saleRecord.getSalesRetail()); 90: 91: gstExclusive = saleRecord.getSalesRetail() / GST_CONVERSION; 92: saleRecord.setSalesRetail(gstExclusive); 93: 94: System.out.println("\t" + saleRecord.getSalesRetail()); 95: } 96: 97: reader.close(); 98: } catch (Exception e) { 99: System.out.println("~~> " + lineNum + " " + e.getMessage()); 100: System.out.println(); 101: 102: e.printStackTrace(); 103: } 104: } 105: 106: 107: 108: /** 109: * Create line provider for DTAR0020lines 110: * 111: * 112: * @author Bruce Martin 113: * 114: */ 115: private class DTAR0020provider implements LineProvider { 116: 117: /** 118: * @see net.sf.RecordEditor.record.LineProvider#getLine 119: */ 120: public Line getLine(LayoutDetail recordDescription) { 121: return new LineDTAR0020(recordDescription); 122: } 123: 124: /** 125: * @see net.sf.RecordEditor.record.LineProvider#getLine 126: */ 127: public Line getLine(LayoutDetail recordDescription, byte[] lineBytes) { 128: return new LineDTAR0020(recordDescription, lineBytes); 129: } 130: 131: /** 132: * @see net.sf.RecordEditor.record.LineProvider#getLine 133: */ 134: public Line getLine(LayoutDetail recordDescription, String linesText) { 135: return new LineDTAR0020(recordDescription, linesText); 136: } 137: } 138: 139: /** 140: * LineIO example 2 141: * 142: * @param args program arguments 143: */ 144: public static void main(String[] args) { 145: new XmplLineIO3(); 146: } 147:}