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:com.jk.util.JKObjectUtil.java

/**
 * Gets the property value./*  w  w  w.  j a v  a  2  s .co m*/
 *
 * @param <T>
 *            the generic type
 * @param instance
 *            the instance
 * @param fieldName
 *            the field name
 * @return the property value
 */
public static <T> T getPropertyValue(final Object instance, final String fieldName) {
    try {
        return (T) PropertyUtils.getProperty(instance, fieldName);
    } catch (final Exception e) {
        throw new RuntimeException(e);
    }
}

From source file:net.sourceforge.fenixedu.util.domain.SlotSelector.java

@Override
public Integer getOrder(ObjectType target) {
    try {/*w w w . j a v  a  2s.  c  o  m*/
        return (Integer) PropertyUtils.getProperty(target, this.slotName);
    } catch (IllegalAccessException e) {
        throw new DomainException("adapter.ordered.relation.no.slot.access", e);
    } catch (InvocationTargetException e) {
        throw handleInvocationTargetException(e, "adapter.ordered.relation.invocation.exception");
    } catch (NoSuchMethodException e) {
        throw new DomainException("adapter.ordered.relation.no.slot", e);
    }
}

From source file:net.sf.infrared.web.customtags.ContainsTag.java

public int doStartTag() throws JspException {
    Object formBean = RequestUtils.lookup(pageContext, name, scope);

    // Able to get an value for instance as Struts creates page context variable
    // with the same name as the id in the logic:iterate tag. Thus for each iteration
    // the value of this variable is updated.

    String instance = (String) RequestUtils.lookup(pageContext, selectedName, scope);
    flag = Boolean.valueOf(notContains).booleanValue();

    Set currentInstance = null;//from   ww w .j av a  2s  .co  m
    try {
        currentInstance = (Set) PropertyUtils.getProperty(formBean, property);
    } catch (Exception e) {
        logger.error("Unable to find the property " + property + " in the bean", e);
    }

    if ((currentInstance.contains(instance) && !flag) || (!currentInstance.contains(instance) && flag))
        return (EVAL_BODY_INCLUDE);
    else
        return (SKIP_BODY);
}

From source file:com.hula.lang.commands.data.ListContains.java

@Override
public void execute(RuntimeConnector connector) {
    List list = (List) this.getVariableValue("default", connector);
    String path = this.getVariableValueAsString("path", connector);
    Object value = this.getVariableValue("value", connector);

    boolean found = false;

    Iterator iter = list.iterator();
    while (iter.hasNext()) {
        Object listItem = iter.next();

        Object compare = listItem;
        if (path != null) {
            try {
                compare = PropertyUtils.getProperty(listItem, path);
            } catch (Exception e) {
                throw new HulaRuntimeException("error.getting.path",
                        "error getting path [" + path + "] for object [" + listItem + "]", e);
            }//from  w  w  w  .java  2  s  .c o  m
        }

        if (compare.equals(value)) {
            found = true;
            break;
        }

    }

    connector.setVariable(getReturnParameter(), found);

}

From source file:com.tonbeller.wcf.convert.BooleanConverter.java

/**
 * sets the selected attribute of the checkbox from the bean
 *//*w  w  w.ja va  2  s .  co  m*/
public void convert(Formatter fmt, Object bean, Element elem)
        throws IllegalAccessException, NoSuchMethodException, InvocationTargetException {

    String modelReference = Item.getModelReference(elem);
    if (bean == null || modelReference.length() == 0)
        return;

    Boolean value = (Boolean) PropertyUtils.getProperty(bean, Item.getModelReference(elem));
    boolean b = (value == null) ? false : value.booleanValue();
    Item.setSelected(elem, b);
}

From source file:jp.co.opentone.bsol.framework.core.util.PropertyGetUtil.java

public static Object getNestedProperty(Object data, String name) {
    try {/*from   w  w  w .  ja v  a 2 s .  c  o  m*/
        if (!name.contains(".")) {
            return PropertyUtils.getProperty(data, name);
        }
        if (name.contains("[")) {
            String[] names = name.split("\\.", 2);
            Object obj = null;
            try {
                obj = PropertyUtils.getIndexedProperty(data, names[0]);
            } catch (NullPointerException npe) {
                // ???null??
                obj = null;
            }
            if (obj == null) {
                return null;
            }
            return getNestedProperty(obj, names[1]);
        }
        try {
            return PropertyUtils.getNestedProperty(data, name);
        } catch (NestedNullException nne) {
            // ?????null??????
            // null?
            return null;
        }
    } catch (Exception e) {
        throw new ApplicationFatalRuntimeException("invalid property : " + name, e);
    }
}

From source file:javax.faces.component.AbstractUIComponentPropertyTest.java

@Test
public void testDefaultValue() throws Exception {
    Assert.assertEquals(_defaultValue, PropertyUtils.getProperty(_component, _property));
}

From source file:net.sourceforge.fenixedu.util.UniqueAcronymCreator.java

private void initialize() throws Exception {
    existingAcronyms.clear();/*from  w  w  w .  j a v  a2 s.co m*/
    colisions.clear();

    for (final T object : objects) {
        String objectAcronym = (String) PropertyUtils.getProperty(object, acronymSlot);

        if (objectAcronym != null) {
            if (existingAcronyms.containsKey(objectAcronym)) {
                throw new Exception("given object list doesn't have unique acronyms!");
            }

            existingAcronyms.put(objectAcronym, object);
        }
    }
}

From source file:com.esofthead.mycollab.module.user.ui.components.ActiveUserMultiSelectComp.java

@Override
protected ItemSelectionComp<SimpleUser> buildItem(final SimpleUser item) {
    ItemSelectionComp<SimpleUser> buildItem = super.buildItem(item);
    String userAvatarId = "";

    try {/* w w  w  .  j  av a2  s  . c o m*/
        userAvatarId = (String) PropertyUtils.getProperty(item, "avatarid");
    } catch (Exception e) {
        LOG.error("Error while getting project member avatar", e);
    }

    buildItem.setIcon(UserAvatarControlFactory.createAvatarResource(userAvatarId, 16));
    return buildItem;
}

From source file:net.mlw.vlh.web.tag.InvertedRowTag.java

public void convertValueList() throws JspException {
    ValueList vl = getRootTag().getValueList();

    try {/*from w ww.  j  a  v a  2  s .c o m*/

        while (vl.hasNext()) {
            Object bean = vl.next();
            Object xAxis = PropertyUtils.getProperty(bean, "ixaxis");
            Object yAxis = PropertyUtils.getProperty(bean, "iyaxis");
            Object value = PropertyUtils.getProperty(bean, "ivalue");

            xAxisMap.put(xAxis, null);

            Map map = (Map) yAxisMap.get(yAxis);
            if (map == null) {
                yAxisMap.put(yAxis, map = new HashMap());
                map.put("yaxis", yAxis);
            }
            map.put(JspUtils.format(xAxis, null, null).toLowerCase().replace(' ', '_'), value);
        }
    } catch (Exception e) {
        LOGGER.error("InvertedRowTag.convertValueList() exception...", e);
    }

    //Add all the columns to the tag context.
    for (Iterator iter = xAxisMap.keySet().iterator(); iter.hasNext();) {
        String label = JspUtils.format(iter.next(), null, null);
        addColumnInfo(new ColumnInfo(label, label.toLowerCase().replace(' ', '_'), null, null));
    }

    getRootTag().setValueList(
            new DefaultListBackedValueList(new ArrayList(yAxisMap.values()), vl.getValueListInfo()));
}