1 package org.apache.turbine.services.intake.model; 2 3 18 19 import java.math.BigDecimal ; 20 21 import org.apache.commons.lang.StringUtils; 22 23 import org.apache.torque.om.NumberKey; 24 25 import org.apache.turbine.services.intake.IntakeException; 26 import org.apache.turbine.services.intake.validator.NumberKeyValidator; 27 import org.apache.turbine.services.intake.xmlmodel.XmlField; 28 29 36 public class NumberKeyField 37 extends BigDecimalField 38 { 39 40 47 public NumberKeyField(XmlField field, Group group) 48 throws IntakeException 49 { 50 super(field, group); 51 } 52 53 58 public void setDefaultValue(String prop) 59 { 60 if (prop == null) 61 { 62 return; 63 } 64 65 defaultValue = new NumberKey(prop); 66 } 67 68 73 protected String getDefaultValidator() 74 { 75 return NumberKeyValidator.class.getName(); 76 } 77 78 81 protected void doSetValue() 82 { 83 if (isMultiValued) 84 { 85 String [] inputs = parser.getStrings(getKey()); 86 NumberKey[] values = new NumberKey[inputs.length]; 87 for (int i = 0; i < inputs.length; i++) 88 { 89 if (StringUtils.isNotEmpty(inputs[i])) 90 { 91 values[i] = new NumberKey( 92 canonicalizeDecimalInput(inputs[i])); 93 } 94 else 95 { 96 values[i] = null; 97 } 98 } 99 setTestValue(values); 100 } 101 else 102 { 103 String val = parser.getString(getKey()); 104 if (StringUtils.isNotEmpty(val)) 105 { 106 BigDecimal bd = canonicalizeDecimalInput(val); 107 setTestValue(new NumberKey(bd)); 108 } 109 else 110 { 111 setTestValue(null); 112 } 113 } 114 } 115 } 116 | Popular Tags |