Example usage for org.apache.commons.jxpath.ri InfoSetUtil stringValue

List of usage examples for org.apache.commons.jxpath.ri InfoSetUtil stringValue

Introduction

In this page you can find the example usage for org.apache.commons.jxpath.ri InfoSetUtil stringValue.

Prototype

public static String stringValue(Object object) 

Source Link

Document

Converts the supplied object to String.

Usage

From source file:org.openvpms.component.system.common.jxpath.TypeConversionUtil.java

/**
 * Converts the supplied object to BigDecimal
 * //from   www  . j av a2 s.c  o m
 * @param object
 *            the incoming object
 * @return BigDecimal            
 */
public static BigDecimal bigDecimalValue(Object object) {
    if (object instanceof BigDecimal) {
        return (BigDecimal) object;
    } else if (object instanceof BigInteger) {
        return new BigDecimal((BigInteger) object);
    } else if (object instanceof Number) {
        return new BigDecimal(((Number) object).doubleValue());
    } else if (object instanceof Boolean) {
        return new BigDecimal(((Boolean) object).booleanValue() ? 0.0 : 1.0);
    } else if (object instanceof String) {
        BigDecimal value = new BigDecimal(0.0);
        if (!object.equals("")) {
            try {
                value = new BigDecimal((String) object);
            } catch (NumberFormatException ex) {
                value = BigDecimal.ZERO;
            }
        }
        return value;
    } else if (object instanceof NodePointer) {
        return bigDecimalValue(((NodePointer) object).getValue());
    } else if (object instanceof EvalContext) {
        EvalContext ctx = (EvalContext) object;
        Pointer ptr = ctx.getSingleNodePointer();
        if (ptr != null) {
            return bigDecimalValue(ptr);
        }
        return BigDecimal.ZERO;
    }
    return bigDecimalValue(InfoSetUtil.stringValue(object));
}