/** performs a deep copy of all the attributes of the field */ public FieldMetaData deepCopy() { FieldMetaData fieldCopy = new ElementaryFieldMetaData(new String(myName), myRecord.getName()); fieldCopy.setIsFieldRedefine(isRedefine); fieldCopy.setDecimalPosition(decimalPosition); fieldCopy.setArraySize(myArraySize); fieldCopy.setSize(mySize); fieldCopy.setOffset(myOffset); fieldCopy.setType(myType); if (isFieldRedefine()) { fieldCopy.setFieldRedefined(myFieldRedefined.deepCopy()); } fieldCopy.setDependentFieldName(new String(myDependentFieldName)); fieldCopy.setIsSigned(isSigned); return fieldCopy; }
/** * this method extracts and returns the value for the field, if the field is an array, the value * is an <code>Vector</code> */ public Object extractValueFromArray(byte[] recordData) { Object value; if (this.isArray()) { int offset = this.getOffset(); ArrayList fieldValue = new ArrayList(this.getArraySize()); for (int i = this.getArraySize(); i > 0; i--) { FieldMetaData fieldCopy = this.deepCopy(); fieldCopy.setOffset(offset); ByteConverter converter = new ByteConverter(fieldCopy, recordData); fieldValue.add(converter.getStringValue()); offset += mySize; } value = fieldValue; } else { ByteConverter converter = new ByteConverter(this, recordData); value = converter.getStringValue(); } return 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); } }