List of usage examples for org.apache.commons.beanutils PropertyUtils getProperty
public static Object getProperty(Object bean, String name) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException
Return the value of the specified property of the specified bean, no matter which property reference format is used, with no type conversions.
For more details see PropertyUtilsBean
.
From source file:com.fuxian.yuncai.common.util.CollectionUtils.java
/** * ????(Getter), ??Map.//from w ww . j a v a 2s . c o m * @param collection Map<String,Map> * @param keyPropertyName * @param valuePropertyNames ????? * @return */ @SuppressWarnings({ "rawtypes", "unchecked" }) public static Map extractToMaps(final Collection collection, final String keyPropertyName, final String[] valuePropertyNames) { if (collection == null || collection.size() == 0) { return new HashMap(); } Map map = new HashMap(collection.size()); try { for (Object obj : collection) { Map mapParam = null; if (valuePropertyNames != null && valuePropertyNames.length > 0) { mapParam = new HashMap(valuePropertyNames.length); for (String valuePropertyName : valuePropertyNames) { mapParam.put(valuePropertyName, PropertyUtils.getProperty(obj, valuePropertyName)); } } Object keyPropertyNameValue = PropertyUtils.getProperty(obj, keyPropertyName); if (keyPropertyNameValue != null) { map.put(PropertyUtils.getProperty(obj, keyPropertyName), mapParam); } else { continue; } } } catch (Exception e) { throw ReflectionUtils.convertReflectionExceptionToUnchecked(e); } return map; }
From source file:com.monits.commons.validation.FieldMatchValidator.java
@Override public boolean isValid(final Object value, final ConstraintValidatorContext context) { try {//w ww . java 2 s . c om final Object firstObj = PropertyUtils.getProperty(value, firstFieldName); final Object secondObj = PropertyUtils.getProperty(value, secondFieldName); return type.isValid(firstObj, secondObj); } catch (final Exception ignore) { // ignore return false; } }
From source file:com.qumoon.commons.BeanMapper.java
public static <T extends com.google.protobuf.GeneratedMessage> T convertBean2Proto( com.google.protobuf.GeneratedMessage.Builder message, Object srcObject) throws Exception { for (Field srcField : srcObject.getClass().getDeclaredFields()) { Object value = PropertyUtils.getProperty(srcObject, srcField.getName()); if (value == null) { continue; }/* w w w . j a v a 2 s . c om*/ Descriptors.FieldDescriptor fd = message.getDescriptorForType().findFieldByName(srcField.getName()); if (null == fd) { continue; } if (srcField.getType() == BigDecimal.class) { message.setField(fd, ((BigDecimal) value).toString()); continue; } else { if (srcField.getType() == Date.class) { message.setField(fd, ((Date) value).getTime()); continue; } else { message.setField(fd, value); } } } return (T) message.build(); }
From source file:com.mindquarry.persistence.jcr.model.DefaultProperty.java
public Object getContent(Object bean) { try {//from www. ja v a2 s.c o m return PropertyUtils.getProperty(bean, getName()); } catch (IllegalAccessException e) { throw new JcrPersistenceInternalException(e); } catch (InvocationTargetException e) { throw new JcrPersistenceInternalException(e); } catch (NoSuchMethodException e) { throw new JcrPersistenceInternalException(e); } }
From source file:com.xyz.util.WebDataUtil.java
/** * ?ID?,???./* www. j av a 2 s . c o m*/ * * ??????id,??????id?????. * ???id?ID?,?ID?id??. * * @param srcObjects ?? * @param checkedIds ID? * @param clazz ? * @param idName ?? */ public static <T, ID> void mergeByCheckedIds(final Collection<T> srcObjects, final Collection<ID> checkedIds, final Class<T> clazz, final String idName) { //? Assert.notNull(srcObjects, "scrObjects?"); Assert.hasText(idName, "idName?"); Assert.notNull(clazz, "clazz?"); //ID?,???. if (checkedIds == null) { srcObjects.clear(); return; } //????,id?ID?,. //?,ID???id,ID?id???ID. Iterator<T> srcIterator = srcObjects.iterator(); try { while (srcIterator.hasNext()) { T element = srcIterator.next(); Object id; id = PropertyUtils.getProperty(element, idName); if (!checkedIds.contains(id)) { srcIterator.remove(); } else { checkedIds.remove(id); } } //ID??id????,,id??. for (ID id : checkedIds) { T obj = clazz.newInstance(); PropertyUtils.setProperty(obj, idName, id); srcObjects.add(obj); } } catch (Exception e) { throw ReflectionUtil.convertToUncheckedException(e); } }
From source file:net.sourceforge.fenixedu.util.domain.SlotSelector.java
@Override public Collection<ObjectType> getObjects(HolderType holder) { try {// w w w .ja v a 2s .c o m return (Collection<ObjectType>) PropertyUtils.getProperty(holder, this.relationName); } catch (IllegalAccessException e) { throw new DomainException("adapter.ordered.relation.no.slot.access", e); } catch (InvocationTargetException e) { throw handleInvocationTargetException(e, "adapter.ordered.relation.invocation.exception"); } catch (NoSuchMethodException e) { throw new DomainException("adapter.ordered.relation.no.slot", e); } }
From source file:net.jcreate.e3.table.model.AbstractDataModel.java
/** * ?//from w ww . jav a 2s . c o m * @param pItem next? * @param pProperty ?? * @return ? */ public Object getCellValue(Object pItem, String pProperty) { if (pItem == null) { return null; } Object itemValue = null; if (pItem instanceof Map) { itemValue = ((Map) pItem).get(pProperty); } else { try { itemValue = PropertyUtils.getProperty(pItem, pProperty); } catch (Exception ex) { if (logger.isDebugEnabled()) { logger.debug(":" + pItem.getClass().getName() + "?:" + pProperty); } } //end try-catch } //end else return itemValue; }
From source file:com.mycollab.module.crm.ui.components.RelatedReadItemField.java
@Override protected Component initContent() { try {/*from ww w . j a v a 2 s .c om*/ final Integer typeId = (Integer) PropertyUtils.getProperty(RelatedReadItemField.this.bean, "typeid"); if (typeId == null) { return new Label(""); } final String type = (String) PropertyUtils.getProperty(bean, "type"); if (type == null || type.equals("")) { return new Label(""); } FontAwesome relatedLink = null; String relateItemName = null; if (CrmTypeConstants.ACCOUNT.equals(type)) { AccountService accountService = AppContextUtil.getSpringBean(AccountService.class); final SimpleAccount account = accountService.findById(typeId, MyCollabUI.getAccountId()); if (account != null) { relateItemName = account.getAccountname(); relatedLink = CrmAssetsManager.getAsset(CrmTypeConstants.ACCOUNT); } } else if (CrmTypeConstants.CAMPAIGN.equals(type)) { CampaignService campaignService = AppContextUtil.getSpringBean(CampaignService.class); final SimpleCampaign campaign = campaignService.findById(typeId, MyCollabUI.getAccountId()); if (campaign != null) { relateItemName = campaign.getCampaignname(); relatedLink = CrmAssetsManager.getAsset(CrmTypeConstants.CAMPAIGN); } } else if (CrmTypeConstants.CONTACT.equals(type)) { ContactService contactService = AppContextUtil.getSpringBean(ContactService.class); final SimpleContact contact = contactService.findById(typeId, MyCollabUI.getAccountId()); if (contact != null) { relateItemName = contact.getContactName(); relatedLink = CrmAssetsManager.getAsset(CrmTypeConstants.CONTACT); } } else if (CrmTypeConstants.LEAD.equals(type)) { LeadService leadService = AppContextUtil.getSpringBean(LeadService.class); final SimpleLead lead = leadService.findById(typeId, MyCollabUI.getAccountId()); if (lead != null) { relateItemName = lead.getLeadName(); relatedLink = CrmAssetsManager.getAsset(CrmTypeConstants.LEAD); } } else if (CrmTypeConstants.OPPORTUNITY.equals(type)) { OpportunityService opportunityService = AppContextUtil.getSpringBean(OpportunityService.class); final SimpleOpportunity opportunity = opportunityService.findById(typeId, MyCollabUI.getAccountId()); if (opportunity != null) { relateItemName = opportunity.getOpportunityname(); relatedLink = CrmAssetsManager.getAsset(CrmTypeConstants.OPPORTUNITY); } } else if (CrmTypeConstants.CASE.equals(type)) { CaseService caseService = AppContextUtil.getSpringBean(CaseService.class); final SimpleCase cases = caseService.findById(typeId, MyCollabUI.getAccountId()); if (cases != null) { relateItemName = cases.getSubject(); relatedLink = CrmAssetsManager.getAsset(CrmTypeConstants.CASE); } } LabelLink related = new LabelLink(relateItemName, CrmLinkBuilder.generateActivityPreviewLinkFull(type, typeId)); if (relatedLink != null) related.setIconLink(relatedLink); if (relatedLink != null) { return related; } else { return new Label(""); } } catch (Exception e) { return new Label(""); } }
From source file:ar.com.fdvs.dj.util.MultiPropertyComparator.java
private static Comparable getValue(final Object _object, final String _field) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException { final Object value = PropertyUtils.getProperty(_object, _field); if (value == null) return null; if (!(value instanceof Comparable)) throw new RuntimeException("Objects are not Comparable, class " + value.getClass().getName()); return (Comparable) value; }
From source file:com.gisgraphy.helper.BeanHelper.java
private boolean compareProperty(final Object object1, final Object object2, final String propertyName) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException { final Object object1PropValue = PropertyUtils.getProperty(object1, propertyName); final Object object2PropValue = PropertyUtils.getProperty(object2, propertyName); if (object1PropValue == null) { return object2PropValue == null; }/*w w w. j av a2 s . c o m*/ return object1PropValue.equals(object2PropValue); }