Source Code Cross Referenced for DateBean.java in  » ERP-CRM-Financial » sakai » org » sakaiproject » metaobj » shared » model » 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 » ERP CRM Financial » sakai » org.sakaiproject.metaobj.shared.model 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**********************************************************************************
002:         * $URL: https://source.sakaiproject.org/svn/metaobj/tags/sakai_2-4-1/metaobj-impl/api-impl/src/java/org/sakaiproject/metaobj/shared/model/DateBean.java $
003:         * $Id: DateBean.java 22417 2007-03-12 13:49:39Z john.ellis@rsmart.com $
004:         ***********************************************************************************
005:         *
006:         * Copyright (c) 2004, 2005, 2006 The Sakai Foundation.
007:         * 
008:         * Licensed under the Educational Community License, Version 1.0 (the "License"); 
009:         * you may not use this file except in compliance with the License. 
010:         * You may obtain a copy of the License at
011:         * 
012:         *      http://www.opensource.org/licenses/ecl1.php
013:         * 
014:         * Unless required by applicable law or agreed to in writing, software 
015:         * distributed under the License is distributed on an "AS IS" BASIS, 
016:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
017:         * See the License for the specific language governing permissions and 
018:         * limitations under the License.
019:         *
020:         **********************************************************************************/package org.sakaiproject.metaobj.shared.model;
021:
022:        import java.text.MessageFormat;
023:        import java.text.Format;
024:        import java.text.ParseException;
025:        import java.util.Calendar;
026:        import java.util.Date;
027:        import java.util.GregorianCalendar;
028:        import java.util.List;
029:
030:        import org.apache.commons.logging.Log;
031:        import org.apache.commons.logging.LogFactory;
032:        import org.sakaiproject.metaobj.utils.mvc.intf.FieldValueWrapper;
033:        import org.sakaiproject.metaobj.utils.xml.NormalizationException;
034:        import org.sakaiproject.util.DateWidgetFormat;
035:
036:        public class DateBean implements  FieldValueWrapper {
037:            protected final Log logger = LogFactory.getLog(getClass());
038:            private String month = "";
039:            private String year = "";
040:            private String day = "";
041:            private String hour = "";
042:            private String minute = "";
043:            private String second = "";
044:            private String fullDate = null;
045:            boolean nullFlag = true;
046:
047:            private Format dateFormat;
048:            private DateWidgetFormat dateFormatUtil = new DateWidgetFormat();
049:
050:            public DateBean() {
051:                dateFormat = dateFormatUtil.getLocaleDateFormat();
052:            }
053:
054:            public DateBean(Date date) {
055:                dateFormat = dateFormatUtil.getLocaleDateFormat();
056:                if (date != null) {
057:                    setBackingDate(date);
058:                }
059:            }
060:
061:            public void setBackingDate(Date date) {
062:                Calendar cal = Calendar.getInstance();
063:                cal.setTime(date);
064:                setYear("" + cal.get(Calendar.YEAR));
065:                setMonth("" + (cal.get(Calendar.MONTH) + 1));
066:                setDay("" + cal.get(Calendar.DATE));
067:                setHour("" + cal.get(Calendar.HOUR));
068:                setMinute("" + cal.get(Calendar.MINUTE));
069:                setSecond("" + cal.get(Calendar.SECOND));
070:                nullFlag = false;
071:            }
072:
073:            public String getMonth() {
074:                return month;
075:            }
076:
077:            public void setMonth(String month) {
078:                this .month = month;
079:                checkFlag(month);
080:            }
081:
082:            public String getYear() {
083:                return year;
084:            }
085:
086:            public void setYear(String year) {
087:                this .year = year;
088:                checkFlag(year);
089:            }
090:
091:            public String getDay() {
092:                return day;
093:            }
094:
095:            public void setDay(String day) {
096:                this .day = day;
097:                checkFlag(day);
098:            }
099:
100:            public String getHour() {
101:                return hour;
102:            }
103:
104:            public void setHour(String hour) {
105:                this .hour = hour;
106:                checkFlag(hour);
107:            }
108:
109:            public String getMinute() {
110:                return minute;
111:            }
112:
113:            public void setMinute(String minute) {
114:                this .minute = minute;
115:                checkFlag(minute);
116:            }
117:
118:            public String getSecond() {
119:                return second;
120:            }
121:
122:            public void setSecond(String second) {
123:                this .second = second;
124:                checkFlag(second);
125:            }
126:
127:            public void setValue(Object value) {
128:                setBackingDate((Date) value);
129:                nullFlag = (value == null);
130:            }
131:
132:            public Object getValue() {
133:                return getDate();
134:            }
135:
136:            public void validate(String fieldName, List errors, String label) {
137:                if (nullFlag) {
138:                    return;
139:                }
140:
141:                if (fullDate != null) {
142:                    try {
143:                        setValue(dateFormat.parseObject(getFullDate()));
144:                    } catch (ParseException e) {
145:                        errors
146:                                .add(new ValidationError(
147:                                        label,
148:                                        fieldName,
149:                                        NormalizationException.DATE_INVALID_ERROR_CODE,
150:                                        new Object[] { getFullDate() },
151:                                        MessageFormat.format(
152:                                                "invalid date {0}",
153:                                                new Object[] { getFullDate() })));
154:                        nullFlag = true;
155:                    }
156:
157:                    return;
158:                }
159:
160:                try {
161:                    Integer.parseInt(getYear());
162:                } catch (NumberFormatException e) {
163:                    errors.add(new ValidationError(label, fieldName + ".year",
164:                            "invalid year {0}", new Object[] { getYear() },
165:                            MessageFormat.format("invalid year {0}",
166:                                    new Object[] { getYear() })));
167:                }
168:                try {
169:                    Integer.parseInt(getMonth());
170:                } catch (NumberFormatException e) {
171:                    errors.add(new ValidationError(label, fieldName + ".month",
172:                            "invalid month {0}", new Object[] { getYear() },
173:                            MessageFormat.format("invalid month {0}",
174:                                    new Object[] { getYear() })));
175:                }
176:                try {
177:                    Integer.parseInt(getDay());
178:                } catch (NumberFormatException e) {
179:                    errors.add(new ValidationError(label, fieldName + ".day",
180:                            "invalid day {0}", new Object[] { getYear() },
181:                            MessageFormat.format("invalid day {0}",
182:                                    new Object[] { getYear() })));
183:                }
184:
185:                /*
186:                try {
187:                   Integer.parseInt(getHour());
188:                } catch (NumberFormatException e) {
189:                   ValidationError error = new ValidationError("invalid hour: {0}",
190:                         new Object[]{getHour()});
191:                   errors.add(error);
192:                }
193:                try {
194:                   Integer.parseInt(getMinute());
195:                } catch (NumberFormatException e) {
196:                   ValidationError error = new ValidationError("invalid minute: {0}",
197:                         new Object[]{getMinute()});
198:                   errors.add(error);
199:                }
200:                try {
201:                   Integer.parseInt(getSecond());
202:                } catch (NumberFormatException e) {
203:                   ValidationError error = new ValidationError("invalid second: {0}",
204:                         new Object[]{getSecond()});
205:                   errors.add(error);
206:                }
207:                 */
208:            }
209:
210:            public Date getDate() {
211:                if (nullFlag) {
212:                    return null;
213:                }
214:
215:                return new GregorianCalendar(
216:                        getValue(getYear()),
217:                        getValue(getMonth()) - 1, // month is zero indexed
218:                        getValue(getDay()), getValue(getHour()),
219:                        getValue(getMinute()), getValue(getSecond())).getTime();
220:            }
221:
222:            protected int getValue(String value) {
223:                try {
224:                    return Integer.parseInt(value);
225:                } catch (NumberFormatException e) {
226:                    return 0;
227:                }
228:            }
229:
230:            protected void checkFlag(String value) {
231:                nullFlag = (value == null || value.length() == 0);
232:            }
233:
234:            public String getFullDate() {
235:                return fullDate;
236:            }
237:
238:            public void setFullDate(String fullDate) {
239:                this .fullDate = fullDate;
240:                checkFlag(fullDate);
241:            }
242:
243:            public Object clone() {
244:                try {
245:                    return super .clone();
246:                } catch (CloneNotSupportedException e) {
247:                    throw new RuntimeException(e);
248:                }
249:            }
250:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.