Search in sources :

Example 1 with EntityProvider

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;
}
Also used : Provider(javax.inject.Provider) EntityProvider(org.minijax.cdi.EntityProvider) MediaType(javax.ws.rs.core.MediaType) RuntimeType(javax.ws.rs.RuntimeType) Type(java.lang.reflect.Type) Consumes(javax.ws.rs.Consumes) MediaType(javax.ws.rs.core.MediaType)

Aggregations

Type (java.lang.reflect.Type)1 Provider (javax.inject.Provider)1 Consumes (javax.ws.rs.Consumes)1 RuntimeType (javax.ws.rs.RuntimeType)1 MediaType (javax.ws.rs.core.MediaType)1 EntityProvider (org.minijax.cdi.EntityProvider)1