Your browser does not support JavaScript and this site utilizes JavaScript to build content and provide links to additional information. You should either enable JavaScript in your browser settings or use a browser that supports JavaScript in order to take full advantage of this site.
1 16 17 18 package org.apache.commons.beanutils.converters; 19 20 21 import java.math.BigDecimal ; 22 import org.apache.commons.beanutils.ConversionException; 23 import org.apache.commons.beanutils.Converter; 24 25 26 36 37 public final class BigDecimalConverter implements Converter { 38 39 40 42 43 47 public BigDecimalConverter() { 48 49 this.defaultValue = null; 50 this.useDefault = false; 51 52 } 53 54 55 61 public BigDecimalConverter(Object defaultValue) { 62 63 this.defaultValue = defaultValue; 64 this.useDefault = true; 65 66 } 67 68 69 71 72 75 private Object defaultValue = null; 76 77 78 81 private boolean useDefault = true; 82 83 84 86 87 97 public Object convert(Class type, Object value) { 98 99 if (value == null) { 100 if (useDefault) { 101 return (defaultValue); 102 } else { 103 throw new ConversionException("No value specified"); 104 } 105 } 106 107 if (value instanceof BigDecimal ) { 108 return (value); 109 } 110 111 try { 112 return (new BigDecimal (value.toString())); 113 } catch (Exception e) { 114 if (useDefault) { 115 return (defaultValue); 116 } else { 117 throw new ConversionException(e); 118 } 119 } 120 121 } 122 123 124 } 125
| Popular Tags
|