KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > turbine > services > intake > model > NumberKeyField


1 package org.apache.turbine.services.intake.model;
2
3 /*
4  * Copyright 2001-2004 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 JavaDoc;
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,v 1.8.2.2 2004/05/20 03:16:39 seade Exp $
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 JavaDoc 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 JavaDoc 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 JavaDoc[] 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 JavaDoc val = parser.getString(getKey());
104             if (StringUtils.isNotEmpty(val))
105             {
106                 BigDecimal JavaDoc bd = canonicalizeDecimalInput(val);
107                 setTestValue(new NumberKey(bd));
108             }
109             else
110             {
111                 setTestValue(null);
112             }
113         }
114     }
115 }
116
Popular Tags