* Process a @ManyToMany or many-to-many element into a TopLink MnayToMany
* mapping.
*/
public void process() {
// Create a M-M mapping and process common collection mapping metadata.
ManyToManyMapping mapping = new ManyToManyMapping();
process(mapping);
if (getMappedBy().equals("")) {
// Processing the owning side of a M-M that is process a join table.
processJoinTable(getJoinTable(), mapping);
} else {
// We are processing the a non-owning side of a M-M. Must set the
// mapping read-only.
mapping.setIsReadOnly(true);
// Get the owning mapping from the reference descriptor metadata.
ManyToManyMapping ownerMapping = null;
if (getOwningMapping().isManyToManyMapping()){
ownerMapping = (ManyToManyMapping)getOwningMapping();
} else {
// If improper mapping encountered, throw an exception.
getValidator().throwInvalidMappingEncountered(getJavaClass(), getReferenceClass());
}
// Set the relation table name from the owner.
mapping.setRelationTableName(ownerMapping.getRelationTableQualifiedName());
// Add all the source foreign keys we found on the owner.
mapping.setSourceKeyFields(ownerMapping.getTargetKeyFields());
mapping.setSourceRelationKeyFields(ownerMapping.getTargetRelationKeyFields());
// Add all the target foreign keys we found on the owner.
mapping.setTargetKeyFields(ownerMapping.getSourceKeyFields());
mapping.setTargetRelationKeyFields(ownerMapping.getSourceRelationKeyFields());
}
// Add the mapping to the descriptor.
m_descriptor.addMapping(mapping);
}