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.sqewd.open.dal.core.persistence.query.EntityListSorter.java

private int compare(final AbstractEntity esrc, final AbstractEntity etgt, final SortColumn column)
        throws Exception {
    StructAttributeReflect attr = ReflectionUtils.get().getAttribute(esrc.getClass(), column.getColumn());

    Object vsrc = PropertyUtils.getProperty(esrc, attr.Field.getName());
    Object vtgt = PropertyUtils.getProperty(etgt, attr.Field.getName());

    int retval = 0;
    Class<?> ftype = attr.Field.getType();
    if (EnumPrimitives.isPrimitiveType(ftype)) {
        EnumPrimitives type = EnumPrimitives.type(ftype);
        switch (type) {
        case ECharacter:
            retval = (Character) vsrc - (Character) vtgt;
            break;
        case EShort:
            retval = (Short) vsrc - (Short) vtgt;
            break;
        case EInteger:
            retval = (Integer) vsrc - (Integer) vtgt;
            break;
        case ELong:
            retval = (int) ((Long) vsrc - (Long) vtgt);
            break;
        case EFloat:
            float fval = ((Float) vsrc - (Float) vtgt);
            if (fval < 0) {
                retval = -1;// w  w  w.j  a va  2  s.c  o m
            } else if (fval > 0) {
                retval = 1;
            }
            break;
        case EDouble:
            double dval = ((Double) vsrc - (Double) vtgt);
            if (dval < 0) {
                retval = -1;
            } else if (dval > 0) {
                retval = 1;
            }
            break;
        default:
            break;
        }
    } else {
        if (ftype.equals(String.class)) {
            retval = ((String) vsrc).compareTo((String) vtgt);
        } else if (ftype.equals(Date.class)) {
            retval = ((Date) vsrc).compareTo((Date) vtgt);
        }
    }
    if (column.getOrder() == EnumSortOrder.DSC) {
        retval = retval * -1;
    }
    return retval;
}

From source file:com.base2.kagura.core.report.connectors.ReportConnector.java

/**
 * Runs the report./*from  w  w w. ja va 2 s.c o  m*/
 * @param extra middleware provided values, such as date/time, system configuration, logged in user, permissions
 *              and what ever else is of value to the user.
 */
public void run(Map<String, Object> extra) {
    if (getParameterConfig() != null) {
        Boolean parametersRequired = false;
        List<String> requiredParameters = new ArrayList<String>();
        for (ParamConfig paramConfig : getParameterConfig()) {
            if (BooleanUtils.isTrue(paramConfig.getRequired())) {
                try {
                    if (StringUtils
                            .isBlank(ObjectUtils.toString(PropertyUtils.getProperty(paramConfig, "value")))) {
                        parametersRequired = true;
                        requiredParameters.add(paramConfig.getName());
                    }
                } catch (IllegalAccessException e) {
                    e.printStackTrace();
                } catch (InvocationTargetException e) {
                    e.printStackTrace();
                } catch (NoSuchMethodException e) {
                    e.printStackTrace();
                }
            }
        }
        if (parametersRequired) {
            errors.add("Some required parameters weren't filled in: "
                    + StringUtils.join(requiredParameters, ", ") + ".");
            return;
        }
    }
    runReport(extra);
}

From source file:com.tobedevoured.modelcitizen.template.JavaBeanTemplate.java

public Object get(Object model, String property) throws BlueprintTemplateException {
    logger.trace("Getting property [{}] for Model [{}]", property, model);
    try {//from  w w  w .  j a  va 2  s  . c o  m
        return PropertyUtils.getProperty(model, property);
    } catch (IllegalAccessException propertyException) {
        throw new BlueprintTemplateException(propertyException);
    } catch (InvocationTargetException propertyException) {
        throw new BlueprintTemplateException(propertyException);
    } catch (NoSuchMethodException propertyException) {
        throw new BlueprintTemplateException(propertyException);
    }
}

From source file:com.googlecode.aviator.runtime.type.AviatorJavaType.java

@Override
public Object getValue(Map<String, Object> env) {
    try {/*from  w  w w.  j a  v  a 2s  . c  om*/
        if (env != null) {
            if (name.contains(".")) {
                return PropertyUtils.getProperty(env, name);
            } else {
                return env.get(name);
            }
        }
        return null;
    } catch (Throwable t) {
        throw new ExpressionRuntimeException("Could not find variable " + name, t);
    }
}

From source file:jp.co.ctc_g.jse.core.validation.constraints.feature.lessthanequalsto.LessThanEqualsToValidator.java

/**
 * {@inheritDoc}/* ww  w.  j  a  v a 2 s .c  om*/
 */
@Override
public boolean isValid(Object suspect, ConstraintValidatorContext context) {
    Object f = null;
    Object t = null;
    try {
        f = PropertyUtils.getProperty(suspect, lessThanEqualsTo.from());
        t = PropertyUtils.getProperty(suspect, lessThanEqualsTo.to());
    } catch (IllegalAccessException e) {
        if (L.isDebugEnabled()) {
            L.debug(Strings.substitute(R.getString("D-VALIDATOR-LESS-THAN-EQUALS-TO#0001"),
                    Maps.hash("from", lessThanEqualsTo.from()).map("to", lessThanEqualsTo.to()).map("target",
                            suspect.getClass().getSimpleName())));
        }
        throw new InternalException(AfterValidator.class, "E-VALIDATOR-LESS-THAN-EQUALS-TO#0001", e);
    } catch (InvocationTargetException e) {
        if (L.isDebugEnabled()) {
            L.debug(Strings.substitute(R.getString("D-VALIDATOR-LESS-THAN-EQUALS-TO#0002"),
                    Maps.hash("from", lessThanEqualsTo.from()).map("to", lessThanEqualsTo.to()).map("target",
                            suspect.getClass().getSimpleName())));
        }
        throw new InternalException(AfterValidator.class, "E-VALIDATOR-LESS-THAN-EQUALS-TO#0002", e);
    } catch (NoSuchMethodException e) {
        if (L.isDebugEnabled()) {
            L.debug(Strings.substitute(R.getString("D-VALIDATOR-LESS-THAN-EQUALS-TO#0003"),
                    Maps.hash("from", lessThanEqualsTo.from()).map("to", lessThanEqualsTo.to()).map("target",
                            suspect.getClass().getSimpleName())));
        }
        throw new InternalException(AfterValidator.class, "E-VALIDATOR-LESS-THAN-EQUALS-TO#0003", e);
    }
    if (f == null || t == null)
        return true;
    return Validators.lessThanEqualsTo(Validators.toBigDecimal(f), Validators.toBigDecimal(t)) ? true
            : addErrors(context);
}

From source file:com.stephenduncanjr.easymock.matcher.BeanProperty.java

/**
 * @see org.easymock.IArgumentMatcher#matches(java.lang.Object)
 *//*from w  ww  .j  a  v a2 s . com*/
public boolean matches(final Object actual) {
    for (final Entry<String, ?> entry : this.expectedProperties.entrySet()) {
        try {
            final Object actualValue = PropertyUtils.getProperty(actual, entry.getKey());
            if (!(entry.getValue() == actualValue || entry.getValue().equals(actualValue))) {
                return false;
            }
        } catch (IllegalAccessException e) {
            return false;
        } catch (InvocationTargetException e) {
            return false;
        } catch (NoSuchMethodException e) {
            return false;
        } catch (RuntimeException e) {
            return false;
        }
    }

    return true;
}

From source file:jp.co.ctc_g.jse.core.validation.constraints.feature.greaterthanequalsto.GreaterThanEqualsToValidator.java

/**
 * {@inheritDoc}//  ww w.j  a v a 2s  . co  m
 */
@Override
public boolean isValid(Object suspect, ConstraintValidatorContext context) {
    Object f = null;
    Object t = null;
    try {
        f = PropertyUtils.getProperty(suspect, greaterThanEqualsTo.from());
        t = PropertyUtils.getProperty(suspect, greaterThanEqualsTo.to());
    } catch (IllegalAccessException e) {
        if (L.isDebugEnabled()) {
            L.debug(Strings.substitute(R.getString("D-VALIDATOR-GREATER-THAN-EQUALS-TO#0001"),
                    Maps.hash("from", greaterThanEqualsTo.from()).map("to", greaterThanEqualsTo.to())
                            .map("target", suspect.getClass().getSimpleName())));
        }
        throw new InternalException(AfterValidator.class, "E-VALIDATOR-GREATER-THAN-EQUALS-TO#0001", e);
    } catch (InvocationTargetException e) {
        if (L.isDebugEnabled()) {
            L.debug(Strings.substitute(R.getString("D-VALIDATOR-GREATER-THAN-EQUALS-TO#0002"),
                    Maps.hash("from", greaterThanEqualsTo.from()).map("to", greaterThanEqualsTo.to())
                            .map("target", suspect.getClass().getSimpleName())));
        }
        throw new InternalException(AfterValidator.class, "E-VALIDATOR-GREATER-THAN-EQUALS-TO#0002", e);
    } catch (NoSuchMethodException e) {
        if (L.isDebugEnabled()) {
            L.debug(Strings.substitute(R.getString("D-VALIDATOR-GREATER-THAN-EQUALS-TO#0003"),
                    Maps.hash("from", greaterThanEqualsTo.from()).map("to", greaterThanEqualsTo.to())
                            .map("target", suspect.getClass().getSimpleName())));
        }
        throw new InternalException(AfterValidator.class, "E-VALIDATOR-GREATER-THAN-EQUALS-TO#0003", e);
    }
    if (f == null || t == null)
        return true;
    return Validators.greaterThanEqualsTo(Validators.toBigDecimal(f), Validators.toBigDecimal(t)) ? true
            : addErrors(context);
}

From source file:com.sf.ddao.factory.param.DefaultParameter.java

public Object extractParam(Context context) throws SQLException {
    final MethodCallCtx callCtx = CtxHelper.get(context, MethodCallCtx.class);
    Object[] args = callCtx.getArgs();
    Object param;//  ww  w  . java 2s.  c  o  m
    if (num != null) {
        if (num == RETURN_ARG_IDX) {
            param = callCtx.getLastReturn();
        } else {
            if (args.length <= num) {
                throw new SQLException("Query refers to argument #" + num + ", while method has only "
                        + args.length + " arguments");
            }
            param = args[num];
        }
    } else {
        param = args[0];
    }
    if (propName == null) {
        return param;
    }
    if (param instanceof Map) {
        return ((Map) param).get(propName);
    }
    try {
        return PropertyUtils.getProperty(param, propName);
    } catch (Exception e) {
        throw new SQLException("Failed to get statement parameter " + name + " from " + param, e);
    }
}

From source file:com.genologics.ri.container.Placement.java

public Placement(LimsEntityLinkable<Artifact> link) {
    this.uri = link.getUri();
    this.limsid = link.getLimsid();

    try {/*from w  w  w.  j av a 2 s . co m*/
        wellPosition = (String) PropertyUtils.getProperty(link, "wellPosition");
    } catch (Exception e) {
        // Ignore.
    }
}

From source file:fr.mael.microrss.util.Tools.java

public static HashMap<String, Object> toMap(UserConfig conf)
        throws IllegalAccessException, InvocationTargetException, NoSuchMethodException {
    HashMap<String, Object> options = new HashMap<String, Object>();
    PropertyDescriptor[] descs = PropertyUtils.getPropertyDescriptors(UserConfig.class);
    for (PropertyDescriptor desc : descs) {
        if (!desc.getName().equals("class") && !desc.getName().equals("user")) {
            options.put(desc.getName(), PropertyUtils.getProperty(conf, desc.getName()));
        }// w  ww .j a va2s  . c  o  m
    }
    return options;

}