use of org.minijax.cdi.EntityProvider in project minijax by minijax.
the class MinijaxApplication method getParamProviders.
/**
* Returns the param providers for a resource method.
*
* This is very similar to the logic used in building param providers for a normal
* <code>@Inject</code> constructor, with one major difference.
*
* A resource method is allowed one special "entity" parameter representing the content body.
* This entity parameter is handled by a <code>EntityProvider</code>.
*
* @param method The resource method.
* @return The array of resource method param providers.
*/
private Provider<?>[] getParamProviders(final Method method) {
final Class<?>[] paramClasses = method.getParameterTypes();
final Type[] paramTypes = method.getGenericParameterTypes();
final Annotation[][] annotations = method.getParameterAnnotations();
final Provider<?>[] result = new Provider<?>[paramTypes.length];
final Consumes consumes = method.getAnnotation(Consumes.class);
final List<MediaType> consumesTypes = MediaTypeUtils.parseMediaTypes(consumes);
boolean consumed = false;
for (int i = 0; i < paramTypes.length; i++) {
if (annotations[i].length == 0 && !consumed) {
result[i] = new EntityProvider<>(paramClasses[i], paramTypes[i], annotations[i], consumesTypes);
consumed = true;
} else {
result[i] = getInjector().getProvider(paramClasses[i], annotations[i]);
}
}
return result;
}
Aggregations