Source Code Cross Referenced for TimeRangeValidator.java in  » Workflow-Engines » osbl-1_0 » org » conform » 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 » Workflow Engines » osbl 1_0 » org.conform.validator 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.conform.validator;
002:
003:        import org.conform.Validator;
004:        import org.conform.ValidationException;
005:
006:        import java.util.Calendar;
007:        import java.sql.Time;
008:        import java.lang.annotation.Annotation;
009:
010:        public class TimeRangeValidator implements  Validator {
011:            private Time from;
012:            private Time until;
013:            private boolean fromInclusive;
014:            private boolean untilInclusive;
015:            private boolean fromNow;
016:            private boolean untilNow;
017:
018:            public TimeRangeValidator() {
019:            }
020:
021:            public TimeRangeValidator(Annotation annotation) {
022:                TimeRange dateRange = (TimeRange) annotation;
023:                switch (dateRange.from()) {
024:                case NOW_INCLUSIVE:
025:                    fromInclusive = true;
026:                case NOW:
027:                    fromNow = true;
028:                }
029:                switch (dateRange.until()) {
030:                case NOW_INCLUSIVE:
031:                    untilInclusive = true;
032:                case NOW:
033:                    untilNow = true;
034:                }
035:            }
036:
037:            public TimeRangeValidator(Time from, Time until) {
038:                this .from = from;
039:                this .until = until;
040:            }
041:
042:            public TimeRangeValidator(Time from, boolean fromInclusive,
043:                    Time until, boolean untilInclusive) {
044:                this .from = from;
045:                this .fromInclusive = fromInclusive;
046:                this .until = until;
047:                this .untilInclusive = untilInclusive;
048:            }
049:
050:            public Time getFrom() {
051:                return from;
052:            }
053:
054:            public void setFrom(Time from) {
055:                this .from = from;
056:            }
057:
058:            public Time getUntil() {
059:                return until;
060:            }
061:
062:            public void setUntil(Time until) {
063:                this .until = until;
064:            }
065:
066:            public boolean isFromInclusive() {
067:                return fromInclusive;
068:            }
069:
070:            public void setFromInclusive(boolean fromInclusive) {
071:                this .fromInclusive = fromInclusive;
072:            }
073:
074:            public boolean isUntilInclusive() {
075:                return untilInclusive;
076:            }
077:
078:            public void setUntilInclusive(boolean untilInclusive) {
079:                this .untilInclusive = untilInclusive;
080:            }
081:
082:            /**
083:             * ...[...]...
084:             *    *****
085:             * ...]...[...
086:             *     ***
087:             */
088:            public Object validate(Object value) {
089:                if (value == null)
090:                    return null;
091:
092:                Time time = (Time) value;
093:
094:                if (fromNow)
095:                    from = new Time(System.currentTimeMillis());
096:                if (untilNow)
097:                    until = new Time(System.currentTimeMillis());
098:
099:                if (from != null
100:                        && ((fromInclusive && time.before(from)) || (!fromInclusive && !time
101:                                .after(from))))
102:                    throw new ValidationException(
103:                            new ValidationException.Message(
104:                                    getFromMessage(fromInclusive),
105:                                    new Object[] { value, from, until }));
106:                if (until != null
107:                        && ((untilInclusive && time.after(until)) || (!untilInclusive && !time
108:                                .before(until))))
109:                    throw new ValidationException(
110:                            new ValidationException.Message(
111:                                    getUntilMessage(untilInclusive),
112:                                    new Object[] { value, from, until }));
113:
114:                return value;
115:            }
116:
117:            private String getFromMessage(boolean fromInclusive) {
118:                return fromInclusive ? "validation.timeFromInclusive"
119:                        : "validation.timeFrom";
120:            }
121:
122:            private String getUntilMessage(boolean untilInclusive) {
123:                return untilInclusive ? "validation.timeUntilInclusive"
124:                        : "validation.timeUntil";
125:            }
126:
127:            public static Time time(int hour, int minute, int second) {
128:                Calendar calendar = Calendar.getInstance();
129:                calendar.set(Calendar.SECOND, second);
130:                calendar.set(Calendar.MINUTE, minute);
131:                calendar.set(Calendar.HOUR, hour);
132:                Time time = new Time(calendar.getTime().getTime());
133:                System.out.println("time = " + time);
134:                return time;
135:            }
136:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.