private ComponentRequirement findRequirement(final AnnField field, AnnClass annClass, ClassLoader cl)
throws ComponentGleanerException
{
assert field != null;
Requirement anno = field.getAnnotation(Requirement.class);
if (anno == null) {
return null;
}
String fieldType = field.getType();
// TODO implement type resolution without loading classes
Class<?> type;
try {
type = Class.forName(fieldType, false, cl);
} catch (ClassNotFoundException ex) {
// TODO Auto-generated catch block
throw new ComponentGleanerException("Can't load class " + fieldType);
}
ComponentRequirement requirement;
if (isRequirementListType(type)) {
requirement = new ComponentRequirementList();
String[] hints = anno.hints();
if (hints != null && hints.length > 0) {
((ComponentRequirementList)requirement).setRoleHints(Arrays.asList(hints));
}
//
// TODO: See if we can glean any type details out of any generic information from the map or collection
//
}
else {
requirement = new ComponentRequirement();
requirement.setRoleHint(filterEmptyAsNull(anno.hint()));
}
// TODO need to read default annotation values
// if (anno.role()==null || anno.role().isAssignableFrom(Object.class)) {
if (anno.role().isAssignableFrom(Object.class)) {
requirement.setRole(type.getName());
}
else {
requirement.setRole(anno.role().getName());
}
requirement.setFieldName(field.getName());
requirement.setFieldMappingType(type.getName());
requirement.setOptional( anno.optional() );
return requirement;
}