BigDecimalValueTagpublic class BigDecimalValueTag extends ValueTag This class is a custom action intended to be used in the body of
a sqlQuery or an sqlUpdate action element. It adds the specified
value to its parent's value list. |
Fields Summary |
---|
private BigDecimal | value |
Methods Summary |
---|
public int | doEndTag()Gets the value, specified by the value attribute, the stringValue
attribute, the param attribute, or the name and property attributes,
and adds it to the parent's value list. If the value is a String
and a pattern attribute is specified, the String is converted
into the appropriate type before being added to the parent's
value list.
if (stringValue != null) {
value = toBigDecimal(stringValue, pattern);
}
else if (param != null) {
String paramValue = getParameter(param);
value = toBigDecimal(paramValue, pattern);
}
else if (name != null) {
value = getBigDecimal(name, property, pattern);
}
ValueTagParent parent =
(ValueTagParent) findAncestorWithClass(this, ValueTagParent.class);
if (parent == null) {
throw new JspException("The sqlBigDecimalValue action is not " +
"enclosed by a supported action type");
}
parent.addValue(new BigDecimalValue(value));
return EVAL_PAGE;
| private java.math.BigDecimal | getBigDecimal(java.lang.String beanName, java.lang.String propertyName, java.lang.String pattern)
BigDecimal bdValue = null;
Object bean = getBean(beanName);
Method readMethod = getPropertyReadMethod(bean, propertyName);
Class returnType = readMethod.getReturnType();
Object value = getValue(bean, readMethod, propertyName);
if (BigDecimal.class.isAssignableFrom(returnType)) {
bdValue = (BigDecimal) value;
}
else if (String.class.isAssignableFrom(returnType)) {
bdValue = toBigDecimal((String) value, pattern);
}
else {
throw new JspException("Read method for the " + propertyName +
" property in the bean named " + beanName + " is not of type " +
" String or BigDecimal");
}
return bdValue;
| public void | release()Releases all instance variables.
value = null;
super.release();
| public void | setValue(java.math.BigDecimal value)Sets the value property.
this.value = value;
| private java.math.BigDecimal | toBigDecimal(java.lang.String stringValue, java.lang.String pattern)
BigDecimal bdValue = null;
try {
Number number = StringFormat.toNumber(stringValue, pattern);
bdValue = new BigDecimal(number.doubleValue());
}
catch (ParseException e) {
throw new JspException(stringValue + " can not be converted to " +
" a BigDecimal using pattern: " + pattern + ". Message: " +
e.getMessage());
}
return bdValue;
|
|