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:fi.vrk.xroad.catalog.lister.JaxbCatalogServiceTest.java

private String getStringProperty(String propertyName, Object item)
        throws IllegalAccessException, InvocationTargetException, NoSuchMethodException {
    return (String) PropertyUtils.getProperty(item, propertyName);
}

From source file:com.zhuangjy.dao.ReflectionUtil.java

/**
 * ????(getter), ??List.//from ww  w. ja v a 2 s  . co  m
 * 
 * @param collection
 *            ???.
 * @param propertyName
 *            ??????.
 */
public static List<?> convertElementPropertyToList(final Collection<?> collection, final String propertyName)
        throws IllegalAccessException, NoSuchMethodException, InvocationTargetException {
    List<Object> list = new ArrayList<Object>();

    for (Object obj : collection) {
        list.add(PropertyUtils.getProperty(obj, propertyName));
    }

    return list;
}

From source file:com.qperior.gsa.oneboxprovider.implementations.jive.rest.QPJiveJsonObject.java

private String ensureStringProperty(Object bean, String name) {
    try {/*from  w w  w .  java  2  s  .  c  om*/
        return (String) PropertyUtils.getProperty(bean, name);
    } catch (Exception exc) {
        this.log.info("Exception in getting JSON property '" + name + "': " + exc.getLocalizedMessage());
        return null;
    }
}

From source file:com.zfsoft.util.reflect.ReflectionUtils.java

/**
 * ????(getter), ??List./*from   ww w .j a  v  a 2 s.  co m*/
 * 
 * @param collection ???.
 * @param propertyName ??????.
 */
@SuppressWarnings("unchecked")
public static List fetchElementPropertyToList(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.mh.commons.utils.Reflections.java

/**
 * ????(getter), ??List.//  w ww.jav  a  2s .  c o  m
 * 
 * @param collection ???.
 * @param propertyName ??????.
 */
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 convertReflectionExceptionToUnchecked(e);
    }

    return list;
}

From source file:com.timtripcony.AbstractSmartDocumentModel.java

@Override
public Object getValue(final Object key) {
    Object result = null;//from   w  ww . j ava 2 s. c  o  m
    try {
        result = PropertyUtils.getProperty(this, key.toString());
    } catch (Throwable t) {
        result = super.getValue(key);
    }
    return result;
}

From source file:com.esofthead.mycollab.mobile.module.crm.view.activity.RelatedItemSelectionField.java

@Override
protected Component initContent() {
    final RelatedItemSelectionView targetView = new RelatedItemSelectionView(this);
    navButton.setStyleName("combo-box");
    navButton.setWidth("100%");
    navButton.setTargetView(targetView);
    navButton.addClickListener(new NavigationButton.NavigationButtonClickListener() {
        private static final long serialVersionUID = -3929991734772006774L;

        @Override//  ww  w  .  ja  v  a  2 s  . co m
        public void buttonClick(NavigationButton.NavigationButtonClickEvent event) {
            try {
                targetView.selectTab((String) PropertyUtils.getProperty(bean, "type"));
            } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
                LOG.error("Error when select tab", e);
            }
        }
    });
    return navButton;
}

From source file:com.feilong.commons.core.bean.PropertyUtil.java

/**
 *  {@link PropertyUtils#getProperty(Object, String)} ?.
 * //from  w w w  .j a v a2s  .  c  o m
 * <pre>
 * {@code
 * getPropertysetProperty,?2?JavaBean????.
 * Company c = new Company();
 * c.setName("Simple");
 * 
 * Simple?????
 * //Simple
 * log.debug(BeanUtils.getProperty(c, "name"));
 * 
 * Map???key??
 * //Map
 *     log.debug(BeanUtils.getProperty(c, "address (A2)"));
 *     HashMap am = new HashMap();
 *     am.put("1","234-222-1222211");
 *     am.put("2","021-086-1232323");
 *     BeanUtils.setProperty(c,"telephone",am);
 * log.debug(BeanUtils.getProperty(c, "telephone (2)"));
 * 
 * Indexed??[]??ArrayList???.
 * //index
 *     log.debug(BeanUtils.getProperty(c, "otherInfo[2]"));
 *     BeanUtils.setProperty(c, "product[1]", "NOTES SERVER");
 *     log.debug(BeanUtils.getProperty(c, "product[1]"));
 * 
 * 3????
 * //nest
 *     log.debug(BeanUtils.getProperty(c, "employee[1].name"));
 * 
 * }
 * </pre>
 * 
 * <h3>{@link BeanUtils#getProperty(Object, String)}&{@link PropertyUtils#getProperty(Object, String)}</h3>
 * 
 * <blockquote>
 * <p>
 * {@link BeanUtils#getProperty(Object, String)} ?String,<br>
 * {@link PropertyUtils#getProperty(Object, String)} Object,???
 * </p>
 * </blockquote>
 * 
 * @param <T>
 *            the generic type
 * @param bean
 *            Bean whose property is to be extracted
 * @param name
 *            Possibly indexed and/or nested name of the property to be extracted
 * 
 * @return {@link PropertyUtils#getProperty(Object, String)} ?
 * @throws BeanUtilException
 *             if IllegalAccessException | InvocationTargetException | NoSuchMethodException
 * @see com.feilong.commons.core.bean.BeanUtil#getProperty(Object, String)
 * @see org.apache.commons.beanutils.BeanUtils#getProperty(Object, String)
 * @see org.apache.commons.beanutils.PropertyUtils#getProperty(Object, String)
 * @see org.apache.commons.beanutils.PropertyUtilsBean
 */
public static <T> T getProperty(Object bean, String name) throws BeanUtilException {
    //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.
    try {
        @SuppressWarnings("unchecked")
        T propertyValue = (T) PropertyUtils.getProperty(bean, name);
        return propertyValue;
    } catch (Exception e) {
        log.error(e.getClass().getName(), e);
        throw new BeanUtilException(e);
    }
}

From source file:gov.nih.nci.caarray.dao.AbstractCaArrayDaoImpl.java

Criterion createExample(Object entity, MatchMode matchMode, boolean excludeNulls, boolean excludeZeroes,
        Collection<String> excludeProperties) {
    final Example example = Example.create(entity).enableLike(matchMode).ignoreCase();
    if (excludeZeroes) {
        example.excludeZeroes();/*ww  w.j  av  a2s. com*/
    } else if (!excludeNulls) {
        example.excludeNone();
    }
    for (final String property : excludeProperties) {
        example.excludeProperty(property);
    }

    // ID property is not handled by Example, so we have to special case it
    final PersistentClass pclass = getClassMapping(entity.getClass());
    Object idVal = null;
    if (pclass != null && pclass.hasIdentifierProperty()) {
        try {
            idVal = PropertyUtils.getProperty(entity, pclass.getIdentifierProperty().getName());
        } catch (final Exception e) {
            LOG.warn("Could not retrieve identifier value in a by example query, ignoring it", e);
        }
    }
    if (idVal == null) {
        return example;
    } else {
        return Restrictions.and(Restrictions.idEq(idVal), example);
    }
}

From source file:com.esofthead.mycollab.module.crm.ui.components.CrmFollowersComp.java

private void followItem(String username, V bean) {
    try {/*ww  w  .j a  v  a2s. com*/
        MonitorItem monitorItem = new MonitorItem();
        monitorItem.setMonitorDate(new GregorianCalendar().getTime());
        monitorItem.setType(type);
        monitorItem.setTypeid((int) PropertyUtils.getProperty(bean, "id"));
        monitorItem.setUser(username);
        monitorItem.setSaccountid(AppContext.getAccountId());
        monitorItemService.saveWithSession(monitorItem, AppContext.getUsername());
    } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
        LOG.error("Error", e);
    }
}