use of org.motechproject.mds.web.domain.ComboboxHolder in project motech by motech.
the class InstanceServiceImpl method setProperty.
private void setProperty(Object instance, FieldRecord fieldRecord, MotechDataService service, Long deleteValueFieldId, boolean retainId) throws NoSuchMethodException, ClassNotFoundException, NoSuchFieldException, IllegalAccessException {
String fieldName = fieldRecord.getName();
TypeDto type = getType(fieldRecord);
String methodName = "set" + StringUtils.capitalize(fieldName);
ComboboxHolder holder = type.isCombobox() ? new ComboboxHolder(instance, fieldRecord) : null;
String methodParameterType = getMethodParameterType(type, holder);
ClassLoader classLoader = instance.getClass().getClassLoader();
Class<?> parameterType;
Object parsedValue;
if (Byte[].class.getName().equals(methodParameterType) || byte[].class.getName().equals(methodParameterType)) {
parameterType = getCorrectByteArrayType(methodParameterType);
parsedValue = parseBlobValue(fieldRecord, service, fieldName, deleteValueFieldId, instance);
} else {
parameterType = classLoader.loadClass(methodParameterType);
parsedValue = parseValue(holder, methodParameterType, fieldRecord, classLoader);
}
MetadataDto versionMetadata = fieldRecord.getMetadata(Constants.MetadataKeys.VERSION_FIELD);
validateNonEditableField(fieldRecord, instance, parsedValue, versionMetadata);
Method method = MethodUtils.getAccessibleMethod(instance.getClass(), methodName, parameterType);
if (method == null && TypeHelper.hasPrimitive(parameterType)) {
method = MethodUtils.getAccessibleMethod(instance.getClass(), methodName, TypeHelper.getPrimitive(parameterType));
// if the setter is for a primitive, but we have a null, we leave the default
if (method != null && parsedValue == null) {
return;
}
}
invokeMethod(method, instance, parsedValue, methodName, fieldName);
setTransactionVersion(instance, fieldRecord, retainId, versionMetadata);
}
Aggregations