%line | %branch | |||||||||
---|---|---|---|---|---|---|---|---|---|---|
org.apache.turbine.services.intake.model.NumberKeyField |
|
|
1 | package org.apache.turbine.services.intake.model; |
|
2 | ||
3 | /* |
|
4 | * Copyright 2001-2005 The Apache Software Foundation. |
|
5 | * |
|
6 | * Licensed under the Apache License, Version 2.0 (the "License") |
|
7 | * you may not use this file except in compliance with the License. |
|
8 | * You may obtain a copy of the License at |
|
9 | * |
|
10 | * http://www.apache.org/licenses/LICENSE-2.0 |
|
11 | * |
|
12 | * Unless required by applicable law or agreed to in writing, software |
|
13 | * distributed under the License is distributed on an "AS IS" BASIS, |
|
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
15 | * See the License for the specific language governing permissions and |
|
16 | * limitations under the License. |
|
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 | 0 | super(field, group); |
51 | 0 | } |
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 | 0 | if (prop == null) |
61 | { |
|
62 | 0 | return; |
63 | } |
|
64 | ||
65 | 0 | defaultValue = new NumberKey(prop); |
66 | 0 | } |
67 | ||
68 | /** |
|
69 | * A suitable validator. |
|
70 | * |
|
71 | * @return A suitable validator |
|
72 | */ |
|
73 | protected String getDefaultValidator() |
|
74 | { |
|
75 | 0 | 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 | 0 | if (isMultiValued) |
84 | { |
|
85 | 0 | String[] inputs = parser.getStrings(getKey()); |
86 | 0 | NumberKey[] values = new NumberKey[inputs.length]; |
87 | 0 | for (int i = 0; i < inputs.length; i++) |
88 | { |
|
89 | 0 | if (StringUtils.isNotEmpty(inputs[i])) |
90 | { |
|
91 | 0 | values[i] = new NumberKey( |
92 | canonicalizeDecimalInput(inputs[i])); |
|
93 | } |
|
94 | else |
|
95 | { |
|
96 | 0 | values[i] = null; |
97 | } |
|
98 | } |
|
99 | 0 | setTestValue(values); |
100 | } |
|
101 | else |
|
102 | { |
|
103 | 0 | String val = parser.getString(getKey()); |
104 | 0 | if (StringUtils.isNotEmpty(val)) |
105 | { |
|
106 | 0 | BigDecimal bd = canonicalizeDecimalInput(val); |
107 | 0 | setTestValue(new NumberKey(bd)); |
108 | } |
|
109 | else |
|
110 | { |
|
111 | 0 | setTestValue(null); |
112 | } |
|
113 | } |
|
114 | 0 | } |
115 | } |
This report is generated by jcoverage, Maven and Maven JCoverage Plugin. |