View Javadoc
1 /* 2 * Copyright (C) The Spice Group. All rights reserved. 3 * 4 * This software is published under the terms of the Spice 5 * Software License version 1.1, a copy of which has been included 6 * with this distribution in the LICENSE.txt file. 7 */ 8 package org.codehaus.spice.converter.lib; 9 10 import java.math.BigDecimal; 11 import org.codehaus.spice.converter.AbstractConverter; 12 import org.codehaus.spice.converter.ConverterException; 13 14 /*** 15 * String to BigDecimal converter. 16 * 17 * @author Peter Donald 18 * @version $Revision: 1.1 $ $Date: 2003/12/02 08:37:56 $ 19 */ 20 public class StringToBigDecimalConverter 21 extends AbstractConverter 22 { 23 /*** 24 * Construct the converter. 25 */ 26 public StringToBigDecimalConverter() 27 { 28 this( null ); 29 } 30 31 /*** 32 * Construct the converter with a default value. 33 * If the default value is non-null, it will be returned if unable 34 * to convert object to correct type. 35 * 36 * @param defaultValue the default value 37 */ 38 public StringToBigDecimalConverter( final BigDecimal defaultValue ) 39 { 40 super( String.class, BigDecimal.class, defaultValue ); 41 } 42 43 /*** 44 * Converts a String to a BigDecimal. 45 * 46 * @param object the original object to convert 47 * @param context the context in which to convert object (unused) 48 * @return the converted object 49 * @throws ConverterException if error converting object 50 */ 51 public Object convert( final Object object, final Object context ) 52 throws ConverterException 53 { 54 try 55 { 56 return new BigDecimal( object.toString() ); 57 } 58 catch( final NumberFormatException nfe ) 59 { 60 return noConvert( object, nfe ); 61 } 62 } 63 } 64

This page was automatically generated by Maven