Search in sources :

Example 16 with ParameterType

use of org.apache.cxf.jaxrs.model.ParameterType in project cxf by apache.

the class InjectionUtils method injectIntoCollectionOrArray.

// CHECKSTYLE:OFF
private static Object injectIntoCollectionOrArray(Class<?> rawType, Type genericType, Annotation[] paramAnns, MultivaluedMap<String, String> values, boolean isbean, boolean decoded, ParameterType pathParam, Message message) {
    // CHECKSTYLE:ON
    Class<?> type = getCollectionType(rawType);
    final Class<?> realType;
    final Type realGenericType;
    if (rawType.isArray()) {
        realType = rawType.getComponentType();
        realGenericType = realType;
    } else {
        Type[] types = getActualTypes(genericType);
        if (types == null || types.length == 0 || !(types[0] instanceof ParameterizedType)) {
            realType = getActualType(genericType);
            realGenericType = realType;
        } else {
            realType = getRawType(types[0]);
            realGenericType = types[0];
        }
    }
    Object theValues = null;
    if (type != null) {
        try {
            theValues = type.newInstance();
        } catch (IllegalAccessException ex) {
            reportServerError("CLASS_ACCESS_FAILURE", type.getName());
        } catch (Exception ex) {
            reportServerError("CLASS_INSTANTIATION_FAILURE", type.getName());
        }
    } else {
        theValues = Array.newInstance(realType, isbean ? 1 : values.values().iterator().next().size());
    }
    if (isbean) {
        Object o = InjectionUtils.handleBean(realType, paramAnns, values, pathParam, message, decoded);
        addToCollectionValues(theValues, o, 0);
    } else {
        List<String> valuesList = values.values().iterator().next();
        valuesList = checkPathSegment(valuesList, realType, pathParam);
        for (int ind = 0; ind < valuesList.size(); ind++) {
            Object o = InjectionUtils.handleParameter(valuesList.get(ind), decoded, realType, realGenericType, paramAnns, pathParam, message);
            addToCollectionValues(theValues, o, ind);
        }
    }
    return theValues;
}
Also used : ParameterizedType(java.lang.reflect.ParameterizedType) GenericArrayType(java.lang.reflect.GenericArrayType) ParameterType(org.apache.cxf.jaxrs.model.ParameterType) MediaType(javax.ws.rs.core.MediaType) Type(java.lang.reflect.Type) WildcardType(java.lang.reflect.WildcardType) ParameterizedType(java.lang.reflect.ParameterizedType) InvocationTargetException(java.lang.reflect.InvocationTargetException) WebApplicationException(javax.ws.rs.WebApplicationException)

Aggregations

ParameterType (org.apache.cxf.jaxrs.model.ParameterType)16 MetadataMap (org.apache.cxf.jaxrs.impl.MetadataMap)10 Type (java.lang.reflect.Type)8 HashMap (java.util.HashMap)8 LinkedHashMap (java.util.LinkedHashMap)8 Map (java.util.Map)8 MediaType (javax.ws.rs.core.MediaType)8 Parameter (org.apache.cxf.jaxrs.model.Parameter)8 GenericArrayType (java.lang.reflect.GenericArrayType)7 ParameterizedType (java.lang.reflect.ParameterizedType)7 WildcardType (java.lang.reflect.WildcardType)7 List (java.util.List)7 MultivaluedMap (javax.ws.rs.core.MultivaluedMap)6 ArrayList (java.util.ArrayList)5 InvocationTargetException (java.lang.reflect.InvocationTargetException)4 Method (java.lang.reflect.Method)4 WebApplicationException (javax.ws.rs.WebApplicationException)4 Endpoint (org.apache.cxf.endpoint.Endpoint)4 Field (java.lang.reflect.Field)3 InputStream (java.io.InputStream)2