castedValue = InjectionUtils.convertStringToPrimitive(value, actualType);
if (isCollection) {
castedValue = getCollectionSingleton(valueType, castedValue);
}
} catch (Exception e) {
throw new SearchParseException("Cannot convert String value \"" + value
+ "\" to a value of class " + valueType.getName(), e);
}
} else {
Class<?> classType = isCollection ? valueType : value.getClass();
try {
Method setterM = valueType.getMethod("set" + getMethodNameSuffix(setter),
new Class[]{classType});
Object objectValue = !isCollection ? value : getCollectionSingleton(valueType, value);
setterM.invoke(ownerBean, new Object[]{objectValue});
castedValue = objectValue;
} catch (Throwable ex) {
throw new SearchParseException("Cannot convert String value \"" + value
+ "\" to a value of class " + valueType.getName(), ex);
}
}
}
if (lastCastedValue != null) {
castedValue = lastCastedValue;
}
return castedValue;
} else {
String[] names = setter.split("\\.");
try {
String nextPart = getMethodNameSuffix(names[1]);
Method getterM = actualType.getMethod("get" + nextPart, new Class[]{});
Class<?> returnType = getterM.getReturnType();
boolean returnCollection = InjectionUtils.isSupportedCollectionOrArray(returnType);
boolean isPrimitive = InjectionUtils.isPrimitive(returnType) || returnType.isEnum();
boolean lastTry = names.length == 2
&& (isPrimitive || returnType == Date.class || returnCollection);
Object valueObject = lastTry && ownerBean != null ? ownerBean : actualType.newInstance();
Object nextObject;
if (lastTry) {
if (!returnCollection) {
nextObject = isPrimitive ? InjectionUtils.convertStringToPrimitive(value, returnType)
: convertToDate(value);
} else {
nextObject = Collections.singletonList(value);
}
} else {
nextObject = returnType.newInstance();
}
Method setterM = actualType.getMethod("set" + nextPart, new Class[]{returnType});
setterM.invoke(valueObject, new Object[]{nextObject});
lastCastedValue = lastCastedValue == null ? valueObject : lastCastedValue;
if (lastTry) {
return isCollection ? Collections.singletonList(lastCastedValue) : lastCastedValue;
}
TypeInfo nextTypeInfo = new TypeInfo(nextObject.getClass(), getterM.getGenericReturnType());
return parseType(nextObject, lastCastedValue, setter.substring(index + 1),
nextTypeInfo, value);
} catch (Throwable e) {
throw new SearchParseException("Cannot convert String value \"" + value
+ "\" to a value of class " + valueType.getName(), e);
}
}
}