Source Code Cross Referenced for LongRangeValidator.java in  » J2EE » myfaces-core-1.2.0 » javax » faces » 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 » J2EE » myfaces core 1.2.0 » javax.faces.validator 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2004 The Apache Software Foundation.
003:         *
004:         * Licensed under the Apache License, Version 2.0 (the "License");
005:         * you may not use this file except in compliance with the License.
006:         * You may obtain a copy of the License at
007:         *
008:         *      http://www.apache.org/licenses/LICENSE-2.0
009:         *
010:         * Unless required by applicable law or agreed to in writing, software
011:         * distributed under the License is distributed on an "AS IS" BASIS,
012:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013:         * See the License for the specific language governing permissions and
014:         * limitations under the License.
015:         */
016:        package javax.faces.validator;
017:
018:        import javax.faces.component.StateHolder;
019:        import javax.faces.component.UIComponent;
020:        import javax.faces.context.FacesContext;
021:
022:        /**
023:         * see Javadoc of <a href="http://java.sun.com/javaee/javaserverfaces/1.2/docs/api/index.html">JSF Specification</a>
024:         *
025:         * @author Manfred Geiler (latest modification by $Author: cagatay $)
026:         * @author Thomas Spiegl
027:         * @version $Revision: 517405 $ $Date: 2007-03-12 22:23:37 +0100 (Mo, 12 Mrz 2007) $
028:         */
029:        public class LongRangeValidator implements  Validator, StateHolder {
030:            // FIELDS
031:            public static final String MAXIMUM_MESSAGE_ID = "javax.faces.validator.LongRangeValidator.MAXIMUM";
032:            public static final String MINIMUM_MESSAGE_ID = "javax.faces.validator.LongRangeValidator.MINIMUM";
033:            public static final String TYPE_MESSAGE_ID = "javax.faces.validator.LongRangeValidator.TYPE";
034:            public static final String VALIDATOR_ID = "javax.faces.LongRange";
035:            public static final String NOT_IN_RANGE_MESSAGE_ID = "javax.faces.validator.LongRangeValidator.NOT_IN_RANGE";
036:
037:            private Long _minimum = null;
038:            private Long _maximum = null;
039:            private boolean _transient = false;
040:
041:            // CONSTRUCTORS
042:            public LongRangeValidator() {
043:            }
044:
045:            public LongRangeValidator(long maximum) {
046:                _maximum = new Long(maximum);
047:            }
048:
049:            public LongRangeValidator(long maximum, long minimum) {
050:                _maximum = new Long(maximum);
051:                _minimum = new Long(minimum);
052:            }
053:
054:            // VALIDATE
055:            public void validate(FacesContext facesContext,
056:                    UIComponent uiComponent, Object value)
057:                    throws ValidatorException {
058:                if (facesContext == null)
059:                    throw new NullPointerException("facesContext");
060:                if (uiComponent == null)
061:                    throw new NullPointerException("uiComponent");
062:
063:                if (value == null) {
064:                    return;
065:                }
066:
067:                double dvalue = parseLongValue(facesContext, uiComponent, value);
068:                if (_minimum != null && _maximum != null) {
069:                    if (dvalue < _minimum.longValue()
070:                            || dvalue > _maximum.longValue()) {
071:                        Object[] args = {
072:                                _minimum,
073:                                _maximum,
074:                                _MessageUtils.getLabel(facesContext,
075:                                        uiComponent) };
076:                        throw new ValidatorException(_MessageUtils
077:                                .getErrorMessage(facesContext,
078:                                        NOT_IN_RANGE_MESSAGE_ID, args));
079:                    }
080:                } else if (_minimum != null) {
081:                    if (dvalue < _minimum.longValue()) {
082:                        Object[] args = {
083:                                _minimum,
084:                                _MessageUtils.getLabel(facesContext,
085:                                        uiComponent) };
086:                        throw new ValidatorException(_MessageUtils
087:                                .getErrorMessage(facesContext,
088:                                        MINIMUM_MESSAGE_ID, args));
089:                    }
090:                } else if (_maximum != null) {
091:                    if (dvalue > _maximum.longValue()) {
092:                        Object[] args = {
093:                                _maximum,
094:                                _MessageUtils.getLabel(facesContext,
095:                                        uiComponent) };
096:                        throw new ValidatorException(_MessageUtils
097:                                .getErrorMessage(facesContext,
098:                                        MAXIMUM_MESSAGE_ID, args));
099:                    }
100:                }
101:            }
102:
103:            private long parseLongValue(FacesContext facesContext,
104:                    UIComponent uiComponent, Object value)
105:                    throws ValidatorException {
106:                if (value instanceof  Number) {
107:                    return ((Number) value).longValue();
108:                }
109:
110:                try {
111:                    return Long.parseLong(value.toString());
112:                } catch (NumberFormatException e) {
113:                    Object[] args = { _MessageUtils.getLabel(facesContext,
114:                            uiComponent) };
115:                    throw new ValidatorException(_MessageUtils.getErrorMessage(
116:                            facesContext, TYPE_MESSAGE_ID, args));
117:                }
118:
119:            }
120:
121:            // GETTER & SETTER
122:            public long getMaximum() {
123:                return _maximum != null ? _maximum.longValue() : Long.MAX_VALUE;
124:            }
125:
126:            public void setMaximum(long maximum) {
127:                _maximum = new Long(maximum);
128:            }
129:
130:            public long getMinimum() {
131:                return _minimum != null ? _minimum.longValue() : Long.MIN_VALUE;
132:            }
133:
134:            public void setMinimum(long minimum) {
135:                _minimum = new Long(minimum);
136:            }
137:
138:            public boolean isTransient() {
139:                return _transient;
140:            }
141:
142:            public void setTransient(boolean transientValue) {
143:                _transient = transientValue;
144:            }
145:
146:            // RESTORE & SAVE STATE
147:            public Object saveState(FacesContext context) {
148:                Object values[] = new Object[2];
149:                values[0] = _maximum;
150:                values[1] = _minimum;
151:                return values;
152:            }
153:
154:            public void restoreState(FacesContext context, Object state) {
155:                Object values[] = (Object[]) state;
156:                _maximum = (Long) values[0];
157:                _minimum = (Long) values[1];
158:            }
159:
160:            // MISC
161:            public boolean equals(Object o) {
162:                if (this  == o)
163:                    return true;
164:                if (!(o instanceof  LongRangeValidator))
165:                    return false;
166:
167:                final LongRangeValidator longRangeValidator = (LongRangeValidator) o;
168:
169:                if (_maximum != null ? !_maximum
170:                        .equals(longRangeValidator._maximum)
171:                        : longRangeValidator._maximum != null)
172:                    return false;
173:                if (_minimum != null ? !_minimum
174:                        .equals(longRangeValidator._minimum)
175:                        : longRangeValidator._minimum != null)
176:                    return false;
177:
178:                return true;
179:            }
180:
181:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.