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.xsw.utils.Collections3.java
/** * ????(Getter), ??List.//from w ww.j a v a 2 s . co m * * @param collection ???. * @param propertyName ??????. */ @SuppressWarnings("all") 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.nerve.commons.repository.utils.ConvertUtils.java
/** * ????javaBean?javabeanproperties?//from w w w . j a va 2 s. c o m * ?nametitle * javabeannamevalue * properties * { * name:name, * title:value * } * ?name?javabeannametitle?value * @param collection * @param properties * @return */ public static List convertElementPropertyToBeanList(final Collection collection, final Map<String, String> properties, Class<?> toType) { List list = new ArrayList(); try { for (Object obj : collection) { Object bean = toType.newInstance(); for (String key : properties.keySet()) { PropertyUtils.setProperty(bean, properties.get(key), PropertyUtils.getProperty(obj, key)); } list.add(bean); } } catch (Exception e) { throw ReflectionUtils.convertReflectionExceptionToUnchecked(e); } return list; }
From source file:com.snapdeal.archive.util.ArchivalUtil.java
/** * Returns a map where key is of type K and value is object. * @param objects//from w w w. j a v a 2s .c o m * @param propertyName * @return */ public static <K, T> Map<K, T> getPropertyObjectMap(Set<T> objects, String propertyName, Class<K> propertyClass) { Map<K, T> propertyObjectMap = new HashMap<>(); for (T t : objects) { Object value = null; try { value = PropertyUtils.getProperty(t, propertyName); K k = (K) propertyClass.cast(value); propertyObjectMap.put(k, t); } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) { e.printStackTrace(); } } return propertyObjectMap; }
From source file:cn.com.axiom.utils.Collections3.java
/** * ????(Getter), ??List.//from w ww .j a v a 2 s . c o m * * @param collection ???. * @param propertyName ??????. */ @SuppressWarnings({ "rawtypes", "unchecked" }) 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.njmd.framework.utils.CollectionsUtil.java
/** * ????(Getter), ??List.// w w w.j a v a2 s. co m * * @param collection * ???. * @param propertyName * ??????. */ public static List extractToList(final Collection collection, final String propertyName) { List list = new ArrayList(); try { for (Object obj : collection) { list.add(PropertyUtils.getProperty(obj, propertyName)); } } catch (Exception e) { throw ReflectionUtil.convertReflectionExceptionToUnchecked(e); } return list; }
From source file:com.safetys.framework.jmesa.util.ItemUtils.java
/** * Get the value from the Bean or Map by property. * //from w w w.java 2s . co m * @param item The Bean or Map. * @param property The Bean attribute or Map key. * @return The value from the Bean or Map. */ public static Object getItemValue(Object item, String property) { Object itemValue = null; try { if (item instanceof Map) { itemValue = ((Map<?, ?>) item).get(property); if (itemValue != null) { return itemValue; } // ports such as the tags will store the original bean Object bean = ((Map<?, ?>) item).get(JMESA_ITEM); if (bean == null) { logger.debug("the map does not have property " + property); return null; } itemValue = getItemValue(bean, property); } else { itemValue = PropertyUtils.getProperty(item, property); } } catch (Exception e) { logger.debug("item class " + item.getClass().getName() + " does not have property " + property); } return itemValue; }
From source file:com.algoTrader.service.ib.IBMarketDataServiceException.java
/** * Finds the root cause of the parent exception * by traveling up the exception tree/*w ww. j a va 2s . com*/ */ private static Throwable findRootCause(Throwable th) { if (th != null) { // Reflectively get any exception causes. try { Throwable targetException = null; // java.lang.reflect.InvocationTargetException String exceptionProperty = "targetException"; if (PropertyUtils.isReadable(th, exceptionProperty)) { targetException = (Throwable) PropertyUtils.getProperty(th, exceptionProperty); } else { exceptionProperty = "causedByException"; //javax.ejb.EJBException if (PropertyUtils.isReadable(th, exceptionProperty)) { targetException = (Throwable) PropertyUtils.getProperty(th, exceptionProperty); } } if (targetException != null) { th = targetException; } } catch (Exception ex) { // just print the exception and continue ex.printStackTrace(); } if (th.getCause() != null) { th = th.getCause(); th = findRootCause(th); } } return th; }
From source file:com.micmiu.modules.utils.Collections3.java
/** * ????(Getter), ??List./*from www . j av a2 s .co 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:jp.co.opentone.bsol.framework.web.view.PagePropertyUtil.java
/** * page??{@link Transfer}????????./*from w ww. j a v a 2 s. c om*/ * <p> * ???????????????. * </p> * @param page * page * @return {@link Transfer}???? */ public static Map<String, Object> collectTransferValues(Page page) { Map<String, Object> values = new HashMap<String, Object>(); for (Class<?> c = page.getClass(); c != null; c = c.getSuperclass()) { for (Field field : c.getDeclaredFields()) { if (field.isAnnotationPresent(Transfer.class)) { String name = field.getName(); Object value; try { value = PropertyUtils.getProperty(page, name); if (value != null) { values.put(name, value); } } catch (IllegalAccessException e) { throw new ReflectionRuntimeException(e); } catch (InvocationTargetException e) { throw new ReflectionRuntimeException(e); } catch (NoSuchMethodException e) { throw new ReflectionRuntimeException(e); } } } } return values; }
From source file:de.iew.web.dto.WebDTO.java
/** * {@inheritDoc}//from w w w . j a va2s . c om * <p> * Verwendet Commons-Beanutils um den Getter fr die angeforderte * Eigenschaft aufzurufen. * </p> */ public Object getProperty(String name) throws NoSuchPropertyException { try { return PropertyUtils.getProperty(this, name); } catch (Exception e) { throw new NoSuchPropertyException("The requested property " + name + " could not be resolved.", e); } }