use of org.qi4j.api.service.qualifier.Qualifier in project qi4j-sdk by Qi4j.
the class ServiceInjectionProviderFactory method newInjectionProvider.
@Override
public InjectionProvider newInjectionProvider(Resolution resolution, DependencyModel dependencyModel) throws InvalidInjectionException {
// TODO This could be changed to allow multiple @Qualifier annotations
Annotation qualifierAnnotation = first(filter(Specifications.translate(Annotations.type(), hasAnnotation(Qualifier.class)), iterable(dependencyModel.annotations())));
Specification<ServiceReference<?>> serviceQualifier = null;
if (qualifierAnnotation != null) {
Qualifier qualifier = qualifierAnnotation.annotationType().getAnnotation(Qualifier.class);
try {
serviceQualifier = qualifier.value().newInstance().qualifier(qualifierAnnotation);
} catch (Exception e) {
throw new InvalidInjectionException("Could not instantiate qualifier serviceQualifier", e);
}
}
if (dependencyModel.rawInjectionType().equals(Iterable.class)) {
Type iterableType = ((ParameterizedType) dependencyModel.injectionType()).getActualTypeArguments()[0];
if (Classes.RAW_CLASS.map(iterableType).equals(ServiceReference.class)) {
// @Service Iterable<ServiceReference<MyService<Foo>> serviceRefs
Type serviceType = ((ParameterizedType) iterableType).getActualTypeArguments()[0];
return new IterableServiceReferenceProvider(serviceType, serviceQualifier);
} else {
// @Service Iterable<MyService<Foo>> services
return new IterableServiceProvider(iterableType, serviceQualifier);
}
} else if (dependencyModel.rawInjectionType().equals(ServiceReference.class)) {
// @Service ServiceReference<MyService<Foo>> serviceRef
Type referencedType = ((ParameterizedType) dependencyModel.injectionType()).getActualTypeArguments()[0];
return new ServiceReferenceProvider(referencedType, serviceQualifier);
} else {
// @Service MyService<Foo> service
return new ServiceProvider(dependencyModel.injectionType(), serviceQualifier);
}
}
Aggregations