XMLCompositeCollectionMapping aggregateToSourceFieldNameAssociationsMapping = new XMLCompositeCollectionMapping();
aggregateToSourceFieldNameAssociationsMapping.setReferenceClass(FieldTranslation.class);
// Handle translation of fields associations string to field.
aggregateToSourceFieldNameAssociationsMapping.setAttributeAccessor(new AttributeAccessor() {
public Object getAttributeValueFromObject(Object object) {
AggregateObjectMapping mapping = (AggregateObjectMapping)object;
Vector associations = mapping.getAggregateToSourceFieldNameAssociations();
Vector translations = new Vector(associations.size());
for (int index = 0; index < associations.size(); index++) {
Association association = (Association)associations.get(index);
FieldTranslation translation = new FieldTranslation();
translation.setKey(new DatabaseField((String)association.getKey()));
translation.setValue(new DatabaseField((String)association.getValue()));
translations.add(translation);
}
return translations;
}
public void setAttributeValueInObject(Object object, Object value) {
AggregateObjectMapping mapping = (AggregateObjectMapping)object;
Vector associations = (Vector)value;
for (int index = 0; index < associations.size(); index++) {
Association association = (Association)associations.get(index);
association.setKey(((DatabaseField)association.getKey()).getQualifiedName());
association.setValue(((DatabaseField)association.getValue()).getQualifiedName());
}
mapping.setAggregateToSourceFieldNameAssociations(associations);
}
});
aggregateToSourceFieldNameAssociationsMapping.setAttributeName("aggregateToSourceFieldNameAssociationsMapping");
aggregateToSourceFieldNameAssociationsMapping.setXPath(getPrimaryNamespaceXPath() + "field-translations/" + getPrimaryNamespaceXPath() + "field-translation");
descriptor.addMapping(aggregateToSourceFieldNameAssociationsMapping);