public boolean isReadable(Class<?> type, Type genericType, Annotation[] anns, MediaType mt) { if (InjectionUtils.isSupportedCollectionOrArray(type)) { type = InjectionUtils.getActualType(genericType); if (type == null) { return false; } } return canBeReadAsJaxbElement(type) || isSupported(type, genericType, anns); }
private static boolean isSupported(Class<?> type) { return InjectionUtils.isPrimitive(type); }
public static Type processGenericTypeIfNeeded(Class<?> serviceCls, Class<?> paramCls, Type type) { if (type instanceof TypeVariable) { type = InjectionUtils.getSuperType(serviceCls, (TypeVariable<?>)type); } else if (type instanceof ParameterizedType) { ParameterizedType pt = (ParameterizedType)type; if (pt.getActualTypeArguments()[0] instanceof TypeVariable && isSupportedCollectionOrArray(getRawType(pt))) { TypeVariable<?> typeVar = (TypeVariable<?>)pt.getActualTypeArguments()[0]; Type theType = InjectionUtils.getSuperType(serviceCls, typeVar); if (theType instanceof Class) { type = new ParameterizedCollectionType((Class<?>)theType); } else { type = processGenericTypeIfNeeded(serviceCls, paramCls, theType); type = new ParameterizedCollectionType(type); } } } if (type == null || type == Object.class) { type = paramCls; } return type; }
private static boolean allowedMapListValue(Class<?> cls, Type type) { if (List.class.isAssignableFrom(cls)) { Class<?> listtype = getRawType( getType(((ParameterizedType)type).getActualTypeArguments(), 0)); return InjectionUtils.isPrimitive(listtype); } return false; }
private static boolean isSupportedMap(Type genericType) { Class<?> rawType = getRawType(genericType); if (Map.class.isAssignableFrom(rawType) && genericType instanceof ParameterizedType) { ParameterizedType paramType = (ParameterizedType) genericType; if (paramType.getActualTypeArguments().length == 2) { Class<?> firstType = getRawType(getType(paramType.getActualTypeArguments(), 0)); Type secondType = getType(paramType.getActualTypeArguments(), 1); Class<?> secondRawType = getRawType(secondType); return InjectionUtils.isPrimitive(firstType) && (InjectionUtils.isPrimitive(secondRawType) || allowedMapListValue(secondRawType, secondType)); } } return false; }
public static Type processGenericTypeIfNeeded(Class<?> serviceCls, Class<?> paramCls, Type type) { if (type instanceof TypeVariable) { type = InjectionUtils.getSuperType(serviceCls, (TypeVariable<?>)type); } else if (type instanceof ParameterizedType && ((ParameterizedType)type).getActualTypeArguments()[0] instanceof TypeVariable && isSupportedCollectionOrArray(getRawType(type))) { TypeVariable<?> typeVar = (TypeVariable<?>)((ParameterizedType)type).getActualTypeArguments()[0]; Type theType = InjectionUtils.getSuperType(serviceCls, typeVar); Class<?> cls = theType instanceof Class ? (Class<?>)theType : InjectionUtils.getActualType(theType, 0); type = new ParameterizedCollectionType(cls); } if (type == null || type == Object.class) { type = paramCls; } return type; }
Class<?> jaxbElement) { boolean isCollection = false; if (InjectionUtils.isSupportedCollectionOrArray(type)) { type = InjectionUtils.getActualType(genericType); isCollection = true; Type theType = InjectionUtils.processGenericTypeIfNeeded(serviceClass, Object.class, genericType); type = InjectionUtils.getActualType(theType); || InjectionUtils.isPrimitive(type) || (jaxbElement != null && jaxbElement.isAssignableFrom(type)) || Response.class.isAssignableFrom(type) Class<?> genCls = InjectionUtils.getActualType(genericType); if (genCls != type && genCls != null && genCls != Object.class && !InjectionUtils.isSupportedCollectionOrArray(genCls)) { types.getAllTypes().put(genCls, genCls);
String value) throws SearchParseException { Class<?> valueType = typeInfo.getTypeClass(); boolean isCollection = InjectionUtils.isSupportedCollectionOrArray(valueType); Class<?> actualType = isCollection ? InjectionUtils.getActualType(typeInfo.getGenericType()) : valueType; castedValue = convertToDate(valueType, value); } else { boolean isPrimitive = InjectionUtils.isPrimitive(valueType); boolean isPrimitiveOrEnum = isPrimitive || valueType.isEnum(); if (ownerBean == null || isPrimitiveOrEnum) { CollectionCheck collCheck = getCollectionCheck(originalPropName, isCollection, actualType); if (collCheck == null) { castedValue = InjectionUtils.convertStringToPrimitive(value, actualType); Method getterM = actualType.getMethod("get" + nextPart, new Class[]{}); Class<?> returnType = getterM.getReturnType(); boolean returnCollection = InjectionUtils.isSupportedCollectionOrArray(returnType); Class<?> actualReturnType = !returnCollection ? returnType : InjectionUtils.getActualType(getterM.getGenericReturnType()); && InjectionUtils.isPrimitive(returnType) || returnType.isEnum(); boolean lastTry = names.length == 2 && (isPrimitive || Date.class.isAssignableFrom(returnType) || returnCollection); nextObject = isPrimitive ? InjectionUtils.convertStringToPrimitive(value, returnType) : convertToDate(returnType, value); } else {
private Class<?> getActualType(Type type, int pos) { Class<?> actual = null; try { actual = InjectionUtils.getActualType(type, pos); } catch (Exception ex) { // ignore; } return actual != null && actual != Object.class ? actual : Attachment.class; }
protected void addFormValue(MultivaluedMap<String, String> form, String name, Object pValue, Annotation[] anns) { if (pValue != null) { if (InjectionUtils.isSupportedCollectionOrArray(pValue.getClass())) { Collection<?> c = pValue.getClass().isArray() ? Arrays.asList((Object[]) pValue) : (Collection<?>) pValue; for (Iterator<?> it = c.iterator(); it.hasNext();) { FormUtils.addPropertyToForm(form, name, convertParamValue(it.next(), anns)); } } else { FormUtils.addPropertyToForm(form, name, name.isEmpty() ? pValue : convertParamValue(pValue, anns)); } } }
private void doWriteBeanParam(StringBuilder sb, Class<?> type, Parameter pm, String parentName, List<Class<?>> parentBeanClasses, boolean isJson) { Map<Parameter, Class<?>> pms = InjectionUtils.getParametersFromBeanClass(type, pm.getType(), true); for (Map.Entry<Parameter, Class<?>> entry : pms.entrySet()) { String name = entry.getKey().getName(); if (parentName != null) { name = parentName + "." + name; } Class<?> paramCls = entry.getValue(); boolean isPrimitive = InjectionUtils.isPrimitive(paramCls) || paramCls.isEnum(); if (isPrimitive || Date.class.isAssignableFrom(paramCls) || InjectionUtils.isSupportedCollectionOrArray(paramCls)) { doWriteParam(sb, entry.getKey(), paramCls, paramCls, name, new Annotation[] {}, isJson); } else if (!parentBeanClasses.contains(paramCls)) { parentBeanClasses.add(paramCls); doWriteBeanParam(sb, paramCls, entry.getKey(), name, parentBeanClasses, isJson); parentBeanClasses.remove(paramCls); } } }
if (pValues != null && pValues.length > 0) { for (Object pValue : pValues) { if (InjectionUtils.isSupportedCollectionOrArray(pValue.getClass())) { Collection<?> c = pValue.getClass().isArray() ? Arrays.asList((Object[]) pValue) : (Collection<?>) pValue; Object pValue = pValues[0]; MultivaluedMap<String, Object> values = InjectionUtils.extractValuesFromBean(pValue, ""); for (Map.Entry<String, List<Object>> entry : values.entrySet()) { for (Object v : entry.getValue()) {
Type genericParam = InjectionUtils.processGenericTypeIfNeeded( ori.getClassResourceInfo().getServiceClass(), param, genericParameterTypes[i]); param = InjectionUtils.updateParamClassToTypeIfNeeded(param, genericParam);
protected boolean isValidClassResourceInfo(ClassResourceInfo cri) { Class<?> serviceCls = cri.getServiceClass(); return !(cri.isCreatedFromModel() && serviceCls == cri.getResourceClass() && !InjectionUtils.isConcreteClass(serviceCls)); }
private void injectProperties(Object instance, Map<String, List<String>> props) { if (props == null || props.isEmpty()) { return; } Method[] methods = instance.getClass().getMethods(); Map<String, Method> methodsMap = new HashMap<>(); for (Method m : methods) { methodsMap.put(m.getName(), m); } for (Map.Entry<String, List<String>> entry : props.entrySet()) { Method m = methodsMap.get("set" + Character.toUpperCase(entry.getKey().charAt(0)) + entry.getKey().substring(1)); if (m != null) { Class<?> type = m.getParameterTypes()[0]; Object value; if (InjectionUtils.isPrimitive(type)) { value = PrimitiveUtils.read(entry.getValue().get(0), type); } else { value = entry.getValue(); } InjectionUtils.injectThroughMethod(instance, m, value); } } }
value = decodeValue(value, decoded, pType); result = createFromParameterHandler(value, pClass, genericType, paramAnns, message); } catch (IllegalArgumentException nfe) { throw createParamConversionException(pType, nfe); throw createParamConversionException(pType, nfe); throw ex; } catch (Exception ex) { Throwable t = getOrThrowActualException(ex); LOG.warning(new org.apache.cxf.common.i18n.Message("CLASS_CONSTRUCTOR_FAILURE", BUNDLE, ? new String[] {"fromString", "fromValue", "valueOf"} : new String[] {"valueOf", "fromString"}; result = evaluateFactoryMethods(value, pType, result, cls, methodNames); reportServerError("WRONG_PARAMETER_TYPE", pClass.getName()); return pClass.cast(result); } catch (ClassCastException ex) { reportServerError("WRONG_PARAMETER_TYPE", pClass.getName()); return null;
value = decodeValue(value, decoded, pType); Object result = instantiateFromParameterHandler(value, cls, paramAnns, message); if (result != null) { return pClass.cast(result); throw ex; } catch (Exception ex) { result = createFromParameterHandler(value, cls, paramAnns, message); if (result == null) { LOG.severe(new org.apache.cxf.common.i18n.Message("CLASS_CONSTRUCTOR_FAILURE", : new String[] {"valueOf", "fromString"}; for (String mName : methodNames) { result = evaluateFactoryMethod(value, cls, pType, mName); if (result != null) { break; result = createFromParameterHandler(value, cls, paramAnns, message); reportServerError("WRONG_PARAMETER_TYPE", pClass.getName());
Type secondType = InjectionUtils.getType(paramType.getActualTypeArguments(), 1); Class<?> valueType = (Class<?>) InjectionUtils.getType(valueParamType .getActualTypeArguments(), 0); List<String> valuesList = processedValuesEntry.getValue(); for (String value : valuesList) { Object o = InjectionUtils.handleParameter(value, decoded, valueType, valueType, paramAnns, pathParam, message); theValues.add(convertStringToPrimitive(processedValuesEntry.getKey(), keyType), o); (Class<?>) InjectionUtils.getType(paramType.getActualTypeArguments(), 1); for (Map.Entry<String, List<String>> processedValuesEntry : processedValues.entrySet()) { List<String> valuesList = processedValuesEntry.getValue(); for (String value : valuesList) { Object o = InjectionUtils.handleParameter(value, decoded, valueType, valueType, paramAnns, pathParam, message); theValues.put( convertStringToPrimitive(processedValuesEntry.getKey(), keyType), o);
public static Object convertStringToPrimitive(String value, Class<?> cls) { return convertStringToPrimitive(value, cls, new Annotation[]{}); } public static Object convertStringToPrimitive(String value, Class<?> cls, Annotation[] anns) {
public static Object convertStringToPrimitive(String value, Class<?> cls, Annotation[] anns) { Message m = JAXRSUtils.getCurrentMessage(); Object obj = createFromParameterHandler(value, cls, cls, anns, m); if (obj != null) { return obj; } else if (cls.isEnum()) { if (m != null && !MessageUtils.getContextualBoolean(m, ENUM_CONVERSION_CASE_SENSITIVE, false)) { obj = invokeValueOf(value.toUpperCase(), cls); obj = invokeValueOf(value, cls); } catch (RuntimeException ex) { if (m == null) { obj = invokeValueOf(value.toUpperCase(), cls); } else { throw ex; return invokeValueOf(value, cls);