ankitp 2005/02/22 11:32:30 Modified: java/src/org/apache/xerces/xs/datatypes ByteList.java XSDateTime.java ObjectList.java java/src/org/apache/xerces/impl/dv/xs AbstractDateTimeDV.java DurationDV.java Log: fixes to interfaces Revision Changes Path 1.6 +2 -2 xml-xerces/java/src/org/apache/xerces/xs/datatypes/ByteList.java Index: ByteList.java =================================================================== RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/xs/datatypes/ByteList.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- ByteList.java 11 Feb 2005 21:31:51 -0000 1.5 +++ ByteList.java 22 Feb 2005 19:32:30 -0000 1.6 @@ -47,7 +47,7 @@ public boolean contains(byte item); /** - * Returns the <code>index</code>of the item in the collection. The index + * Returns the <code>index</code>th item in the collection. The index * starts at 0. * @param index index into the collection. * @return The <code>byte</code> at the <code>index</code>th 1.7 +68 -46 xml-xerces/java/src/org/apache/xerces/xs/datatypes/XSDateTime.java Index: XSDateTime.java =================================================================== RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/xs/datatypes/XSDateTime.java,v retrieving revision 1.6 retrieving revision 1.7 diff -u -r1.6 -r1.7 --- XSDateTime.java 11 Feb 2005 21:49:28 -0000 1.6 +++ XSDateTime.java 22 Feb 2005 19:32:30 -0000 1.7 @@ -27,53 +27,75 @@ */ public interface XSDateTime { - /** - * @return year - */ - public int getYear(); - - /** - * @return month - */ - public int getMonth(); - - /** - * @return day - */ - public int getDay(); - - /** - * @return hour - */ - public int getHour(); - - /** - * @return minutes - */ - public int getMinutes(); - - /** - * @return seconds - */ - public double getSeconds(); - - /** - * @return whether a timezone is specified - */ - public boolean hasTimeZone(); - - /** - * @return time hours - */ - public int getTimeZoneHours(); - - /** - * @return timezone minutes - */ - public int getTimeZoneMinutes(); + /** + * @return years – can be negative for datetime; + * returns 0 for duration types + */ + public int getYears(); + + /** + * @return months – can be negative only for durations; + * For duration types, it returns years*12 + months + */ + public int getMonths(); + + /** + * @return days – cannot be negative; + * returns 0 for duration types + */ + public int getDays(); + + /** + * @return hours – cannot be negative; + * returns 0 for duration types + */ + public int getHours(); + + /** + * @return minutes – cannot be negative; + * returns 0 for duration types + */ + public int getMinutes(); + + /** + * @return seconds – can be negative only for durations; + * For duration types, it returns days*24*3600 + hours*3600 + * + minutes*60 + seconds + */ + public double getSeconds(); + + /** + * @return boolean (true when timezone exists) + */ + public boolean hasTimeZone(); + + /** + * @return timezone hours (for GMT-xx:xx this will be negative), + * not valid for duration types + */ + public int getTimeZoneHours(); + + /** + * @return timezone minutes (for GMT-xx:xx this will be negative), + * not valid for duration types + */ + public int getTimeZoneMinutes(); /** - * @return original lexical value + * @return the original lexical value */ public String getLexicalValue(); + + /** + * @return a new datetime object with normalized values + * (has no effect on durations or objects already + * normalized) + */ + public XSDateTime normalize(); + + /** + * @return whether a datetime object is normalized or not + * (value is not useful for durations) + */ + public boolean isNormalized(); } 1.6 +4 -3 xml-xerces/java/src/org/apache/xerces/xs/datatypes/ObjectList.java Index: ObjectList.java =================================================================== RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/xs/datatypes/ObjectList.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- ObjectList.java 8 Oct 2004 15:20:39 -0000 1.5 +++ ObjectList.java 22 Feb 2005 19:32:30 -0000 1.6 @@ -1,5 +1,5 @@ /* - * Copyright 2004 The Apache Software Foundation. + * Copyright 2004, 2005 The Apache Software Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -51,7 +51,8 @@ * @param index index into the collection. * @return The <code>Object</code> at the <code>index</code>th * position in the <code>ObjectList</code>, or <code>null</code> if - * the index specified is not valid. + * the index specified is not valid - greater than or equal to the + * number of items in the list or less than zero. */ public Object item(int index); 1.33 +126 -57 xml-xerces/java/src/org/apache/xerces/impl/dv/xs/AbstractDateTimeDV.java Index: AbstractDateTimeDV.java =================================================================== RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/dv/xs/AbstractDateTimeDV.java,v retrieving revision 1.32 retrieving revision 1.33 diff -u -r1.32 -r1.33 --- AbstractDateTimeDV.java 11 Feb 2005 21:49:28 -0000 1.32 +++ AbstractDateTimeDV.java 22 Feb 2005 19:32:30 -0000 1.33 @@ -569,6 +569,8 @@ // should consider reorganizing it. // + //save unnormalized values + saveUnnormalized(date); //add minutes (from time zone) int negate = -1; @@ -619,6 +621,18 @@ /** + * @param date + */ + private void saveUnnormalized(DateTimeData date) { + date.unNormYear = date.year; + date.unNormMonth = date.month; + date.unNormDay = date.day; + date.unNormHour = date.hour; + date.unNormMinute = date.minute; + date.unNormSecond = date.second; + } + + /** * Resets object representation of date/time * * @param data date/time object @@ -803,7 +817,15 @@ int year, month, day, hour, minute, utc; double second; int timezoneHr, timezoneMin; - String originalValue; + private String originalValue; + boolean normalized = false; + + int unNormYear; + int unNormMonth; + int unNormDay; + int unNormHour; + int unNormMinute; + double unNormSecond; // used for comparisons - to decide the 'interesting' portions of // a date/time based data type. @@ -818,7 +840,7 @@ this.type = type; } public DateTimeData(int year, int month, int day, int hour, int minute, - double second, int utc, String originalValue, AbstractDateTimeDV type) { + double second, int utc, String originalValue, boolean normalized, AbstractDateTimeDV type) { this.year = year; this.month = month; this.day = day; @@ -840,65 +862,112 @@ } return canonical; } - /* (non-Javadoc) - * @see org.apache.xerces.xs.datatypes.XSDateTime#getYear() - */ - public int getYear() { - return year; - } - /* (non-Javadoc) - * @see org.apache.xerces.xs.datatypes.XSDateTime#getMonth() - */ - public int getMonth() { - return month; - } - /* (non-Javadoc) - * @see org.apache.xerces.xs.datatypes.XSDateTime#getDay() - */ - public int getDay() { - return day; - } - /* (non-Javadoc) - * @see org.apache.xerces.xs.datatypes.XSDateTime#getHour() - */ - public int getHour() { - return hour; - } - /* (non-Javadoc) - * @see org.apache.xerces.xs.datatypes.XSDateTime#getMinutes() - */ - public int getMinutes() { - return minute; - } - /* (non-Javadoc) - * @see org.apache.xerces.xs.datatypes.XSDateTime#getSeconds() - */ - public double getSeconds() { - return second; - } - /* (non-Javadoc) - * @see org.apache.xerces.xs.datatypes.XSDateTime#hasTimeZone() - */ - public boolean hasTimeZone() { - return utc != 0; - } - /* (non-Javadoc) - * @see org.apache.xerces.xs.datatypes.XSDateTime#getTimeZoneHours() - */ - public int getTimeZoneHours() { - return timezoneHr; - } - /* (non-Javadoc) - * @see org.apache.xerces.xs.datatypes.XSDateTime#getTimeZoneMinutes() - */ - public int getTimeZoneMinutes() { - return timezoneMin; - } + /* (non-Javadoc) + * @see org.apache.xerces.xs.datatypes.XSDateTime#getYear() + */ + public int getYears() { + if(type instanceof DurationDV) + return 0; + return normalized?year:unNormYear; + } + /* (non-Javadoc) + * @see org.apache.xerces.xs.datatypes.XSDateTime#getMonth() + */ + public int getMonths() { + if(type instanceof DurationDV) { + return year*12 + month; + } + return normalized?month:unNormMonth; + } + /* (non-Javadoc) + * @see org.apache.xerces.xs.datatypes.XSDateTime#getDay() + */ + public int getDays() { + if(type instanceof DurationDV) + return 0; + return normalized?day:unNormDay; + } + /* (non-Javadoc) + * @see org.apache.xerces.xs.datatypes.XSDateTime#getHour() + */ + public int getHours() { + if(type instanceof DurationDV) + return 0; + return normalized?hour:unNormHour; + } + /* (non-Javadoc) + * @see org.apache.xerces.xs.datatypes.XSDateTime#getMinutes() + */ + public int getMinutes() { + if(type instanceof DurationDV) + return 0; + return normalized?minute:unNormMinute; + } + /* (non-Javadoc) + * @see org.apache.xerces.xs.datatypes.XSDateTime#getSeconds() + */ + public double getSeconds() { + if(type instanceof DurationDV) { + return day*24*60*60 + hour*60*60 + minute*60 + second; + } + return normalized?second:unNormSecond; + } + /* (non-Javadoc) + * @see org.apache.xerces.xs.datatypes.XSDateTime#hasTimeZone() + */ + public boolean hasTimeZone() { + return utc != 0; + } + /* (non-Javadoc) + * @see org.apache.xerces.xs.datatypes.XSDateTime#getTimeZoneHours() + */ + public int getTimeZoneHours() { + return timezoneHr; + } + /* (non-Javadoc) + * @see org.apache.xerces.xs.datatypes.XSDateTime#getTimeZoneMinutes() + */ + public int getTimeZoneMinutes() { + return timezoneMin; + } /* (non-Javadoc) * @see org.apache.xerces.xs.datatypes.XSDateTime#getLexicalValue() */ public String getLexicalValue() { return originalValue; } + /* (non-Javadoc) + * @see org.apache.xerces.xs.datatypes.XSDateTime#normalize() + */ + public XSDateTime normalize() { + if(!normalized) { + DateTimeData dt = (DateTimeData)this.clone(); + dt.normalized = true; + return dt; + } + return this; + } + /* (non-Javadoc) + * @see org.apache.xerces.xs.datatypes.XSDateTime#isNormalized() + */ + public boolean isNormalized() { + return normalized; + } + + public Object clone() { + DateTimeData dt = new DateTimeData(this.year, this.month, this.day, this.hour, + this.minute, this.second, this.utc, this.originalValue, this.normalized, this.type); + dt.canonical = this.canonical; + dt.position = position; + dt.timezoneHr = this.timezoneHr; + dt.timezoneMin = this.timezoneMin; + dt.unNormYear = this.unNormYear; + dt.unNormMonth = this.unNormMonth; + dt.unNormDay = this.unNormDay; + dt.unNormHour = this.unNormHour; + dt.unNormMinute = this.unNormMinute; + dt.unNormSecond = this.unNormSecond; + return dt; + } } } 1.17 +7 -6 xml-xerces/java/src/org/apache/xerces/impl/dv/xs/DurationDV.java Index: DurationDV.java =================================================================== RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/dv/xs/DurationDV.java,v retrieving revision 1.16 retrieving revision 1.17 diff -u -r1.16 -r1.17 --- DurationDV.java 17 Dec 2004 20:21:24 -0000 1.16 +++ DurationDV.java 22 Feb 2005 19:32:30 -0000 1.17 @@ -1,5 +1,5 @@ /* - * Copyright 1999-2002,2004 The Apache Software Foundation. + * Copyright 1999-2002,2004, 2005 The Apache Software Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -40,10 +40,10 @@ // // the dates are in format: {CCYY,MM,DD, H, S, M, MS, timezone} private final static DateTimeData[] DATETIMES= { - new DateTimeData(1696, 9, 1, 0, 0, 0, 'Z', null, null), - new DateTimeData(1697, 2, 1, 0, 0, 0, 'Z', null, null), - new DateTimeData(1903, 3, 1, 0, 0, 0, 'Z', null, null), - new DateTimeData(1903, 7, 1, 0, 0, 0, 'Z', null, null)}; + new DateTimeData(1696, 9, 1, 0, 0, 0, 'Z', null, true, null), + new DateTimeData(1697, 2, 1, 0, 0, 0, 'Z', null, true, null), + new DateTimeData(1903, 3, 1, 0, 0, 0, 'Z', null, true, null), + new DateTimeData(1903, 7, 1, 0, 0, 0, 'Z', null, true, null)}; public Object getActualValue(String content, ValidationContext context) throws InvalidDatatypeValueException{ try{ @@ -64,6 +64,7 @@ protected DateTimeData parse(String str, int durationType) throws SchemaDateTimeException{ int len = str.length(); DateTimeData date= new DateTimeData(str, this); + date.normalized = true; int start = 0; char c=str.charAt(start++);
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]