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.google.code.simplestuff.bean.BusinessObjectAnnotationParser.java
/** * Retrieves a "field-value" map of all properties of the given * object annotated as <code>BusinessField</code>s. * <p>// w w w . j a v a2 s. co m * These should constitute a "business key" for this object * * @param object the object whose properties should be examined * @return a map of all appropriately annotated fields */ static Map<String, Object> retrieveBusinessFields(Object object) { Map<String, Object> businessProperties = new HashMap<String, Object>(); for (Field field : collectAnnotatedFields(object.getClass())) { String propertyName = field.getName(); try { businessProperties.put(propertyName, PropertyUtils.getProperty(object, propertyName)); } catch (Exception exception) { // ignore any of the exceptions that can be thrown and simply // skip the property } } return businessProperties; }
From source file:com.open.cas.shiro.util.CollectionsUtils.java
/** * ????(Getter), ??Map./* ww w .jav a 2s. co m*/ * * @param collection ???. * @param keyPropertyName ????MapKey??. */ public static Map extractToMap(final Collection collection, final String keyPropertyName) { Map map = new HashMap(); try { for (Object obj : collection) { map.put(PropertyUtils.getProperty(obj, keyPropertyName), obj); } } catch (Exception e) { throw ReflectionUtils.convertReflectionExceptionToUnchecked(e); } return map; }
From source file:de.hybris.platform.commercefacades.address.converters.populator.SingleLineAddressFormatPopulator.java
@Override public void populate(final AddressModel addressModel, final StringBuilder addressLine) throws ConversionException { for (final String field : addressFormatList) { try {// ww w . j av a 2s . c om final String fieldValue = (String) PropertyUtils.getProperty(addressModel, field); if (fieldValue != null) { addressLine.append(fieldValue); addressLine.append(", "); } } catch (final NestedNullException e) { if (LOG.isDebugEnabled()) { LOG.debug(e.getLocalizedMessage()); } } catch (final Exception e) { throw new ConversionException(e.getLocalizedMessage()); } } if (addressLine.length() > 2) { // Trim last ", " addressLine.setLength(addressLine.length() - 2); } }
From source file:com.discursive.jccook.collections.predicate.PropertyPredicate.java
public boolean evaluate(Object object) { boolean propertyFound = false; try {//from w w w . java 2 s . c om Object value = PropertyUtils.getProperty(object, property); if (value != null) { if (matchValue != null) { propertyFound = matchValue.equals(value); } else { propertyFound = true; } } } catch (Exception e) { // If there was an exception, the predicate returns false } return propertyFound; }
From source file:$.Collections3.java
/** * ????(Getter), ??List./*from ww w . jav a 2s . c o m*/ * * @param collection ???. * @param propertyName ??????. */ public static List extractToList(final Collection collection, final String propertyName) { List list = new ArrayList(collection.size()); try { for (Object obj : collection) { list.add(PropertyUtils.getProperty(obj, propertyName)); } } catch (Exception e) { throw Reflections.convertReflectionExceptionToUnchecked(e); } return list; }
From source file:com.create.validation.RequiredOnPropertyValueValidator.java
@Override public boolean isValid(Object value, ConstraintValidatorContext context) { try {/*from w w w . ja va 2 s . co m*/ final Object propertyValue = PropertyUtils.getProperty(value, requiredOnPropertyValue.property()); final Object requiredPropertyValue = PropertyUtils.getProperty(value, requiredOnPropertyValue.requiredProperty()); return propertyValue == null || isRequiredOnPropertyValue(propertyValue, requiredPropertyValue); } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) { throw new IllegalArgumentException(e); } }
From source file:net.sf.jabb.util.text.CollectionFormatter.java
/** * Format a collection's elements' properties to delimiter separated string.<br> * Usage examples: <br>/*from www .j av a 2 s.c om*/ * <code> * CollectionFormatter.format(myCollection, null, ","); * CollectionFormatter.format(myCollection, "personInCharge.name.firstName", ", "); * CollectionFormatter.format(myCollection, "relatedPeople(InCharge).name", ", "); * CollectionFormatter.format(myCollection, "subordinate[3].address(home).city", " | "); * </code> * @param collection The collection that will be formatted * @param property The property of the collection's element that will be put into the result string. * Please see PropertyUtils.getProperty() of commons-beanutils for detail. * Use null if the element itself needs to be put into the result string. * @param separator Used in the result string to separate each element. * @param trim true if the property need to be trimmed, false if not. * @return A string containing separated properties of the collection's elements */ static public String format(Collection<?> collection, String property, String separator, boolean trim) { StringBuilder sb = new StringBuilder(); if (collection != null) { for (Object o : collection) { Object p = null; if (property == null) { p = o; } else { try { p = PropertyUtils.getProperty(o, property); } catch (Exception e) { p = "ACCESS_ERROR:" + property; } } sb.append(p == null ? "null" : (trim ? p.toString().trim() : p.toString())); sb.append(separator); } } if (sb.length() > 0) { sb.setLength(sb.length() - separator.length()); } return sb.toString(); }
From source file:com.yunmel.syncretic.utils.commons.CollectionsUtils.java
/** * ????(Getter), ??List./*from w w w .j a v a 2s . c om*/ * * @param collection ???. * @param propertyName ??????. */ @SuppressWarnings("unchecked") public static List extractToList(final Collection collection, final String propertyName) { List list = Lists.newArrayList(collection.size()); try { for (Object obj : collection) { list.add(PropertyUtils.getProperty(obj, propertyName)); } } catch (Exception e) { throw Reflections.convertReflectionExceptionToUnchecked(e); } return list; }
From source file:com.cyclopsgroup.waterview.utils.TagSupport.java
/** * Throw MissingAttributeException if an attribute is missing * * @param name Attribute name//from w ww . j ava 2s . co m * @throws JellyTagException Throw it out */ protected final void requireAttribute(String name) throws JellyTagException { Object value = null; try { value = PropertyUtils.getProperty(this, name); } catch (Exception e) { throw new JellyTagException("Attribute [" + name + "] is not defined in tag"); } if (value == null) { throw new MissingAttributeException(name); } }
From source file:com.nec.nsgui.taglib.nssorttab.ListSTModel.java
public Object getValueAt(int rowIndex, String colName) throws Exception { Object object;// ww w .j ava 2s . c om Object rtnValue = null; if (dataList == null || dataList.size() == 0 || colName == null || colName.trim().equals("")) { return null; } if (rowIndex < 0 || rowIndex >= getRowCount()) { return null; } object = dataList.get(rowIndex); if (object == null) { return null; } try { rtnValue = PropertyUtils.getProperty(object, colName); } catch (Exception e) { throw e; } return rtnValue; }