Using the generated Java helper class in an application
The Java class created by the RecordClassGenerator class can be used as part of an existing Java application to construct or parse a byte array passed to or from an assembler application.
Each generated Java helper class contains two constructors that can be used to create an instance of the generated class. Also, individual public accessor methods are generated for each symbol in the assembler source code. These constructors and accessor methods enable you to either:
- Create a new instance of the generated class then use the accessor methods to set the fields in the class and obtain a byte array that represents the fields you have set, ready to be used by the assembler program.
- Create an instance of the generated class based on an existing byte array that was passed to the Java program from the assembler program. The accessor methods can then be used to obtain the values from fields in the byte array.
Constructing a new record
This example creates a new instance of the MyRecord class by using the zero
argument constructor and uses the setClaimNumber() method to set a value for the
CLAIM_NUMBER field. Other accessor methods might then be used to set the other fields in the record.
When all the fields are set, then the getByteBuffer() method is used to obtain a
byte array that is in the correct format to be used as input to the assembler
program.
MyRecord rec = new MyRecord();
String claimnum = "0000000000123456789";
rec.setClaimNumber(claimnum);
byte[] record = rec.getByteBuffer();
Creating a record from an existing byte array
If the Java program already has access to a byte array that contains data from the assembler
program, then it can be used within the MyRecord class constructor to create an
instance of the MyRecord class, which represents the data within the array. The
Java program can use the getClaimNumber() method to obtain the value of the field
within the byte array and manipulate it as
necessary.
byte[] record;
MyRecord rec = new MyRecord(record);
String claimnum = rec.getClaimNumber();