@SuppressWarnings("unchecked")
private static Object calculateParameterValue(Class parameterType, final Annotation[] parameterAnnotations,
ObjectLocator locator, Map<Class, Object> parameterDefaults)
{
AnnotationProvider provider = new AnnotationProvider()
{
public <T extends Annotation> T getAnnotation(Class<T> annotationClass)
{
return findAnnotation(parameterAnnotations, annotationClass);
}
};
// At some point, it would be nice to eliminate InjectService, and rely
// entirely on service interface type and point-of-injection markers.
InjectService is = provider.getAnnotation(InjectService.class);
if (is != null)
{
String serviceId = is.value();
return locator.getService(serviceId, parameterType);
}
// In the absence of @InjectService, try some autowiring. First, does the
// parameter type match on of the resources (the parameter defaults)?
if (provider.getAnnotation(Inject.class) == null)
{
Object result = parameterDefaults.get(parameterType);
if (result != null) return result;
}