Source Code Cross Referenced for DateTimeDataType.java in  » Database-ORM » MMBase » org » mmbase » datatypes » 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 » Database ORM » MMBase » org.mmbase.datatypes 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:
003:        This software is OSI Certified Open Source Software.
004:        OSI Certified is a certification mark of the Open Source Initiative.
005:
006:        The license (Mozilla version 1.0) can be read at the MMBase site.
007:        See http://www.MMBase.org/license
008:
009:         */
010:        package org.mmbase.datatypes;
011:
012:        import java.util.*;
013:
014:        import org.mmbase.bridge.*;
015:        import org.mmbase.util.Casting;
016:        import org.mmbase.util.DynamicDate;
017:        import org.mmbase.util.logging.*;
018:
019:        /**
020:         * The date-time datatype further describes {@link java.util.Date} objects. The date can be
021:         * restricted to a certain period (using {@link #setMin}, {@link #setMax}, and {@link
022:         * org.mmbase.util.Casting#toDate}. The presentation logic can be specified using a pattern, see
023:         * {@link #getPattern}.
024:         *
025:         * @author Pierre van Rooden
026:         * @author Michiel Meeuwissen
027:         * @version $Id: DateTimeDataType.java,v 1.38 2007/12/10 12:27:01 michiel Exp $
028:         * @since MMBase-1.8
029:         */
030:        public class DateTimeDataType extends ComparableDataType {
031:
032:            public static final Date MIN_VALUE = new Date(Long.MIN_VALUE);
033:            public static final Date MAX_VALUE = new Date(Long.MAX_VALUE);
034:
035:            private static final Logger log = Logging
036:                    .getLoggerInstance(DateTimeDataType.class);
037:
038:            private static final long serialVersionUID = 1L; // increase this if object serialization changes (which we shouldn't do!)
039:
040:            // see javadoc of DateTimeFormat
041:            private boolean weakPattern = true; // means, may not be changed, must be cloned before changing something
042:            private DateTimePattern pattern = DateTimePattern.DEFAULT;
043:
044:            /**
045:             * Constructor for DateTime field.
046:             */
047:            public DateTimeDataType(String name) {
048:                super (name, Date.class);
049:                setMin(MIN_VALUE, true);
050:                setMax(MAX_VALUE, true);
051:            }
052:
053:            protected void xmlValue(org.w3c.dom.Element el, Object value) {
054:                if (value instanceof  DynamicDate) {
055:                    el.setAttribute("value", ((DynamicDate) value).getFormat());
056:                    el.setAttribute("eval", Casting.toString(value));
057:                } else {
058:                    super .xmlValue(el, value);
059:                }
060:            }
061:
062:            public void setDefaultValue(Object o) {
063:                log.debug("Setting default value " + o);
064:                //super.setDefaultValue(Casting.toDate(o));
065:                super .setDefaultValue(o == null ? null : Casting.toDate(o));
066:            }
067:
068:            protected void inheritProperties(BasicDataType origin) {
069:                super .inheritProperties(origin);
070:                if (origin instanceof  DateTimeDataType) {
071:                    DateTimeDataType dataType = (DateTimeDataType) origin;
072:                    if (weakPattern) {
073:                        pattern = dataType.pattern;
074:                    }
075:                }
076:            }
077:
078:            protected Object castToValidate(Object value, Node node, Field field)
079:                    throws CastException {
080:                if (value == null)
081:                    return null;
082:                try {
083:                    return DynamicDate.eval(Casting.toDate(value));
084:                } catch (Throwable t) {
085:                    throw new CastException(t);
086:                }
087:            }
088:
089:            /**
090:             * @return the minimum value as an <code>Date</code>, or very very long ago if there is no minimum.
091:             */
092:            public Date getMin() {
093:                Object min = getMinRestriction().getValue();
094:                return min == null ? MIN_VALUE : Casting.toDate(min);
095:            }
096:
097:            /**
098:             * @return the maximum value as an <code>Date</code>, or a very very in the future if there is no maximum.
099:             */
100:            public Date getMax() {
101:                Object max = getMaxRestriction().getValue();
102:                return max == null ? MAX_VALUE : Casting.toDate(max);
103:            }
104:
105:            /**
106:             * The 'pattern' of a 'DateTime' value gives a <code>DateTimePattern</code> object which can be used as an
107:             * indication for presentation.
108:             *
109:             * Basicly, this can indicate whether the objects present e.g. only a date, only a time and whether e.g. this time includes seconds or not.
110:             *
111:             * <code>DateTimePattern</code> is actually a wrapper arround a pattern, and that is used here.
112:             *
113:             */
114:            public DateTimePattern getPattern() {
115:                return pattern;
116:            }
117:
118:            /**
119:             * Set the pattern for a certain Locale.
120:             * See also {@link #getPattern}.
121:             */
122:            public void setPattern(String p, Locale locale) {
123:                if (weakPattern) {
124:                    pattern = new DateTimePattern(p);
125:                    weakPattern = false;
126:                } else {
127:                    if (locale == null || locale.equals(Locale.US)) {
128:                        pattern.set(p);
129:                    }
130:                }
131:                pattern.set(p, locale);
132:            }
133:
134:            public DataType clone(String name) {
135:                DateTimeDataType clone = (DateTimeDataType) super .clone(name);
136:                clone.weakPattern = true;
137:                return clone;
138:            }
139:
140:            protected StringBuilder toStringBuilder() {
141:                StringBuilder buf = super .toStringBuilder();
142:                buf.append(" " + pattern);
143:                return buf;
144:            }
145:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.