List<Field> fields = new ArrayList<Field>();
try {
if (recordMetaData == VariableFieldRecordMetaData.UNKNOWN_RECORD_TYPE) {
fields.add(new Field(recordMetaData.getFields().get(0).getName(), fieldValues.get(0)));
return new Record(recordMetaData.getName(), fields, recordMetaData);
} else {
int fieldValueOffset = 0;
// In message field definitions do not support variable field definitions... just one record type supported...
if (inMessageRecordMetaData == null && factory.isMultiTypeRecordSet()) {
// Skip the first field value because it's the field name...
fieldValueOffset = +1;
}
for (int i = 0; i < fieldValues.size(); i++) {
int fieldValueIndex = i + fieldValueOffset;
if (fieldValueIndex > fieldValues.size() - 1) {
break;
}
if (!recordMetaData.isWildCardRecord() && i > fieldsMetaData.size() - 1) {
// We're done... ignore the rest of the fields...
break;
}
Field field;
String value = fieldValues.get(fieldValueIndex);
if (recordMetaData.isWildCardRecord() || i > fieldsMetaData.size() - 1) {
field = new Field("field_" + i, value);
} else {
FieldMetaData fieldMetaData = fieldsMetaData.get(i);
if (fieldMetaData.ignore()) {
i += fieldMetaData.getIgnoreCount() - 1;
if (i < 0) {
// An overflow has resulted...
i = Integer.MAX_VALUE - 1;
}
continue;
}
StringFunctionExecutor stringFunction = fieldMetaData.getStringFunctionExecutor();
if (stringFunction != null) {
value = stringFunction.execute(value);
}
field = new Field(fieldMetaData.getName(), value);
field.setMetaData(fieldMetaData);
}
fields.add(field);
}
}
} finally {
recordCount++;
}
return new Record(recordMetaData.getName(), fields, recordMetaData);
}