for (String fieldName : fieldDefinitions.keySet()) {
Field field = fieldDefinitions.get(fieldName);
FieldType fieldType = field.getTypeEnum();
Logger.trace("===== Processing field: " + field.getName() + " - type specified as: " + fieldType.name() + " multiplicity = " + field.getMaxOccurs());
FieldHandler handler = fieldType.getHandler();
String xpath = field.getXpath();
String strValue = null;
Object fieldValue = p.getValue(field.getName());
// First, see if the field should be included in the output
boolean outputField = handler.outputField(field, p);
if (outputField) {
if (field.getMaxOccurs() > 1) {
// We are expecting an ArrayList with one or more items
ArrayList list = (ArrayList)fieldValue;
if (list != null) {
for (Object fieldListItem : list) {
// Do some pre-processing on the field if required
boolean continueProcessing =
handler.preProcessSerialise(namespaces, fieldListItem, xpath, parent, xmldoc, field, p);
// Sometimes the pre-processing may handle the node creation itself (e.g. for coded items),
// in which case we don't need to continue here
if (continueProcessing) {
// If the field is not blank, create a new node or nodes for it to go into
if (!handler.isItemBlank(field, fieldListItem, true)) {
createNode(namespaces, xpath, parent, xmldoc, fieldListItem, handler, field, p);
}
}
}
}
} else {
// Do some pre-processing on the field if required
boolean continueProcessing =
handler.preProcessSerialise(namespaces, fieldValue, xpath, parent, xmldoc, field, p);
// Sometimes the pre-processing may handle the node creation itself (e.g. for coded items),
// in which case we don't need to continue here
if (continueProcessing) {
// If the field is not blank, create a new node or nodes for it to go into
if (!handler.isItemBlank(field, fieldValue, false)) {
createNode(namespaces, xpath, parent, xmldoc, fieldValue, handler, field, p);
}
}
}
}