if (metadata != null) {
if (metadata instanceof EditableDocument) metadata = ((EditableDocument)metadata).unwrap();
// Copy all the metadata into the entry's metadata ...
Document existingMetadata = getMetadata();
MutableDocument newMetadata = new BasicDocument(metadata.size() + 1);
newMetadata.put(FieldName.ID, existingMetadata.get(FieldName.ID));
for (Field field : metadata.fields()) {
String fieldName = field.getName();
if (fieldName.equals(FieldName.ID)) continue;
newMetadata.put(fieldName, field.getValue());
}
// Now record the change ...
value.put(FieldName.METADATA, newMetadata);
}