} else if (isCollection) {
typeInfo.setCollectionCheckInfo(new CollectionCheckInfo(collCheck, castedValue));
castedValue = getEmptyCollection(valueType);
}
} 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);
Class<?> actualReturnType = !returnCollection ? returnType
: InjectionUtils.getActualType(getterM.getGenericReturnType());
boolean isPrimitive = !returnCollection
&& InjectionUtils.isPrimitive(returnType) || returnType.isEnum();
boolean lastTry = names.length == 2
&& (isPrimitive || Date.class.isAssignableFrom(returnType) || returnCollection);
Object valueObject = ownerBean != null ? ownerBean
: actualType.isInterface()
? Proxy.newProxyInstance(this.getClass().getClassLoader(),
new Class[]{actualType},
new InterfaceProxy())
: actualType.newInstance();
Object nextObject;
if (lastTry) {
if (!returnCollection) {
nextObject = isPrimitive ? InjectionUtils.convertStringToPrimitive(value, returnType)
: convertToDate(returnType, value);
} else {
CollectionCheck collCheck = getCollectionCheck(originalPropName, true, actualReturnType);
if (collCheck == null) {
nextObject = getCollectionSingleton(valueType, value);
} else {
typeInfo.setCollectionCheckInfo(new CollectionCheckInfo(collCheck, value));
nextObject = getEmptyCollection(valueType);
}
}
} else if (!returnCollection) {
nextObject = returnType.newInstance();
} else {
nextObject = actualReturnType.newInstance();
}
Method setterM = actualType.getMethod("set" + nextPart, new Class[]{returnType});
Object valueObjectValue = lastTry || !returnCollection
? nextObject : getCollectionSingleton(valueType, nextObject);
setterM.invoke(valueObject, new Object[]{valueObjectValue});
if (lastTry) {
lastCastedValue = lastCastedValue == null ? valueObject : lastCastedValue;
return isCollection ? getCollectionSingleton(valueType, lastCastedValue) : lastCastedValue;
} else {
lastCastedValue = valueObject;
}
TypeInfo nextTypeInfo = new TypeInfo(valueObjectValue.getClass(), getterM.getGenericReturnType());
Object response = parseType(originalPropName,
nextObject,
lastCastedValue,
setter.substring(index + 1),
nextTypeInfo,
value);
if (ownerBean == null) {
return isCollection ? getCollectionSingleton(valueType, lastCastedValue) : lastCastedValue;
} else {
return response;
}
} catch (Throwable e) {
throw new SearchParseException("Cannot convert String value \"" + value
+ "\" to a value of class " + valueType.getName(), e);
}
}
}