KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > turbine > services > intake > validator > NumberValidator


1 package org.apache.turbine.services.intake.validator;
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.util.Map JavaDoc;
20
21 /**
22  * Validates numbers with the following constraints in addition to those
23  * listed in DefaultValidator.
24  *
25  * <table>
26  * <tr><th>Name</th><th>Valid Values</th><th>Default Value</th></tr>
27  * <tr><td>minValue</td><td>greater than BigDecimal.MIN_VALUE</td>
28  * <td>&nbsp;</td></tr>
29  * <tr><td>maxValue</td><td>less than BigDecimal.MAX_VALUE</td>
30  * <td>&nbsp;</td></tr>
31  * <tr><td>notANumberMessage</td><td>Some text</td>
32  * <td>Entry was not a valid number</td></tr>
33  * </table>
34  *
35  * @author <a HREF="mailto:jmcnally@collab.net">John McNally</a>
36  * @author <a HREF="mailto:quintonm@bellsouth.net">Quinton McCombs</a>
37  * @author <a HREF="mailto:Colin.Chalmers@maxware.nl">Colin Chalmers</a>
38  * @version $Id: NumberValidator.java,v 1.8.2.2 2004/05/20 03:06:47 seade Exp $
39  */

40 abstract class NumberValidator
41         extends DefaultValidator
42 {
43     /** The message to show if field fails min-value test */
44     String JavaDoc minValueMessage = null;
45
46     /** The message to show if field fails max-value test */
47     String JavaDoc maxValueMessage = null;
48
49     /** The message to use for invalid numbers */
50     String JavaDoc invalidNumberMessage = null;
51
52     /**
53      * Extract the relevant parameters from the constraints listed
54      * in <rule> tags within the intake.xml file.
55      *
56      * @param paramMap a <code>Map</code> of <code>rule</code>'s
57      * containing constraints on the input.
58      * @exception InvalidMaskException an invalid mask was specified
59      */

60     public void init(Map JavaDoc paramMap)
61             throws InvalidMaskException
62     {
63         super.init(paramMap);
64
65         Constraint constraint =
66                 (Constraint) paramMap.get(INVALID_NUMBER_RULE_NAME);
67
68         if (constraint != null)
69         {
70             invalidNumberMessage = constraint.getMessage();
71         }
72     }
73
74     // ************************************************************
75
// ** Bean accessor methods **
76
// ************************************************************
77

78     /**
79      * Get the value of minValueMessage.
80      *
81      * @return value of minValueMessage.
82      */

83     public String JavaDoc getMinValueMessage()
84     {
85         return minValueMessage;
86     }
87
88     /**
89      * Set the value of minValueMessage.
90      *
91      * @param minValueMessage Value to assign to minValueMessage.
92      */

93     public void setMinValueMessage(String JavaDoc minValueMessage)
94     {
95         this.minValueMessage = minValueMessage;
96     }
97
98     /**
99      * Get the value of maxValueMessage.
100      *
101      * @return value of maxValueMessage.
102      */

103     public String JavaDoc getMaxValueMessage()
104     {
105         return maxValueMessage;
106     }
107
108     /**
109      * Set the value of maxValueMessage.
110      *
111      * @param maxValueMessage Value to assign to maxValueMessage.
112      */

113     public void setMaxValueMessage(String JavaDoc maxValueMessage)
114     {
115         this.maxValueMessage = maxValueMessage;
116     }
117
118     /**
119      * Get the value of invalidNumberMessage.
120      *
121      * @return value of invalidNumberMessage.
122      */

123     public String JavaDoc getInvalidNumberMessage()
124     {
125         return invalidNumberMessage;
126     }
127
128     /**
129      *
130      * Set the value of invalidNumberMessage.
131      * @param invalidNumberMessage Value to assign to invalidNumberMessage.
132      */

133     public void setInvalidNumberMessage(String JavaDoc invalidNumberMessage)
134     {
135         this.invalidNumberMessage = invalidNumberMessage;
136     }
137
138 }
139
Popular Tags