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.hula.lang.util.DotNotationUtil.java

/**
 * Uses beanutils to reflect the value of a property
 * //from w w w . j  a  va 2  s  . c o m
 * @param obj the object to inspect
 * @param property the property to reflect
 * @return the value of the property
 */
private static Object reflect(Object obj, String property) {
    try {
        return PropertyUtils.getProperty(obj, property);
    } catch (Throwable t) {
        logger.error("error getting property [" + t.getClass().getSimpleName() + "]", t);
        return null;
    }
}

From source file:com.lily.dap.service.core.Evaluator.VariableResolverImpl.java

/**
 *
 * Resolves the specified variable within the given context.
 * Returns null if the variable is not found.
 **//*  w  ww  . ja  v a2  s.co m*/
public Object resolveVariable(String pName) throws EvaluatException {
    Object val = null;

    if (context instanceof Map) {
        Map dataMap = (Map) context;
        if (!dataMap.containsKey(pName))
            return null;

        val = dataMap.get(pName);
    } else {
        try {
            val = PropertyUtils.getProperty(context, pName);
        } catch (Exception e) {
            return null;
        }
    }

    return val;
}

From source file:com.redhat.rcm.maven.plugin.buildmetadata.maven.MavenPropertyHelper.java

private static String getProjectProperty(final MavenProject project, final String projectName)
        throws IllegalAccessException, InvocationTargetException, NoSuchMethodException {
    if (project != null) {
        final Object value = PropertyUtils.getProperty(project, projectName);
        if (value != null) {
            return String.valueOf(value);
        } else {/*ww w .  j a  v  a2 s. c o m*/
            return getProjectProperty(project.getParent(), projectName);
        }
    }
    return null;
}

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

/**
 * @see javax.servlet.jsp.tagext.Tag#doEndTag()
 *//*from   w w  w  .  j  a  v  a2 s .co  m*/
public int doEndTag() throws JspException {

    ValueListSpaceTag rootTag = (ValueListSpaceTag) JspUtils.getParent(this, ValueListSpaceTag.class);
    ValueListConfigBean config = rootTag.getConfig();

    DefaultRowTag rowTag = (DefaultRowTag) JspUtils.getParent(this, DefaultRowTag.class);
    appendClassCellAttribute(rowTag.getRowStyleClass());

    Locale locale = config.getLocaleResolver().resolveLocale((HttpServletRequest) pageContext.getRequest());

    if (rowTag.getCurrentRowNumber() == 0) {
        String titleKey = getTitleKey();
        String label = (titleKey == null) ? getTitle()
                : config.getMessageSource().getMessage(titleKey, null, titleKey, locale);

        StringBuffer header = new StringBuffer(512);
        if (label != null) {
            header.append(label);
        }

        header.append(
                "<input type=\"checkbox\" onclick=\"for(i=0; i < this.form.elements.length; i++) {if (this.form.elements[i].name=='")
                .append(getName()).append("') {this.form.elements[i].checked = this.checked;}}\"/>");

        ColumnInfo columnInfo = new ColumnInfo(config.getDisplayHelper().help(pageContext, header.toString()),
                property, null, getAttributes());

        // Process toolTip if any
        // toolTip or toolTipKey is set => get the string and put it into the ColumnInfo
        String toolTipKey = getToolTipKey();
        columnInfo.setToolTip((toolTipKey == null) ? getToolTip()
                : config.getMessageSource().getMessage(toolTipKey, null, toolTipKey, locale));

        rowTag.addColumnInfo(columnInfo);
    }

    Object bean = pageContext.getAttribute(rowTag.getBeanName());
    Object value = "na";

    try {
        value = PropertyUtils.getProperty(bean, property);
    } catch (Exception e) {
    }

    StringBuffer sb = new StringBuffer();

    sb.append(rowTag.getDisplayProvider().getCellPreProcess(getCellAttributes()));

    BodyContent bodyContent = getBodyContent();
    if (bodyContent != null && bodyContent.getString() != null && bodyContent.getString().length() > 0) {
        sb.append(bodyContent.getString());
        bodyContent.clearBody();
    } else {
        sb.append("<input type=\"checkbox\" name=\"").append(name).append("\" value=\"").append(value)
                .append("\"/>");
    }

    sb.append(rowTag.getDisplayProvider().getCellPostProcess());
    JspUtils.write(pageContext, sb.toString());

    release();

    return EVAL_PAGE;
}

From source file:com.sf.ddao.shards.conn.ShardedConnectionHandler.java

public Object extractShardKey(String name, Object shardKey) {
    if (name.length() > 0) {
        // if name defined then key is either mapped value or bean property
        if (shardKey instanceof Map) {
            shardKey = ((Map) shardKey).get(name);
        } else {/*  ww  w  .  j  a  v a2  s . c o  m*/
            try {
                shardKey = PropertyUtils.getProperty(shardKey, name);
            } catch (Exception e) {
                throw new ShardException("Failed to get shard key " + name + " from " + shardKey, e);
            }
        }
        if (shardKey == null) {
            throw new ShardException("Failed to find shard key ");
        }
    }
    return shardKey;
}

From source file:kina.utils.AnnotationUtils.java

/**
 * Returns the value of the fields <i>kinaField</i> in the instance <i>entity</i> of type T.
 *
 * @param entity    the entity to process.
 * @param kinaField the Field to process belonging to <i>entity</i>
 * @return the property value.//from www .  j  a v a  2s.  c o  m
 */
public static Serializable getBeanFieldValue(KinaType entity, java.lang.reflect.Field kinaField) {
    try {
        return (Serializable) PropertyUtils.getProperty(entity, kinaField.getName());

    } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e1) {
        throw new IOException(e1);
    }

}

From source file:io.neocdtv.eclipselink.entitygraph.CopyPartialEntities.java

private void handleSimpleNode(final AttributeNodeImpl node, final Object copyFrom, final Object copyTo)
        throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
    final String attributeName = node.getAttributeName();
    final Object property = PropertyUtils.getProperty(copyFrom, attributeName);
    PropertyUtils.setProperty(copyTo, attributeName, property);
}

From source file:net.jofm.DefaultFixedMapper.java

protected String toFixed(Object sourceObject, FixedMetaData fixedMetadata) throws Exception {
    StringBuilder line = new StringBuilder();
    for (FieldMetaData fieldMetaData : fixedMetadata) {
        Object value = PropertyUtils.getProperty(sourceObject, fieldMetaData.getField().getName());

        if (value == null && fieldMetaData.isRequired()) {
            throw new FixedMappingException("Field '" + fieldMetaData.getField().getName() + "' of "
                    + sourceObject.getClass() + " is required.");
        }/*ww w  .j  a va2s  .c o  m*/

        if (fieldMetaData instanceof FixedFieldMetaData) {
            toFixedField(value, line, (FixedFieldMetaData) fieldMetaData, fieldMetaData.getField().getName());
        } else if (fieldMetaData instanceof PrimitiveFieldMetaData) {
            toPrimitiveField(value, line, (PrimitiveFieldMetaData) fieldMetaData);
        } else if (fieldMetaData instanceof PrimitiveFieldListMetaData) {
            toPrimitiveFieldList(value, line, (PrimitiveFieldListMetaData) fieldMetaData);
        } else if (fieldMetaData instanceof FixedFieldListMetaData) {
            toFixedFieldList(value, line, (FixedFieldListMetaData) fieldMetaData);
        }
    }
    return line.toString();
}

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

@Test
public void testExpressionValue() throws Exception {
    for (T testValue : _testValues) {
        expect(_valueExpression.isLiteralText()).andReturn(false);
        _mocksControl.replay();//  ww  w.j  ava 2  s.  co  m
        _component.setValueExpression(_property, _valueExpression);
        _mocksControl.reset();
        expect(_valueExpression.getValue(eq(_facesContext.getELContext()))).andReturn(testValue);
        _mocksControl.replay();
        Assert.assertEquals(testValue, PropertyUtils.getProperty(_component, _property));
        _mocksControl.reset();
    }
}

From source file:com.mycollab.db.persistence.service.DefaultCrudService.java

@Override
public void massRemoveWithSession(List<T> items, String username, Integer accountId) {
    List<T> primaryKeys = new ArrayList<>(items.size());
    for (T item : items) {
        try {// w w w  .j  a  va 2  s  . c om
            T primaryKey = (T) PropertyUtils.getProperty(item, "id");
            primaryKeys.add(primaryKey);
        } catch (Exception e) {
            throw new MyCollabException(e);
        }
    }
    getCrudMapper().removeKeysWithSession(primaryKeys);
}