/** this method will write its value to the row provided */ public void writeOnRow(CobolRow row, byte[] recordData) { DatabaseField field = new DatabaseField(this.getName(), this.getRecord().getName()); Object value; // check for array first adjust size if necessary if (this.isArray() && this.dependsOn()) { adjustArraySize(row); } if (!this.isFieldRedefine()) { value = extractValueFromArray(recordData); } // redefined field handle accordingly else { value = new CobolRedefinedFieldValue(this, recordData); } row.add(field, value); }
/** this method will write its value from the row to the record data byte array */ public void writeOnArray(CobolRow row, byte[] recordData) { Object value = row.get(this.getName()); ByteConverter converter; if (this.isArray()) { // check for array first adjust size if necessary if (this.dependsOn()) { adjustArraySize(row); } int offset = this.getOffset(); Iterator elements = ((List) value).iterator(); for (int i = this.getArraySize(); i > 0; i--) { FieldMetaData fieldCopy = this.deepCopy(); fieldCopy.setOffset(offset); converter = new ByteConverter(fieldCopy, recordData); String elementValue = (String) elements.next(); converter.setBytesToValue(elementValue); offset += mySize; } } else { converter = new ByteConverter(this, recordData); converter.setBytesToValue((String) value); } }
/** this method adjusts the array size to the value in its dependent field */ protected void adjustArraySize(CobolRow row) { Integer intValue = Helper.integerFromString(row.get(this.getDependentFieldName()).toString()); if (intValue != null) { this.setArraySize(intValue.intValue()); } }