Source Code Cross Referenced for DoubleValidator.java in  » Project-Management » turbine » org » apache » turbine » services » intake » validator » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Project Management » turbine » org.apache.turbine.services.intake.validator 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.apache.turbine.services.intake.validator;
002:
003:        /*
004:         * Copyright 2001-2005 The Apache Software Foundation.
005:         *
006:         * Licensed under the Apache License, Version 2.0 (the "License")
007:         * you may not use this file except in compliance with the License.
008:         * You may obtain a copy of the License at
009:         *
010:         *     http://www.apache.org/licenses/LICENSE-2.0
011:         *
012:         * Unless required by applicable law or agreed to in writing, software
013:         * distributed under the License is distributed on an "AS IS" BASIS,
014:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015:         * See the License for the specific language governing permissions and
016:         * limitations under the License.
017:         */
018:
019:        import java.util.Map;
020:
021:        import org.apache.commons.lang.StringUtils;
022:
023:        /**
024:         * Validates Doubles with the following constraints in addition to those
025:         * listed in NumberValidator and DefaultValidator.
026:         *
027:         * <table>
028:         * <tr><th>Name</th><th>Valid Values</th><th>Default Value</th></tr>
029:         * <tr><td>minValue</td><td>greater than Double.MIN_VALUE</td>
030:         * <td>&nbsp;</td></tr>
031:         * <tr><td>maxValue</td><td>less than Double.MAX_VALUE</td>
032:         * <td>&nbsp;</td></tr>
033:         * <tr><td>invalidNumberMessage</td><td>Some text</td>
034:         * <td>Entry was not a valid number</td></tr>
035:         * </table>
036:         *
037:         * @author <a href="mailto:jmcnally@collab.net">John McNally</a>
038:         * @author <a href="mailto:Colin.Chalmers@maxware.nl">Colin Chalmers</a>
039:         * @version $Id: DoubleValidator.java 264148 2005-08-29 14:21:04Z henning $
040:         */
041:        public class DoubleValidator extends NumberValidator {
042:            /* Init the minValue to that for a Double */
043:            private double minValue = Double.NEGATIVE_INFINITY;
044:
045:            /* Init the maxValue to that for a Double */
046:            private double maxValue = Double.POSITIVE_INFINITY;
047:
048:            /**
049:             * Constructor to use when initialising Object
050:             *
051:             * @param paramMap
052:             * @throws InvalidMaskException
053:             */
054:            public DoubleValidator(Map paramMap) throws InvalidMaskException {
055:                invalidNumberMessage = "Entry was not a valid Double";
056:                init(paramMap);
057:            }
058:
059:            /**
060:             * Default Constructor
061:             */
062:            public DoubleValidator() {
063:            }
064:
065:            /**
066:             * Method to initialise Object
067:             *
068:             * @param paramMap
069:             * @throws InvalidMaskException
070:             */
071:            public void init(Map paramMap) throws InvalidMaskException {
072:                super .init(paramMap);
073:
074:                Constraint constraint = (Constraint) paramMap
075:                        .get(MIN_VALUE_RULE_NAME);
076:                if (constraint != null) {
077:                    String param = constraint.getValue();
078:                    minValue = Double.parseDouble(param);
079:                    minValueMessage = constraint.getMessage();
080:                }
081:
082:                constraint = (Constraint) paramMap.get(MAX_VALUE_RULE_NAME);
083:                if (constraint != null) {
084:                    String param = constraint.getValue();
085:                    maxValue = Double.parseDouble(param);
086:                    maxValueMessage = constraint.getMessage();
087:                }
088:            }
089:
090:            /**
091:             * Determine whether a testValue meets the criteria specified
092:             * in the constraints defined for this validator
093:             *
094:             * @param testValue a <code>String</code> to be tested
095:             * @exception ValidationException containing an error message if the
096:             * testValue did not pass the validation tests.
097:             */
098:            public void assertValidity(String testValue)
099:                    throws ValidationException {
100:                super .assertValidity(testValue);
101:
102:                double d = 0.0D;
103:
104:                if (required || StringUtils.isNotEmpty(testValue)) {
105:                    try {
106:                        d = Double.parseDouble(testValue);
107:                    } catch (RuntimeException e) {
108:                        errorMessage = invalidNumberMessage;
109:                        throw new ValidationException(invalidNumberMessage);
110:                    }
111:
112:                    if (d < minValue) {
113:                        errorMessage = minValueMessage;
114:                        throw new ValidationException(minValueMessage);
115:                    }
116:                    if (d > maxValue) {
117:                        errorMessage = maxValueMessage;
118:                        throw new ValidationException(maxValueMessage);
119:                    }
120:                }
121:            }
122:
123:            // ************************************************************
124:            // **                Bean accessor methods                   **
125:            // ************************************************************
126:
127:            /**
128:             * Get the value of minValue.
129:             *
130:             * @return value of minValue.
131:             */
132:            public double getMinValue() {
133:                return minValue;
134:            }
135:
136:            /**
137:             * Set the value of minValue.
138:             *
139:             * @param value  Value to assign to minValue.
140:             */
141:            public void setMinValue(double value) {
142:                this .minValue = value;
143:            }
144:
145:            /**
146:             * Get the value of maxValue.
147:             *
148:             * @return value of maxValue.
149:             */
150:            public double getMaxValue() {
151:                return maxValue;
152:            }
153:
154:            /**
155:             * Set the value of maxValue.
156:             *
157:             * @param value  Value to assign to maxValue.
158:             */
159:            public void setMaxValue(double value) {
160:                this.maxValue = value;
161:            }
162:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.