XMLCompositeCollectionMapping sourceToTargetKeyFieldAssociationsMapping = new XMLCompositeCollectionMapping();
sourceToTargetKeyFieldAssociationsMapping.setReferenceClass(Association.class);
// Handle translation of foreign key associations to hashtables.
sourceToTargetKeyFieldAssociationsMapping.setAttributeAccessor(new AttributeAccessor() {
public Object getAttributeValueFromObject(Object object) {
AggregateCollectionMapping mapping = (AggregateCollectionMapping)object;
List sourceFields = mapping.getSourceKeyFields();
List targetFields = mapping.getTargetForeignKeyFields();
List associations = new ArrayList(sourceFields.size());
for (int index = 0; index < sourceFields.size(); index++) {
associations.add(new Association(targetFields.get(index), sourceFields.get(index)));
}
return associations;
}
public void setAttributeValueInObject(Object object, Object value) {
AggregateCollectionMapping mapping = (AggregateCollectionMapping)object;
List associations = (List)value;
mapping.setSourceKeyFields(NonSynchronizedVector.newInstance(associations.size()));
mapping.setTargetForeignKeyFields(NonSynchronizedVector.newInstance(associations.size()));
Iterator iterator = associations.iterator();
while (iterator.hasNext()) {
Association association = (Association)iterator.next();
mapping.getSourceKeyFields().add((DatabaseField)association.getValue());
mapping.getTargetForeignKeyFields().add((DatabaseField)association.getKey());
}
}
});
sourceToTargetKeyFieldAssociationsMapping.setAttributeName("sourceToTargetKeyFieldAssociations");
sourceToTargetKeyFieldAssociationsMapping.setXPath(getPrimaryNamespaceXPath() + "target-foreign-key/" + getSecondaryNamespaceXPath() + "field-reference");