Example usage for org.apache.commons.beanutils PropertyUtils getProperty

List of usage examples for org.apache.commons.beanutils PropertyUtils getProperty

Introduction

In this page you can find the example usage for org.apache.commons.beanutils PropertyUtils getProperty.

Prototype

public static Object getProperty(Object bean, String name)
        throws IllegalAccessException, InvocationTargetException, NoSuchMethodException 

Source Link

Document

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.

Usage

From source file:cn.newtouch.util.hibernate.ConvertUtils.java

/**
 * ????(getter), ??List./* w  w  w.j  a  v a2s .c  om*/
 * 
 * @param collection
 *            ???.
 * @param propertyName
 *            ??????.
 */
@SuppressWarnings("unchecked")
public static List convertElementPropertyToList(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 ReflectionUtils.convertReflectionExceptionToUnchecked(e);
    }

    return list;
}

From source file:com.wwinsoft.modules.utils.reflection.ConvertUtils.java

/**
 * ????(getter), ??List.//w ww  . j a v  a2  s.c om
 * 
 * @param collection ???.
 * @param propertyName ??????.
 */
@SuppressWarnings("unchecked")
public static <T> List<T> convertElementPropertyToList(final Collection collection, final String propertyName) {
    List<T> list = new ArrayList();

    try {
        for (Object obj : collection) {
            list.add((T) PropertyUtils.getProperty(obj, propertyName));
        }
    } catch (Exception e) {
        throw ReflectionUtils.convertReflectionExceptionToUnchecked(e);
    }

    return list;
}

From source file:com.jythonui.server.RUtils.java

private static Optional<Date> retrieveD(Object o, String propName) {
    Date d = null;/*  w  ww.j  av  a  2 s . c  o  m*/
    try {
        d = (Date) PropertyUtils.getProperty(o, propName);
    } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
        return null;
    }
    return Optional.fromNullable(d);
}

From source file:com.nec.strudel.entity.EntityUtil.java

public static Object getProperty(Object entity, String name) {
    try {/*from w  w w  .  jav  a  2s. co  m*/
        return PropertyUtils.getProperty(entity, name);
    } catch (IllegalAccessException ex) {
        throw new RuntimeException(ex); // TODO refactor
    } catch (InvocationTargetException ex) {
        throw new RuntimeException(ex); // TODO refactor
    } catch (NoSuchMethodException ex) {
        throw new RuntimeException(ex); // TODO refactor
    }
}

From source file:com.github.daddo.validation.validator.Util.java

public static Object accessPropertyByName(Object bean, String propertyName) throws PropertyAccessException {
    try {// w  w w  .  ja v  a 2s.c o  m
        return PropertyUtils.getProperty(bean, propertyName);
    } catch (IllegalAccessException ex) {
        throw new PropertyAccessException(ex);
    } catch (InvocationTargetException ex) {
        throw new PropertyAccessException(ex);
    } catch (NoSuchMethodException ex) {
        throw new PropertyAccessException(ex);
    }
}

From source file:cn.hxh.springside.mapper.CollectionMapper.java

/**
 * ????(Getter), ??Map.//from   w w w  . j  a va2 s  . c  o m
 * 
 * @param collection ???.
 * @param keyPropertyName ????MapKey??.
 * @param valuePropertyName ????MapValue??.
 */
public static Map extractToMap(final Collection collection, final String keyPropertyName,
        final String valuePropertyName) {
    Map map = new HashMap();

    try {
        for (Object obj : collection) {
            map.put(PropertyUtils.getProperty(obj, keyPropertyName),
                    PropertyUtils.getProperty(obj, valuePropertyName));
        }
    } catch (Exception e) {
        throw ReflectionUtils.convertReflectionExceptionToUnchecked(e);
    }

    return map;
}

From source file:com.eryansky.common.utils.ConvertUtils.java

/**
 * ????(getter), ??List./* w w w. ja va2 s.  co m*/
 * 
 * @param collection ???.
 * @param propertyName ??????.
 */
@SuppressWarnings({ "unchecked", "rawtypes" })
public static List convertElementPropertyToList(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 ReflectionUtils.convertReflectionExceptionToUnchecked(e);
    }

    return list;
}

From source file:gov.nih.nci.ncicb.cadsr.common.jsp.tag.handler.SecureIconDisplay.java

private String getParamValue(Form form, String paramProperty) throws JspException {
    String paramValue = null;//from w w w . j  ava2 s .c o m
    try {
        PropertyUtils beanPropertyUtil = new PropertyUtils();
        paramValue = (String) beanPropertyUtil.getProperty(form, paramProperty);

    } catch (Exception ex) {
        throw new JspException(ex.toString());
    }
    return paramValue;
}

From source file:com.esofthead.mycollab.core.utils.ArrayUtils.java

public static List<Integer> extractIds(List items) {
    try {//from  w w w  . ja  v a2 s . c om
        List<Integer> keys = new ArrayList<>(items.size());
        for (Object item : items) {
            Integer key = (Integer) PropertyUtils.getProperty(item, "id");
            keys.add(key);
        }
        return keys;
    } catch (Exception e) {
        throw new MyCollabException(e);
    }
}

From source file:com.jdy.ddj.common.utils.Collections3.java

/**
 * ????(Getter), ??Map.//from w  w w.  j a v  a2s . co  m
 *
 * @param collection ???.
 * @param keyPropertyName ????MapKey??.
 * @param valuePropertyName ????MapValue??.
 */
public static Map extractToMap(final Collection collection, final String keyPropertyName,
        final String valuePropertyName) {
    Map map = new HashMap();

    try {
        for (Object obj : collection) {
            map.put(PropertyUtils.getProperty(obj, keyPropertyName),
                    PropertyUtils.getProperty(obj, valuePropertyName));
        }
    } catch (Exception e) {
        throw Reflections.convertReflectionExceptionToUnchecked(e);
    }

    return map;
}