Example usage for org.apache.commons.beanutils PropertyUtilsBean getSimpleProperty

List of usage examples for org.apache.commons.beanutils PropertyUtilsBean getSimpleProperty

Introduction

In this page you can find the example usage for org.apache.commons.beanutils PropertyUtilsBean getSimpleProperty.

Prototype

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

Source Link

Document

Return the value of the specified simple property of the specified bean, with no type conversions.

Usage

From source file:de.micromata.genome.util.bean.PropertyDescriptorUtils.java

/**
 * Read property.//w  w w.  j  av a  2 s.  c o  m
 *
 * @param bean the bean
 * @param pd the pd
 * @return the object
 * @throws PropertyAccessException the property access exception
 */
public static Object readProperty(Object bean, PropertyDescriptor pd) throws PropertyAccessException {
    PropertyUtilsBean proputils = BeanUtilsBean.getInstance().getPropertyUtils();
    Object value;
    try {
        value = proputils.getSimpleProperty(bean, pd.getName());
        return value;
    } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException ex) {
        throw new PropertyAccessException("getSimpleProperty", bean, pd, ex);
    }
}

From source file:net.firejack.platform.core.store.registry.resource.ResourceVersionStore.java

private void copyResourceVersionProperties(RV dest, RV orig) {
    PropertyUtilsBean propertyUtils = BeanUtilsBean.getInstance().getPropertyUtils();
    PropertyDescriptor[] propertyDescriptors = propertyUtils.getPropertyDescriptors(orig);
    for (PropertyDescriptor propertyDescriptor : propertyDescriptors) {
        String name = propertyDescriptor.getName();
        if (ArrayUtils.contains(new String[] { "class", "id", "version", "status", "updated", "created" },
                name)) {//from   w  w  w  .  j a  v  a2  s  .  c o m
            continue;
        }
        if (propertyUtils.isReadable(orig, name) && propertyUtils.isWriteable(dest, name)) {
            try {
                Object value = propertyUtils.getSimpleProperty(orig, name);
                if (value instanceof Timestamp) {
                    value = ConvertUtils.convert(value, Date.class);
                }
                BeanUtils.copyProperty(dest, name, value);
            } catch (Exception e) {
                // Should not happen
            }
        }
    }
}

From source file:org.apache.empire.data.bean.BeanRecordProxy.java

protected Object getBeanPropertyValue(Object bean, String property) {
    // Check Params
    if (bean == null)
        throw new InvalidArgumentException("bean", bean);
    if (property == null)
        throw new InvalidArgumentException("property", property);
    try { // Get Property Value
        PropertyUtilsBean pub = BeanUtilsBean.getInstance().getPropertyUtils();
        return pub.getSimpleProperty(bean, property);

    } catch (IllegalAccessException e) {
        log.error(bean.getClass().getName() + ": unable to get property '" + property + "'");
        throw new BeanPropertyGetException(bean, property, e);
    } catch (InvocationTargetException e) {
        log.error(bean.getClass().getName() + ": unable to get property '" + property + "'");
        throw new BeanPropertyGetException(bean, property, e);
    } catch (NoSuchMethodException e) {
        log.warn(bean.getClass().getName() + ": no getter available for property '" + property + "'");
        throw new BeanPropertyGetException(bean, property, e);
    }//from  w  w w .  j ava 2s .  c  o m
}

From source file:org.apache.empire.db.DBRecord.java

/**
 * set a record value from a particular bean property.
 * <P>//  w  w w  .  j  a v a  2 s .  co  m
 * For a property called FOO this is equivalent of calling<BR>
 *     setValue(column, bean.getFOO())
 * <P>
 * @param bean the Java Bean from which to read the value from
 * @param property the name of the property
 * @param column the column for which to set the record value
 */
protected void setBeanValue(Object bean, String property, Column column) {
    try { /*
          if (log.isTraceEnabled())
          log.trace(bean.getClass().getName() + ": getting property '" + property + "' for column " + column.getName());
          */

        // Get Property Value
        PropertyUtilsBean pub = BeanUtilsBean.getInstance().getPropertyUtils();
        Object value = pub.getSimpleProperty(bean, property);

        // Now, set the record value
        setValue(column, value);

    } catch (IllegalAccessException e) {
        log.error(bean.getClass().getName() + ": unable to get property '" + property + "'");
        throw new BeanPropertyGetException(bean, property, e);
    } catch (InvocationTargetException e) {
        log.error(bean.getClass().getName() + ": unable to get property '" + property + "'");
        throw new BeanPropertyGetException(bean, property, e);
    } catch (NoSuchMethodException e) {
        log.warn(bean.getClass().getName() + ": no getter available for property '" + property + "'");
        throw new BeanPropertyGetException(bean, property, e);
    }
}

From source file:org.apache.empire.jsf2.utils.TagEncodingHelper.java

protected Object getBeanPropertyValue(Object bean, String property) {
    try { // Get Property Value
        PropertyUtilsBean pub = BeanUtilsBean.getInstance().getPropertyUtils();
        return pub.getSimpleProperty(bean, property);

    } catch (IllegalAccessException e) {
        log.error(bean.getClass().getName() + ": unable to get property '" + property + "'");
        throw new BeanPropertyGetException(bean, property, e);
    } catch (InvocationTargetException e) {
        log.error(bean.getClass().getName() + ": unable to get property '" + property + "'");
        throw new BeanPropertyGetException(bean, property, e);
    } catch (NoSuchMethodException e) {
        log.warn(bean.getClass().getName() + ": no getter available for property '" + property + "'");
        throw new BeanPropertyGetException(bean, property, e);
    }//from www  .ja  v a 2  s. co m
}

From source file:org.apache.empire.jsf2.utils.TagEncodingHelper.java

public Object getAttributeValueEx(String name) {
    Object value = getTagAttributeValue(name);
    if (value == null) { // Check Column
        value = getColumn().getAttribute(name);
    }//ww w .  ja  v a 2  s. c  om
    // Checks whether it's another column    
    if (value instanceof Column) { // Special case: Value is a column
        Column col = ((Column) value);
        Object rec = getRecord();
        if (rec instanceof Record)
            return ((Record) rec).getValue(col);
        else if (rec != null) { // Get Value from a bean
            String property = col.getBeanPropertyName();
            try { // Use Beanutils to get Property
                PropertyUtilsBean pub = BeanUtilsBean.getInstance().getPropertyUtils();
                return pub.getSimpleProperty(rec, property);
            } catch (Exception e) {
                log.error("BeanUtils.getSimpleProperty failed for " + property, e);
                return null;
            }
        }
        return null;
    }
    return value;
}

From source file:org.apache.empire.spring.EmpireRecord.java

@Override
protected void setBeanValue(Object bean, String property, Column column) {
    try {/*  w ww . ja v  a2  s.c o m*/
        // Get descriptor
        Object value;
        PropertyUtilsBean pub = BeanUtilsBean.getInstance().getPropertyUtils();
        PropertyDescriptor descriptor = pub.getPropertyDescriptor(bean, property);
        if (descriptor == null) {
            return; // Skip this property setter
        }

        // Get Property Value
        value = pub.getSimpleProperty(bean, property);

        // Check enum
        if (value instanceof Enum<?>)
            value = ((Enum<?>) value).name();

        // Set the record value
        setValue(column, value);

    } catch (IllegalAccessException e) {
        log.error(bean.getClass().getName() + ": unable to get property '" + property + "'");
        throw new BeanPropertyGetException(bean, property, e);
    } catch (NoSuchMethodException e) {
        log.error(bean.getClass().getName() + ": unable to get property '" + property + "'");
        throw new BeanPropertyGetException(bean, property, e);
    } catch (InvocationTargetException e) {
        log.error(bean.getClass().getName() + ": unable to get property '" + property + "'");
        throw new BeanPropertyGetException(bean, property, e);
    }
}

From source file:org.apache.empire.struts2.jsp.tags.EmpireTagSupport.java

protected Object getBeanProperty(Object bean, String property) {
    try { /*
          if (log.isTraceEnabled())//from w w w. java  2s .  c o m
          log.trace(bean.getClass().getName() + ": setting property '" + property + "' to " + String.valueOf(value));
          */

        // Get Property Value
        PropertyUtilsBean pub = BeanUtilsBean.getInstance().getPropertyUtils();
        return pub.getSimpleProperty(bean, property);

        // Check result
        /*
         * String res = BeanUtils.getProperty(bean, property); if (res!=value && res.equals(String.valueOf(value))==false) { //
         * Property value cannot be set // (missing setter?) String msg = bean.getClass().getName() + ": unable to set
         * property '" + property + "' to " + String.valueOf(value); return error(ERR_INTERNAL, msg); } else if
         * (log.isInfoEnabled()) { log.info(bean.getClass().getName() + ": property '" + property + "' has been set to " +
         * res); }
         */
        // done

    } catch (IllegalAccessException e) {
        log.error(bean.getClass().getName() + ": unable to set property '" + property + "'");
        return null;
    } catch (InvocationTargetException e) {
        log.error(bean.getClass().getName() + ": unable to set property '" + property + "'");
        return null;
    } catch (NoSuchMethodException e) {
        log.warn(bean.getClass().getName() + ": cannot check value of property '" + property + "'");
        return null;
    }
}

From source file:org.eclipse.wb.internal.rcp.model.rcp.ActionFactoryCreationSupport.java

/**
 * Copies value of property from "this" {@link IWorkbenchAction} into design {@link Action}
 * object./*from  w w  w .  j ava  2 s .c  o m*/
 */
private static void copyActionProperty(Object action, IWorkbenchAction sourceAction, String propertyName)
        throws Exception {
    PropertyUtilsBean propertyUtils = new PropertyUtilsBean();
    Object value = propertyUtils.getSimpleProperty(sourceAction, propertyName);
    if (value instanceof String) {
        propertyUtils.setSimpleProperty(action, propertyName, value);
    } else if (value != null
            && ReflectionUtils.isSuccessorOf(value.getClass(), "org.eclipse.jface.resource.ImageDescriptor")) {
        ClassLoader classLoader = action.getClass().getClassLoader();
        Object imageDescriptor = createID(classLoader, (ImageDescriptor) value);
        propertyUtils.setSimpleProperty(action, propertyName, imageDescriptor);
    }
}