Java Code Examples for org.apache.commons.beanutils.DynaClass#getDynaProperty()

The following examples show how to use org.apache.commons.beanutils.DynaClass#getDynaProperty() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DynaBeanPropertyPointer.java    From commons-jxpath with Apache License 2.0 6 votes vote down vote up
/**
 * Convert a value to the appropriate property type.
 * @param value to convert
 * @param element whether this should be a collection element.
 * @return conversion result
 */
private Object convert(Object value, boolean element) {
    DynaClass dynaClass = dynaBean.getDynaClass();
    DynaProperty property = dynaClass.getDynaProperty(getPropertyName());
    Class type = property.getType();
    if (element) {
        if (type.isArray()) {
            type = type.getComponentType();
        }
        else {
            return value; // No need to convert
        }
    }

    try {
        return TypeUtils.convert(value, type);
    }
    catch (Exception ex) {
        String string = value == null ? "null" : value.getClass().getName();
        throw new JXPathTypeConversionException(
                "Cannot convert value of class " + string + " to type "
                        + type, ex);
    }
}
 
Example 2
Source File: DynaBeanAdapter.java    From reflectutils with Apache License 2.0 5 votes vote down vote up
public Class<?> getFieldType(Object obj, String name) {
    DynaClass dynaClass = ((DynaBean) obj).getDynaClass();
    DynaProperty dynaProperty = dynaClass.getDynaProperty(name);
    if (dynaProperty == null) {
        throw new FieldnameNotFoundException("DynaBean: Could not find this fieldName ("+name+") on the target object: " + obj, name, null);
    }
    return dynaProperty.getType();
}
 
Example 3
Source File: DynaBeanPropertyPointer.java    From commons-jxpath with Apache License 2.0 4 votes vote down vote up
/**
 * Returns true if the bean has the currently selected property.
 * @return boolean
 */
protected boolean isActualProperty() {
    DynaClass dynaClass = dynaBean.getDynaClass();
    return dynaClass.getDynaProperty(getPropertyName()) != null;
}
 
Example 4
Source File: DynaBeanPropertyPointer.java    From commons-jxpath with Apache License 2.0 4 votes vote down vote up
/**
 * Learn whether the property referenced is an indexed property.
 * @return boolean
 */
protected boolean isIndexedProperty() {
    DynaClass dynaClass = dynaBean.getDynaClass();
    DynaProperty property = dynaClass.getDynaProperty(name);
    return property.isIndexed();
}