Source Code Cross Referenced for DateRange.java in  » Content-Management-System » harmonise » org » openharmonise » vfs » metadata » range » 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 » Content Management System » harmonise » org.openharmonise.vfs.metadata.range 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * The contents of this file are subject to the 
003:         * Mozilla Public License Version 1.1 (the "License"); 
004:         * you may not use this file except in compliance with the License. 
005:         * You may obtain a copy of the License at http://www.mozilla.org/MPL/
006:         *
007:         * Software distributed under the License is distributed on an "AS IS"
008:         * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. 
009:         * See the License for the specific language governing rights and 
010:         * limitations under the License.
011:         *
012:         * The Initial Developer of the Original Code is Simulacra Media Ltd.
013:         * Portions created by Simulacra Media Ltd are Copyright (C) Simulacra Media Ltd, 2004.
014:         *
015:         * All Rights Reserved.
016:         *
017:         * Contributor(s):
018:         */
019:        package org.openharmonise.vfs.metadata.range;
020:
021:        import java.text.*;
022:        import java.text.ParseException;
023:        import java.util.Date;
024:
025:        import org.openharmonise.commons.xml.*;
026:        import org.openharmonise.vfs.metadata.*;
027:        import org.openharmonise.vfs.metadata.value.*;
028:        import org.w3c.dom.DOMException;
029:        import org.w3c.dom.Element;
030:        import org.w3c.dom.Node;
031:        import org.w3c.dom.NodeList;
032:        import org.w3c.dom.Text;
033:
034:        /**
035:         * This is the range for date type properties.
036:         * 
037:         * @author Matthew Large
038:         * @version $Revision: 1.1 $
039:         *
040:         */
041:        public class DateRange extends AbstractRange implements  Range {
042:
043:            /**
044:             * Format for date values.
045:             */
046:            public static final String XSD_DATE_FORMAT = "yyyy-MM-dd G";
047:
048:            /**
049:             * Date formatter.
050:             */
051:            private static SimpleDateFormat df = new java.text.SimpleDateFormat(
052:                    XSD_DATE_FORMAT);
053:
054:            /**
055:             * Minimum inclusive date.
056:             */
057:            private Date m_dMinInclusive = null;
058:
059:            /**
060:             * Maximum inclusive date.
061:             */
062:            private Date m_dMaxInclusive = null;
063:
064:            /**
065:             * Minimum exclusive date.
066:             */
067:            private Date m_dMinExclusive = null;
068:
069:            /**
070:             * Maximum exclusive date.
071:             */
072:            private Date m_dMaxExclusive = null;
073:
074:            /**
075:             * 
076:             */
077:            public DateRange() {
078:                super ();
079:            }
080:
081:            /* (non-Javadoc)
082:             * @see com.simulacramedia.vfs.metadata.range.AbstractRange#validate(java.lang.String)
083:             */
084:            public ValidationResult validate(ValueInstance value) {
085:                boolean bIsValid = true;
086:                Date maxDt = getMaximum();
087:                Date minDt = getMinimum();
088:                Date curDate = getDate(((DateValue) value).getValue());
089:
090:                if (maxDt != null && curDate.after(maxDt)) {
091:                    bIsValid = false;
092:                }
093:
094:                if (bIsValid == true && minDt != null && curDate.before(minDt)) {
095:                    bIsValid = false;
096:                }
097:
098:                return new ValidationResult(bIsValid, "");
099:            }
100:
101:            /**
102:             * Returns a {@link Date} object from formatted text.
103:             * 
104:             * @param sValue Date formatted text
105:             * @return Date
106:             */
107:            private Date getDate(String sValue) {
108:                Date date = null;
109:
110:                try {
111:                    if (sValue != null && sValue.length() > 0) {
112:                        date = df.parse(sValue);
113:                    }
114:
115:                } catch (ParseException e) {
116:                    e.printStackTrace();
117:                }
118:
119:                return date;
120:            }
121:
122:            /**
123:             * Returns the minimum date value, will use minimum <i>inclusive</i> value if
124:             * there is one, else it returns the minimum <i>exclusive</i> value.
125:             * 
126:             * @return Minimum date value
127:             */
128:            public Date getMinimum() {
129:                if (this .m_dMinInclusive != null) {
130:                    return this .m_dMinInclusive;
131:                } else {
132:                    return this .m_dMinExclusive;
133:                }
134:            }
135:
136:            /**
137:             * Returns the maximum date value, will use maximum <i>inclusive</i> value if
138:             * there is one, else it returns the maximum <i>exclusive</i> value.
139:             * 
140:             * @return Maximum date value
141:             */
142:            public Date getMaximum() {
143:                if (this .m_dMinInclusive != null) {
144:                    return this .m_dMaxInclusive;
145:                } else {
146:                    return this .m_dMaxExclusive;
147:                }
148:            }
149:
150:            /**
151:             * Sets the minimum <i>inclusive</i> date value.
152:             * 
153:             * @param dt Date value
154:             */
155:            public void setMinimum(Date dt) {
156:                this .m_dMinInclusive = dt;
157:            }
158:
159:            /**
160:             * Sets the miaximum <i>inclusive</i> date value.
161:             * 
162:             * @param dt Date value
163:             */
164:            public void setMaximum(Date dt) {
165:                this .m_dMaxInclusive = dt;
166:            }
167:
168:            /* (non-Javadoc)
169:             * @see com.simulacramedia.vfs.metadata.Range#instantiate(org.w3c.dom.Element)
170:             */
171:            public void instantiate(Element elRange) {
172:                Element elRestriction = XMLUtils.getFirstElementChild(elRange);
173:                NodeList nl = elRestriction.getChildNodes();
174:                for (int i = 0; i < nl.getLength(); i++) {
175:                    Node node = nl.item(i);
176:                    if (node.getNodeType() == Node.ELEMENT_NODE) {
177:                        Element element = (Element) node;
178:                        if (element.getLocalName().equalsIgnoreCase(
179:                                "minInclusive")) {
180:                            Node node2 = element.getFirstChild();
181:                            if (node2.getNodeType() == Node.TEXT_NODE) {
182:                                java.text.SimpleDateFormat df = new java.text.SimpleDateFormat(
183:                                        XSD_DATE_FORMAT);
184:                                try {
185:                                    this .m_dMinInclusive = df
186:                                            .parse(((Text) node2)
187:                                                    .getNodeValue());
188:                                } catch (DOMException e) {
189:                                    e.printStackTrace();
190:                                } catch (ParseException e) {
191:                                    e.printStackTrace();
192:                                }
193:                            }
194:                        } else if (element.getLocalName().equalsIgnoreCase(
195:                                "maxInclusive")) {
196:                            Node node2 = element.getFirstChild();
197:                            if (node2.getNodeType() == Node.TEXT_NODE) {
198:                                java.text.SimpleDateFormat df = new java.text.SimpleDateFormat(
199:                                        XSD_DATE_FORMAT);
200:                                try {
201:                                    this .m_dMaxInclusive = df
202:                                            .parse(((Text) node2)
203:                                                    .getNodeValue());
204:                                } catch (DOMException e) {
205:                                    e.printStackTrace();
206:                                } catch (ParseException e) {
207:                                    e.printStackTrace();
208:                                }
209:                            }
210:                        } else if (element.getLocalName().equalsIgnoreCase(
211:                                "minExclusive")) {
212:                            Node node2 = element.getFirstChild();
213:                            if (node2.getNodeType() == Node.TEXT_NODE) {
214:                                java.text.SimpleDateFormat df = new java.text.SimpleDateFormat(
215:                                        XSD_DATE_FORMAT);
216:                                try {
217:                                    this .m_dMinExclusive = df
218:                                            .parse(((Text) node2)
219:                                                    .getNodeValue());
220:                                } catch (DOMException e) {
221:                                    e.printStackTrace();
222:                                } catch (ParseException e) {
223:                                    e.printStackTrace();
224:                                }
225:                            }
226:                        } else if (element.getLocalName().equalsIgnoreCase(
227:                                "maxExclusive")) {
228:                            Node node2 = element.getFirstChild();
229:                            if (node2.getNodeType() == Node.TEXT_NODE) {
230:                                java.text.SimpleDateFormat df = new java.text.SimpleDateFormat(
231:                                        XSD_DATE_FORMAT);
232:                                try {
233:                                    this .m_dMaxExclusive = df
234:                                            .parse(((Text) node2)
235:                                                    .getNodeValue());
236:                                } catch (DOMException e) {
237:                                    e.printStackTrace();
238:                                } catch (ParseException e) {
239:                                    e.printStackTrace();
240:                                }
241:                            }
242:                        }
243:                    }
244:                }
245:            }
246:
247:            public String toString() {
248:                StringBuffer sBuff = new StringBuffer();
249:
250:                java.text.SimpleDateFormat df = new java.text.SimpleDateFormat(
251:                        XSD_DATE_FORMAT);
252:
253:                sBuff.append("DateRange:\n");
254:                if (this .m_dMinInclusive != null) {
255:                    sBuff.append("minInclusive: ").append(
256:                            df.format(this .m_dMinInclusive)).append("\n");
257:                }
258:                if (this .m_dMaxInclusive != null) {
259:                    sBuff.append("maxInclusive: ").append(
260:                            df.format(this .m_dMaxInclusive)).append("\n");
261:                }
262:                if (this .m_dMinExclusive != null) {
263:                    sBuff.append("minExclusive: ").append(
264:                            df.format(this .m_dMinExclusive)).append("\n");
265:                }
266:                if (this .m_dMaxExclusive != null) {
267:                    sBuff.append("maxExclusive: ").append(
268:                            df.format(this .m_dMaxExclusive)).append("\n");
269:                }
270:
271:                return sBuff.toString();
272:            }
273:
274:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.