List<Field> sourceFields = getAnnotatedFields(sourceClass, EdmNavigationProperty.class);
List<Field> targetFields = getAnnotatedFields(targetClass, EdmNavigationProperty.class);
// first try via association name to get full navigation information
for (Field sourceField : sourceFields) {
final EdmNavigationProperty sourceNav = sourceField.getAnnotation(EdmNavigationProperty.class);
final String sourceAssociation = extractRelationshipName(sourceNav, sourceField);
for (Field targetField : targetFields) {
final EdmNavigationProperty targetNav = targetField.getAnnotation(EdmNavigationProperty.class);
final String targetAssociation = extractRelationshipName(targetNav, targetField);
if (sourceAssociation.equals(targetAssociation)) {
return new AnnotatedNavInfo(sourceField, targetField, sourceNav, targetNav);
}
}
}
// if nothing was found assume none bi-directinal navigation
String targetEntityTypeName = extractEntityTypeName(targetClass);
for (Field sourceField : sourceFields) {
final EdmNavigationProperty sourceNav = sourceField.getAnnotation(EdmNavigationProperty.class);
final String navTargetEntityName = extractEntitTypeName(sourceNav, sourceField);
if (navTargetEntityName.equals(targetEntityTypeName)) {
return new AnnotatedNavInfo(sourceField, null, sourceNav, null);
}