/** * Set multiple properties of a bean at once using a Map. Any unknown properties * shall be ignored. * * @param obj The object to be manipulated. * @param valueMap Map containing property-name (String) / property-value (Object) * pairs to set in the object. * @param allowedProperties If array is NOT null, only the properties matching names * passed here shall be set. */ public final static void setValues(Object obj, Map valueMap, String[] allowedProperties) { Iterator keys = valueMap.keySet().iterator(); while (keys.hasNext()) { String property = keys.next().toString(); Object value = valueMap.get(property); if (allowed(property, allowedProperties)) { setValue(obj, property, value); } } }
/** * Set multiple properties of a bean at once using a Map. Any unknown properties * shall be ignored. * * @param obj The object to be manipulated. * @param valueMap Map containing property-name (String) / property-value (Object) * pairs to set in the object. * @param allowedProperties If array is NOT null, only the properties matching names * passed here shall be set. */ public final static void setValues(Object obj, Map valueMap, String[] allowedProperties) { Iterator keys = valueMap.keySet().iterator(); while (keys.hasNext()) { String property = keys.next().toString(); Object value = valueMap.get(property); if (allowed(property, allowedProperties)) { setValue(obj, property, value); } } }
/** * Get Map of property values from a bean. * * @param obj Object to query for properties. * @param allowedProperties If array is NOT null, only the properties matching names * passed here shall be retrieved. * @return Map containing property-name (String) / property-value (Object) pairs. */ public final static Map getValues(Object obj, String[] allowedProperties) { Map result = new HashMap(); String[] propertyNames = getPropertyNames(obj); for (int i = 0; i < propertyNames.length; i++) { String propertyName = propertyNames[i]; Object propertyValue = getValue(obj, propertyName); if ((propertyName == null) || (propertyValue == null)) { continue; } if (allowed(propertyName, allowedProperties)) { result.put(propertyName, propertyValue); } } return result; }
/** * Get Map of property values from a bean. * * @param obj Object to query for properties. * @param allowedProperties If array is NOT null, only the properties matching names * passed here shall be retrieved. * @return Map containing property-name (String) / property-value (Object) pairs. */ public final static Map getValues(Object obj, String[] allowedProperties) { Map result = new HashMap(); String[] propertyNames = getPropertyNames(obj); for (int i = 0; i < propertyNames.length; i++) { String propertyName = propertyNames[i]; Object propertyValue = getValue(obj, propertyName); if ((propertyName == null) || (propertyValue == null)) { continue; } if (allowed(propertyName, allowedProperties)) { result.put(propertyName, propertyValue); } } return result; }