use of org.eclipse.scout.rt.platform.reflect.FastBeanInfo in project scout.rt by eclipse.
the class BeanUtility method setProperties.
/**
* @param lenient
* true just logs warnings on exceptions, false throws exceptions set all properties on to, filtering with
* filter
*/
public static void setProperties(Object to, Map<String, Object> map, boolean lenient, IPropertyFilter filter) {
FastBeanInfo toInfo = getFastBeanInfo(to.getClass(), null);
for (Iterator<Map.Entry<String, Object>> it = map.entrySet().iterator(); it.hasNext(); ) {
Map.Entry<String, Object> entry = it.next();
String name = entry.getKey();
Object value = entry.getValue();
try {
FastPropertyDescriptor desc = toInfo.getPropertyDescriptor(name);
if (desc != null && (filter == null || filter.accept(desc))) {
Method writeMethod = desc.getWriteMethod();
if (writeMethod != null) {
writeMethod.invoke(to, new Object[] { TypeCastUtility.castValue(value, writeMethod.getParameterTypes()[0]) });
}
}
} catch (Exception e) {
if (lenient) {
LOG.warn("Could not set property property '{}' to value '{}'", name, value, e);
} else {
throw new ProcessingException("property " + name + " with value " + value, e);
}
}
}
}
Aggregations