use of com.haulmont.cuba.core.global.UserSessionSource in project cuba by cuba-platform.
the class PropertyWrapper method valueOf.
protected Object valueOf(Object newValue) throws Converter.ConversionException {
if (newValue == null) {
return null;
}
final Range range = propertyPath.getRange();
if (range == null) {
return newValue;
} else {
final Object obj;
if (range.isDatatype()) {
Datatype<Object> datatype = range.asDatatype();
if (newValue instanceof String) {
try {
newValue = Strings.emptyToNull((String) newValue);
UserSessionSource sessionSource = AppBeans.get(UserSessionSource.NAME);
obj = datatype.parse((String) newValue, sessionSource.getLocale());
} catch (ParseException e) {
throw new Converter.ConversionException(e);
}
} else {
if (newValue.getClass().equals(datatype.getJavaClass())) {
return newValue;
} else {
Datatype newValueDatatype = Datatypes.getNN(newValue.getClass());
// noinspection unchecked
String str = newValueDatatype.format(newValue);
try {
obj = datatype.parse(str);
} catch (ParseException e) {
throw new Converter.ConversionException(e);
}
}
}
} else {
obj = newValue;
}
return obj;
}
}
Aggregations