1 package org.apache.turbine.services.intake.model;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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 /***
30 * @author <a href="mailto:jmcnally@collab.net">John McNally</a>
31 * @author <a href="mailto:dlr@finemaltcoding.com">Daniel Rall</a>
32 * @author <a href="mailto:hps@intermeta.de">Henning P. Schmiedehausen</a>
33 * @author <a href="mailto:quintonm@bellsouth.net">Quinton McCombs</a>
34 * @version $Id: NumberKeyField.java 264148 2005-08-29 14:21:04Z henning $
35 */
36 public class NumberKeyField
37 extends BigDecimalField
38 {
39
40 /***
41 * Constructor.
42 *
43 * @param field xml field definition object
44 * @param group xml group definition object
45 * @throws IntakeException thrown by superclass
46 */
47 public NumberKeyField(XmlField field, Group group)
48 throws IntakeException
49 {
50 super(field, group);
51 }
52
53 /***
54 * Sets the default value for a NumberKey field
55 *
56 * @param prop Parameter for the default values
57 */
58 public void setDefaultValue(String prop)
59 {
60 if (prop == null)
61 {
62 return;
63 }
64
65 defaultValue = new NumberKey(prop);
66 }
67
68 /***
69 * A suitable validator.
70 *
71 * @return A suitable validator
72 */
73 protected String getDefaultValidator()
74 {
75 return NumberKeyValidator.class.getName();
76 }
77
78 /***
79 * Sets the value of the field from data in the parser.
80 */
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 }