List of usage examples for org.apache.commons.beanutils PropertyUtils isReadable
public static boolean isReadable(Object bean, String name)
Return true
if the specified property name identifies a readable property on the specified bean; otherwise, return false
.
For more details see PropertyUtilsBean
.
From source file:org.hx.rainbow.common.util.JavaBeanUtil.java
/** * bean??bean???/*from w ww. java2 s.com*/ * zhf 2012-5-14 [] BeanUtils.copyPropertiescopy * @param fromBean * @param toBean */ public static void copyProperties(Object fromBean, Object toBean) { if (fromBean == null || toBean == null) { return; } try { // BeanUtils.copyProperties(toBean, fromBean); PropertyDescriptor origDescriptors[] = PropertyUtils.getPropertyDescriptors(toBean); for (int i = 0; i < origDescriptors.length; i++) { String name = origDescriptors[i].getName(); if (name.equals("class")) { continue; } //if (PropertyUtils.isReadable(fromBean, name)||PropertyUtils.isWriteable(toBean, name)) { if (PropertyUtils.isReadable(fromBean, name) && PropertyUtils.isWriteable(toBean, name)) { Object obj = PropertyUtils.getProperty(fromBean, name); if (obj == null) { continue; } obj = convertValue(origDescriptors[i], obj); BeanUtils.copyProperty(toBean, name, obj); } } // for end } catch (Exception e) { e.printStackTrace(); throw new AppException(e.getMessage()); } }
From source file:org.kuali.ext.mm.ObjectUtil.java
/** * Populate the given fields of the target object with the corresponding field values of source object * * @param targetObject the target object * @param sourceObject the source object * @param keyFields the given fields of the target object that need to be popluated *//*from www . j av a 2s . co m*/ public static void buildObject(Object targetObject, Object sourceObject, List<String> keyFields) { if (sourceObject.getClass().isArray()) { buildObject(targetObject, sourceObject, keyFields); return; } for (String propertyName : keyFields) { if (PropertyUtils.isReadable(sourceObject, propertyName) && PropertyUtils.isWriteable(targetObject, propertyName)) { try { Object propertyValue = PropertyUtils.getProperty(sourceObject, propertyName); PropertyUtils.setProperty(targetObject, propertyName, propertyValue); } catch (Exception e) { LOG.debug(e); } } } }
From source file:org.kuali.ext.mm.ObjectUtil.java
/** * Populate the property of the target object with the counterpart of the source object * * @param targetObject the target object * @param sourceObject the source object * @param property the specified propety of the target object * @param skipReferenceFields determine whether the referencing fields need to be populated *///from w ww.j a va2s .c o m public static void setProperty(Object targetObject, Object sourceObject, DynaProperty property, boolean skipReferenceFields) { String propertyName = property.getName(); try { if (skipReferenceFields) { Class propertyType = property.getType(); if (propertyType == null || PersistableBusinessObjectBase.class.isAssignableFrom(propertyType) || List.class.isAssignableFrom(propertyType)) { return; } } if (PropertyUtils.isReadable(sourceObject, propertyName) && PropertyUtils.isWriteable(targetObject, propertyName)) { Object propertyValue = PropertyUtils.getProperty(sourceObject, propertyName); PropertyUtils.setProperty(targetObject, propertyName, propertyValue); } } catch (IllegalAccessException e) { LOG.debug(e.getMessage() + ":" + propertyName); } catch (InvocationTargetException e) { LOG.debug(e.getMessage() + ":" + propertyName); } catch (NoSuchMethodException e) { LOG.debug(e.getMessage() + ":" + propertyName); } catch (IllegalArgumentException e) { LOG.debug(e.getMessage() + ":" + propertyName); } catch (Exception e) { LOG.debug(e.getMessage() + ":" + propertyName); } }
From source file:org.kuali.ext.mm.ObjectUtil.java
/** * 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 *//*from w w w . java 2 s .com*/ 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; }
From source file:org.kuali.ext.mm.ObjectUtil.java
/** * concat the specified properties of the given object as a string * * @param object the given object//from w w w . j a va2 s . co m * @param the specified fields that need to be included in the return string * @return the specified properties of the given object as a string */ public static String concatPropertyAsString(Object object, List<String> keyFields) { StringBuilder propertyAsString = new StringBuilder(); for (String field : keyFields) { if (PropertyUtils.isReadable(object, field)) { try { propertyAsString.append(PropertyUtils.getProperty(object, field)); } catch (Exception e) { LOG.error(e); } } } return propertyAsString.toString(); }
From source file:org.kuali.ext.mm.ObjectUtil.java
/** * determine if the source object has a field with null as its value * * @param sourceObject the source object *///from w w w.j av a 2s. c o m 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; }
From source file:org.kuali.kfs.sys.businessobject.inquiry.KfsInquirableImpl.java
/** * Helper method to build an inquiry url for a result field. Special implementation to not build an inquiry link if the value is * all dashes./*from www. j a va 2 s . com*/ * * @param bo the business object instance to build the urls for * @param propertyName the property which links to an inquirable * @return String url to inquiry */ public HtmlData getInquiryUrl(BusinessObject businessObject, String attributeName, boolean forceInquiry) { try { if (PropertyUtils.isReadable(businessObject, attributeName)) { Object objFieldValue = ObjectUtils.getPropertyValue(businessObject, attributeName); String fieldValue = objFieldValue == null ? KFSConstants.EMPTY_STRING : objFieldValue.toString(); if (StringUtils.containsOnly(fieldValue, KFSConstants.DASH)) { return new AnchorHtmlData(); } } return super.getInquiryUrl(businessObject, attributeName, forceInquiry); } catch (Exception ex) { LOG.error("Unable to determine inquiry link for BO Class: " + businessObject.getClass() + " and property " + attributeName); LOG.debug("Unable to determine inquiry link for BO Class: " + businessObject.getClass() + " and property " + attributeName, ex); return new AnchorHtmlData(); } }
From source file:org.kuali.kfs.sys.ObjectUtil.java
/** * Populate the property of the target object with the counterpart of the source object * /*from w w w .j av a 2s.c o m*/ * @param targetObject the target object * @param sourceObject the source object * @param property the specified propety of the target object * @param skipReferenceFields determine whether the referencing fields need to be populated */ public static void setProperty(Object targetObject, Object sourceObject, DynaProperty property, boolean skipReferenceFields) { String propertyName = property.getName(); try { if (skipReferenceFields) { @SuppressWarnings("rawtypes") Class propertyType = property.getType(); if (propertyType == null || PersistableBusinessObjectBase.class.isAssignableFrom(propertyType) || List.class.isAssignableFrom(propertyType)) { return; } } if (PropertyUtils.isReadable(sourceObject, propertyName) && PropertyUtils.isWriteable(targetObject, propertyName)) { Object propertyValue = PropertyUtils.getProperty(sourceObject, propertyName); PropertyUtils.setProperty(targetObject, propertyName, propertyValue); } } catch (IllegalAccessException e) { if (LOG.isDebugEnabled()) { LOG.debug(e.getMessage() + ":" + propertyName); } } catch (InvocationTargetException e) { if (LOG.isDebugEnabled()) { LOG.debug(e.getMessage() + ":" + propertyName); } } catch (NoSuchMethodException e) { if (LOG.isDebugEnabled()) { LOG.debug(e.getMessage() + ":" + propertyName); } } catch (IllegalArgumentException e) { if (LOG.isDebugEnabled()) { LOG.debug(e.getMessage() + ":" + propertyName); } } catch (Exception e) { if (LOG.isDebugEnabled()) { LOG.debug(e.getMessage() + ":" + propertyName); } } }
From source file:org.kuali.ole.sys.businessobject.inquiry.KfsInquirableImpl.java
/** * Helper method to build an inquiry url for a result field. Special implementation to not build an inquiry link if the value is * all dashes.// w w w . j a va 2 s . c o m * * @param bo the business object instance to build the urls for * @param propertyName the property which links to an inquirable * @return String url to inquiry */ @Override public HtmlData getInquiryUrl(BusinessObject businessObject, String attributeName, boolean forceInquiry) { try { if (PropertyUtils.isReadable(businessObject, attributeName)) { Object objFieldValue = ObjectUtils.getPropertyValue(businessObject, attributeName); String fieldValue = objFieldValue == null ? OLEConstants.EMPTY_STRING : objFieldValue.toString(); if (StringUtils.containsOnly(fieldValue, OLEConstants.DASH)) { return new AnchorHtmlData(); } } return super.getInquiryUrl(businessObject, attributeName, forceInquiry); } catch (Exception ex) { LOG.error("Unable to determine inquiry link for BO Class: " + businessObject.getClass() + " and property " + attributeName); LOG.debug("Unable to determine inquiry link for BO Class: " + businessObject.getClass() + " and property " + attributeName, ex); return new AnchorHtmlData(); } }
From source file:org.kuali.rice.kns.util.FieldUtils.java
private static boolean isPropertyReadable(Object bean, String name) { try {//from ww w . ja va2 s . co m return PropertyUtils.isReadable(bean, name); } catch (NestedNullException e) { return false; } }