Java Code Examples for org.apache.commons.beanutils.DynaProperty#getName()
The following examples show how to use
org.apache.commons.beanutils.DynaProperty#getName() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ObjectUtil.java From kfs with GNU Affero General Public License v3.0 | 6 votes |
/** * build a map of business object with its specified property names and corresponding values * * @param businessObject the given business object * @param the specified fields that need to be included in the return map * @return the map of business object with its property names and values */ public static Map<String, Object> buildPropertyMap(Object object, List<String> keyFields) { DynaClass dynaClass = WrapDynaClass.createDynaClass(object.getClass()); DynaProperty[] properties = dynaClass.getDynaProperties(); Map<String, Object> propertyMap = new LinkedHashMap<String, Object>(); for (DynaProperty property : properties) { String propertyName = property.getName(); if (PropertyUtils.isReadable(object, propertyName) && keyFields.contains(propertyName)) { try { Object propertyValue = PropertyUtils.getProperty(object, propertyName); if (propertyValue != null && !StringUtils.isEmpty(propertyValue.toString())) { propertyMap.put(propertyName, propertyValue); } } catch (Exception e) { LOG.info(e); } } } return propertyMap; }
Example 2
Source File: ObjectUtil.java From kfs with GNU Affero General Public License v3.0 | 6 votes |
/** * determine if the source object has a field with null as its value * * @param sourceObject the source object */ public static boolean hasNullValueField(Object sourceObject) { DynaClass dynaClass = WrapDynaClass.createDynaClass(sourceObject.getClass()); DynaProperty[] properties = dynaClass.getDynaProperties(); for (DynaProperty property : properties) { String propertyName = property.getName(); if (PropertyUtils.isReadable(sourceObject, propertyName)) { try { Object propertyValue = PropertyUtils.getProperty(sourceObject, propertyName); if (propertyValue == null) { return true; } } catch (Exception e) { LOG.info(e); return false; } } } return false; }
Example 3
Source File: DynaBeanAdapter.java From reflectutils with Apache License 2.0 | 5 votes |
public List<String> getPropertyNames(Object bean) { List<String> names = new ArrayList<String>(); DynaProperty origDescriptors[] = ((DynaBean) bean).getDynaClass().getDynaProperties(); for (DynaProperty dynaProperty : origDescriptors) { String name = dynaProperty.getName(); names.add(name); } return names; }
Example 4
Source File: TestConfigurationDynaBean.java From commons-configuration with Apache License 2.0 | 5 votes |
/** * Positive test for getDynaPropertys(). Each property name * listed in {@code properties} should be returned exactly once. */ @Test public void testGetDescriptors() { final DynaProperty pd[] = bean.getDynaClass().getDynaProperties(); assertNotNull("Got descriptors", pd); final int count[] = new int[properties.length]; for (final DynaProperty element : pd) { final String name = element.getName(); for (int j = 0; j < properties.length; j++) { if (name.equals(properties[j])) { count[j]++; } } } for (int j = 0; j < properties.length; j++) { if (count[j] < 0) { fail("Missing property " + properties[j]); } else if (count[j] > 1) { fail("Duplicate property " + properties[j]); } } }