You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xerces.apache.org by sa...@apache.org on 2004/08/26 04:14:41 UTC
cvs commit: xml-xerces/java/src/org/apache/xerces/impl/dv/xs AbstractDateTimeDV.java DateDV.java DateTimeDV.java DayDV.java DurationDV.java MonthDayDV.java MonthDV.java TimeDV.java YearDV.java YearMonthDV.java
sandygao 2004/08/25 19:14:41
Modified: java/src/org/apache/xerces/impl/dv/xs
AbstractDateTimeDV.java DateDV.java DateTimeDV.java
DayDV.java DurationDV.java MonthDayDV.java
MonthDV.java TimeDV.java YearDV.java
YearMonthDV.java
Log:
Fixing bug [XERCESJ-919]
http://nagoya.apache.org/jira/browse/XERCESJ-919
We used to ignore leading zeros in the fractional part of date/time "second" values;
we used to retain trailing zeros in the fractional part of data/time "second" values.
Revision Changes Path
1.14 +166 -123 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.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- AbstractDateTimeDV.java 24 Feb 2004 22:44:24 -0000 1.13
+++ AbstractDateTimeDV.java 26 Aug 2004 02:14:40 -0000 1.14
@@ -1,12 +1,12 @@
/*
* Copyright 1999-2004 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.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -41,12 +41,7 @@
//define shared variables for date/time
//define constants
- protected final static int CY = 0, M = 1, D = 2, h = 3,
- m = 4, s = 5, ms = 6, utc=7, hh=0, mm=1;
-
- //size for all objects must have the same fields:
- //CCYY, MM, DD, h, m, s, ms + timeZone
- protected final static int TOTAL_SIZE = 8;
+ protected final static int hh=0, mm=1;
//define constants to be used in assigning default values for
//all date/time excluding duration
@@ -60,8 +55,8 @@
// the parameters are in compiled form (from getActualValue)
public int compare (Object value1, Object value2) {
- return compareDates(((DateTimeData)value1).data,
- ((DateTimeData)value2).data, true);
+ return compareDates(((DateTimeData)value1),
+ ((DateTimeData)value2), true);
}//compare()
/**
@@ -73,23 +68,23 @@
* @param strict
* @return less, greater, less_equal, greater_equal, equal
*/
- protected short compareDates(int[] date1, int[] date2, boolean strict) {
- if ( date1[utc]==date2[utc] ) {
+ protected short compareDates(DateTimeData date1, DateTimeData date2, boolean strict) {
+ if (date1.utc == date2.utc) {
return compareOrder(date1, date2);
}
short c1, c2;
-
- int[] tempDate = new int[TOTAL_SIZE];
+
+ DateTimeData tempDate = new DateTimeData(this);
int[] timeZone = new int[2];
- if ( date1[utc]=='Z' ) {
+ if ( date1.utc=='Z' ) {
//compare date1<=date1<=(date2 with time zone -14)
//
cloneDate(date2, tempDate); //clones date1 value to global temporary storage: fTempDate
timeZone[hh]=14;
timeZone[mm]=0;
- tempDate[utc]='+';
+ tempDate.utc='+';
normalize(tempDate, timeZone);
c1 = compareOrder(date1, tempDate);
if (c1 == LESS_THAN)
@@ -100,7 +95,7 @@
cloneDate(date2, tempDate); //clones date1 value to global temporary storage: tempDate
timeZone[hh]=14;
timeZone[mm]=0;
- tempDate[utc]='-';
+ tempDate.utc='-';
normalize(tempDate, timeZone);
c2 = compareOrder(date1, tempDate);
if (c2 == GREATER_THAN)
@@ -108,14 +103,14 @@
return INDETERMINATE;
}
- else if ( date2[utc]=='Z' ) {
+ else if ( date2.utc=='Z' ) {
//compare (date1 with time zone -14)<=date2
//
cloneDate(date1, tempDate); //clones date1 value to global temporary storage: tempDate
timeZone[hh]=14;
timeZone[mm]=0;
- tempDate[utc]='-';
+ tempDate.utc='-';
if (DEBUG) {
System.out.println("tempDate=" + dateToString(tempDate));
}
@@ -133,7 +128,7 @@
cloneDate(date1, tempDate); //clones date1 value to global temporary storage: tempDate
timeZone[hh]=14;
timeZone[mm]=0;
- tempDate[utc]='+';
+ tempDate.utc='+';
normalize(tempDate, timeZone);
c2 = compareOrder(tempDate, date2);
if (DEBUG) {
@@ -156,16 +151,35 @@
* @param date2 date/time object
* @return 0 if date1 and date2 are equal, a value less than 0 if date1 is less than date2, a value greater than 0 if date1 is greater than date2
*/
- protected short compareOrder (int[] date1, int[] date2) {
-
- for ( int i=0;i<TOTAL_SIZE;i++ ) {
- if ( date1[i]<date2[i] ) {
- return -1;
- }
- else if ( date1[i]>date2[i] ) {
- return 1;
- }
- }
+ protected short compareOrder(DateTimeData date1, DateTimeData date2) {
+ if (date1.year < date2.year)
+ return -1;
+ if (date1.year > date2.year)
+ return 1;
+ if (date1.month < date2.month)
+ return -1;
+ if (date1.month > date2.month)
+ return 1;
+ if (date1.day < date2.day)
+ return -1;
+ if (date1.day > date2.day)
+ return 1;
+ if (date1.hour < date2.hour)
+ return -1;
+ if (date1.hour > date2.hour)
+ return 1;
+ if (date1.minute < date2.minute)
+ return -1;
+ if (date1.minute > date2.minute)
+ return 1;
+ if (date1.second < date2.second)
+ return -1;
+ if (date1.second > date2.second)
+ return 1;
+ if (date1.utc < date2.utc)
+ return -1;
+ if (date1.utc > date2.utc)
+ return 1;
return 0;
}
@@ -177,12 +191,12 @@
* @param data
* @exception RuntimeException
*/
- protected void getTime (String buffer, int start, int end, int[] data, int[] timeZone) throws RuntimeException{
+ protected void getTime (String buffer, int start, int end, DateTimeData data, int[] timeZone) throws RuntimeException{
int stop = start+2;
//get hours (hh)
- data[h]=parseInt(buffer, start,stop);
+ data.hour=parseInt(buffer, start,stop);
//get minutes (mm)
@@ -191,43 +205,25 @@
}
start = stop;
stop = stop+2;
- data[m]=parseInt(buffer, start,stop);
+ data.minute=parseInt(buffer, start,stop);
//get seconds (ss)
if (buffer.charAt(stop++)!=':') {
throw new RuntimeException("Error in parsing time zone" );
}
- start = stop;
- stop = stop+2;
- data[s]=parseInt(buffer, start,stop);
-
- if (stop == end)
- return;
-
- //get miliseconds (ms)
- start = stop;
- int milisec = buffer.charAt(start) == '.' ? start : -1;
//find UTC sign if any
int sign = findUTCSign(buffer, start, end);
- //parse miliseconds
- if ( milisec != -1 ) {
- // The end of millisecond part is between . and
- // either the end of the UTC sign
- start = sign < 0 ? end : sign;
- data[ms]=parseInt(buffer, milisec+1, start);
- }
+ //get seconds (ms)
+ start = stop;
+ stop = sign < 0 ? end : sign;
+ data.second = parseSecond(buffer, start, stop);
//parse UTC time zone (hh:mm)
- if ( sign>0 ) {
- if (start != sign)
- throw new RuntimeException("Error in parsing time zone" );
+ if (sign > 0) {
getTimeZone(buffer, data, sign, end, timeZone);
}
- else if (start != end) {
- throw new RuntimeException("Error in parsing time zone" );
- }
}
/**
@@ -238,7 +234,7 @@
* @param data
* @exception RuntimeException
*/
- protected int getDate (String buffer, int start, int end, int[] date) throws RuntimeException{
+ protected int getDate (String buffer, int start, int end, DateTimeData date) throws RuntimeException{
start = getYearMonth(buffer, start, end, date);
@@ -246,7 +242,7 @@
throw new RuntimeException("CCYY-MM must be followed by '-' sign");
}
int stop = start + 2;
- date[D]=parseInt(buffer, start, stop);
+ date.day=parseInt(buffer, start, stop);
return stop;
}
@@ -258,7 +254,7 @@
* @param data
* @exception RuntimeException
*/
- protected int getYearMonth (String buffer, int start, int end, int[] date) throws RuntimeException{
+ protected int getYearMonth (String buffer, int start, int end, DateTimeData date) throws RuntimeException{
if ( buffer.charAt(0)=='-' ) {
// REVISIT: date starts with preceding '-' sign
@@ -275,13 +271,13 @@
else if (length > 4 && buffer.charAt(start)=='0'){
throw new RuntimeException("Leading zeros are required if the year value would otherwise have fewer than four digits; otherwise they are forbidden");
}
- date[CY]= parseIntYear(buffer, i);
+ date.year= parseIntYear(buffer, i);
if (buffer.charAt(i)!='-') {
throw new RuntimeException("CCYY must be followed by '-' sign");
}
start = ++i;
i = start +2;
- date[M]=parseInt(buffer, start, i);
+ date.month=parseInt(buffer, start, i);
return i; //fStart points right after the MONTH
}
@@ -293,7 +289,7 @@
* @param date
* @exception RuntimeException
*/
- protected void parseTimeZone (String buffer, int start, int end, int[] date, int[] timeZone) throws RuntimeException{
+ protected void parseTimeZone (String buffer, int start, int end, DateTimeData date, int[] timeZone) throws RuntimeException{
//fStart points right after the date
@@ -315,8 +311,8 @@
* @param sign
* @exception RuntimeException
*/
- protected void getTimeZone (String buffer, int[] data, int sign, int end, int[] timeZone) throws RuntimeException{
- data[utc]=buffer.charAt(sign);
+ protected void getTimeZone (String buffer, DateTimeData data, int sign, int end, int[] timeZone) throws RuntimeException{
+ data.utc=buffer.charAt(sign);
if ( buffer.charAt(sign) == 'Z' ) {
if (end>(++sign)) {
@@ -372,35 +368,35 @@
*
* @param data
*/
- protected void validateDateTime (int[] data, int[] timeZone) {
+ protected void validateDateTime (DateTimeData data, int[] timeZone) {
//REVISIT: should we throw an exception for not valid dates
// or reporting an error message should be sufficient?
- if ( data[CY]==0 ) {
+ if ( data.year==0 ) {
throw new RuntimeException("The year \"0000\" is an illegal year value");
}
- if ( data[M]<1 || data[M]>12 ) {
+ if ( data.month<1 || data.month>12 ) {
throw new RuntimeException("The month must have values 1 to 12");
}
//validate days
- if ( data[D]>maxDayInMonthFor(data[CY], data[M]) || data[D]<1 ) {
+ if ( data.day>maxDayInMonthFor(data.year, data.month) || data.day<1 ) {
throw new RuntimeException("The day must have values 1 to 31");
}
//validate hours
- if ( data[h]>23 || data[h]<0 ) {
- if (data[h] == 24 && data[m] == 0 && data[s] == 0 && data[ms] == 0) {
- data[h] = 0;
- if (++data[D] > maxDayInMonthFor(data[CY], data[M])) {
- data[D] = 1;
- if (++data[M] > 12) {
- data[M] = 1;
- if (++data[CY] == 0)
- data[CY] = 1;
+ if ( data.hour>23 || data.hour<0 ) {
+ if (data.hour == 24 && data.minute == 0 && data.second == 0) {
+ data.hour = 0;
+ if (++data.day > maxDayInMonthFor(data.year, data.month)) {
+ data.day = 1;
+ if (++data.month > 12) {
+ data.month = 1;
+ if (++data.year == 0)
+ data.year = 1;
}
}
}
@@ -410,12 +406,12 @@
}
//validate
- if ( data[m]>59 || data[m]<0 ) {
+ if ( data.minute>59 || data.minute<0 ) {
throw new RuntimeException("Minute must have values 0-59");
}
//validate
- if ( data[s]>60 || data[s]<0 ) {
+ if ( data.second>60 || data.second<0 ) {
throw new RuntimeException("Second must have values 0-60");
}
@@ -524,7 +520,7 @@
* @param date CCYY-MM-DDThh:mm:ss+03
* @return CCYY-MM-DDThh:mm:ssZ
*/
- protected void normalize (int[] date, int[] timeZone) {
+ protected void normalize(DateTimeData date, int[] timeZone) {
// REVISIT: we have common code in addDuration() for durations
// should consider reorganizing it.
@@ -532,49 +528,49 @@
//add minutes (from time zone)
int negate = 1;
- if (date[utc]=='+') {
+ if (date.utc=='+') {
negate = -1;
}
if ( DEBUG ) {
- System.out.println("==>date[m]"+date[m]);
+ System.out.println("==>date.minute"+date.minute);
System.out.println("==>timeZone[mm]" +timeZone[mm]);
}
- int temp = date[m] + negate*timeZone[mm];
+ int temp = date.minute + negate*timeZone[mm];
int carry = fQuotient (temp, 60);
- date[m]= mod(temp, 60, carry);
+ date.minute= mod(temp, 60, carry);
if ( DEBUG ) {
System.out.println("==>carry: " + carry);
}
//add hours
- temp = date[h] + negate*timeZone[hh] + carry;
+ temp = date.hour + negate*timeZone[hh] + carry;
carry = fQuotient(temp, 24);
- date[h]=mod(temp, 24, carry);
+ date.hour=mod(temp, 24, carry);
if ( DEBUG ) {
- System.out.println("==>date[h]"+date[h]);
+ System.out.println("==>date.hour"+date.hour);
System.out.println("==>carry: " + carry);
}
- date[D]=date[D]+carry;
+ date.day=date.day+carry;
while ( true ) {
- temp=maxDayInMonthFor(date[CY], date[M]);
- if (date[D]<1) {
- date[D] = date[D] + maxDayInMonthFor(date[CY], date[M]-1);
+ temp=maxDayInMonthFor(date.year, date.month);
+ if (date.day<1) {
+ date.day = date.day + maxDayInMonthFor(date.year, date.month-1);
carry=-1;
}
- else if ( date[D]>temp ) {
- date[D]=date[D]-temp;
+ else if ( date.day>temp ) {
+ date.day=date.day-temp;
carry=1;
}
else {
break;
}
- temp=date[M]+carry;
- date[M]=modulo(temp, 1, 13);
- date[CY]=date[CY]+fQuotient(temp, 1, 13);
+ temp=date.month+carry;
+ date.month=modulo(temp, 1, 13);
+ date.year=date.year+fQuotient(temp, 1, 13);
}
- date[utc]='Z';
+ date.utc='Z';
}
@@ -583,10 +579,14 @@
*
* @param data date/time object
*/
- protected void resetDateObj (int[] data) {
- for ( int i=0;i<TOTAL_SIZE;i++ ) {
- data[i]=0;
- }
+ protected void resetDateObj(DateTimeData data) {
+ data.year = 0;
+ data.month = 0;
+ data.day = 0;
+ data.hour = 0;
+ data.minute = 0;
+ data.second = 0;
+ data.utc = 0;
}
/**
@@ -658,25 +658,23 @@
}
- protected String dateToString(int[] date) {
+ protected String dateToString(DateTimeData date) {
StringBuffer message = new StringBuffer(25);
- append(message, date[CY], 4);
+ append(message, date.year, 4);
message.append('-');
- append(message, date[M], 2);
+ append(message, date.month, 2);
message.append('-');
- append(message, date[D], 2);
+ append(message, date.day, 2);
message.append('T');
- append(message, date[h], 2);
+ append(message, date.hour, 2);
message.append(':');
- append(message, date[m], 2);
+ append(message, date.minute, 2);
message.append(':');
- append(message, date[s], 2);
- message.append('.');
- message.append(date[ms]);
- append(message, (char)date[utc], 0);
+ append(message, date.second);
+ append(message, (char)date.utc, 0);
return message.toString();
}
-
+
protected void append(StringBuffer message, int value, int nch) {
if (value < 0) {
message.append('-');
@@ -702,38 +700,83 @@
}
}
+ protected void append(StringBuffer message, double value) {
+ if (value < 0) {
+ message.append('-');
+ value = -value;
+ }
+ if (value < 10)
+ message.append('0');
+ message.append(value);
+ }
+
+ protected double parseSecond(String buffer, int start, int end)
+ throws NumberFormatException {
+ int dot = -1;
+ for (int i = start; i < end; i++) {
+ char ch = buffer.charAt(i);
+ if (ch == '.')
+ dot = i;
+ else if (ch > '9' || ch < '0')
+ throw new NumberFormatException("'"+buffer.toString()+"' has wrong format");
+ }
+ if (dot == -1) {
+ if (start+2 != end)
+ throw new NumberFormatException("'"+buffer.toString()+"' has wrong format");
+ }
+ else if (start+2 != dot || dot+1 == end) {
+ throw new NumberFormatException("'"+buffer.toString()+"' has wrong format");
+ }
+ return Double.parseDouble(buffer.substring(start, end));
+ }
+
//
//Private help functions
//
- private void cloneDate (int[] finalValue, int[] tempDate) {
- System.arraycopy(finalValue, 0, tempDate, 0, TOTAL_SIZE);
+ private void cloneDate (DateTimeData finalValue, DateTimeData tempDate) {
+ tempDate.year = finalValue.year;
+ tempDate.month = finalValue.month;
+ tempDate.day = finalValue.day;
+ tempDate.hour = finalValue.hour;
+ tempDate.minute = finalValue.minute;
+ tempDate.second = finalValue.second;
+ tempDate.utc = finalValue.utc;
}
/**
* Represents date time data
*/
static final class DateTimeData {
- // actual data stored in an int array
- final int[] data;
+ int year, month, day, hour, minute, utc;
+ double second;
// a pointer to the type that was used go generate this data
// note that this is not the actual simple type, but one of the
// statically created XXXDV objects, so this won't cause any GC problem.
final AbstractDateTimeDV type;
private String canonical;
- public DateTimeData(int[] data, AbstractDateTimeDV type) {
- this.data = data;
+ public DateTimeData(AbstractDateTimeDV type) {
+ this.type = type;
+ }
+ public DateTimeData(int year, int month, int day, int hour, int minute,
+ double second, int utc, AbstractDateTimeDV type) {
+ this.year = year;
+ this.month = month;
+ this.day = day;
+ this.hour = hour;
+ this.minute = minute;
+ this.second = second;
+ this.utc = utc;
this.type = type;
}
public boolean equals(Object obj) {
if (!(obj instanceof DateTimeData))
return false;
- int[] odata = ((DateTimeData)obj).data;
- return type.compareDates(data, odata, true)==0;
+ return type.compareDates(this, (DateTimeData)obj, true)==0;
}
public synchronized String toString() {
if (canonical == null) {
- canonical = type.dateToString(data);
+ canonical = type.dateToString(this);
}
return canonical;
}
1.11 +13 -13 xml-xerces/java/src/org/apache/xerces/impl/dv/xs/DateDV.java
Index: DateDV.java
===================================================================
RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/dv/xs/DateDV.java,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- DateDV.java 24 Feb 2004 22:44:24 -0000 1.10
+++ DateDV.java 26 Aug 2004 02:14:40 -0000 1.11
@@ -1,12 +1,12 @@
/*
* Copyright 1999-2002,2004 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.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -30,7 +30,7 @@
public Object getActualValue(String content) throws InvalidDatatypeValueException {
try{
- return new DateTimeData(parse(content), this);
+ return parse(content);
} catch(Exception ex){
throw new InvalidDatatypeValueException("cvc-datatype-valid.1.2.1", new Object[]{content, "date"});
}
@@ -45,9 +45,9 @@
* @return normalized dateTime representation
* @exception SchemaDateTimeException Invalid lexical representation
*/
- protected int[] parse(String str) throws SchemaDateTimeException{
+ protected DateTimeData parse(String str) throws SchemaDateTimeException{
+ DateTimeData date = new DateTimeData(this);
int len = str.length();
- int[] date = new int[TOTAL_SIZE];
int[] timeZone = new int[2];
int end = getDate(str, 0, len, date);
@@ -57,20 +57,20 @@
//REVISIT: do we need SchemaDateTimeException?
validateDateTime(date, timeZone);
- if ( date[utc]!=0 && date[utc]!='Z' ) {
+ if (date.utc!=0 && date.utc!='Z') {
normalize(date, timeZone);
}
return date;
}
- protected String dateToString(int[] date) {
+ protected String dateToString(DateTimeData date) {
StringBuffer message = new StringBuffer(25);
- append(message, date[CY], 4);
+ append(message, date.year, 4);
message.append('-');
- append(message, date[M], 2);
+ append(message, date.month, 2);
message.append('-');
- append(message, date[D], 2);
- append(message, (char)date[utc], 0);
+ append(message, date.day, 2);
+ append(message, (char)date.utc, 0);
return message.toString();
}
1.9 +9 -9 xml-xerces/java/src/org/apache/xerces/impl/dv/xs/DateTimeDV.java
Index: DateTimeDV.java
===================================================================
RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/dv/xs/DateTimeDV.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- DateTimeDV.java 28 Jun 2004 17:09:49 -0000 1.8
+++ DateTimeDV.java 26 Aug 2004 02:14:40 -0000 1.9
@@ -1,12 +1,12 @@
/*
* Copyright 1999-2002,2004 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.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -31,7 +31,7 @@
public Object getActualValue(String content, ValidationContext context) throws InvalidDatatypeValueException {
try{
- return new DateTimeData(parse(content), this);
+ return parse(content);
} catch(Exception ex){
throw new InvalidDatatypeValueException("cvc-datatype-valid.1.2.1", new Object[]{content, "dateTime"});
}
@@ -46,9 +46,9 @@
* @return normalized dateTime representation
* @exception SchemaDateTimeException Invalid lexical representation
*/
- protected int[] parse(String str) throws SchemaDateTimeException {
+ protected DateTimeData parse(String str) throws SchemaDateTimeException {
+ DateTimeData date = new DateTimeData(this);
int len = str.length();
- int[] date = new int[TOTAL_SIZE];
int[] timeZone = new int[2];
int end = indexOf (str, 0, len, 'T');
@@ -63,13 +63,13 @@
+ " is an invalid dateTime dataype value. "
+ "Invalid character(s) seprating date and time values.");
}
-
+
//validate and normalize
//REVISIT: do we need SchemaDateTimeException?
validateDateTime(date, timeZone);
- if ( date[utc]!=0 && date[utc]!='Z') {
+ if (date.utc!=0 && date.utc!='Z') {
normalize(date, timeZone);
}
return date;
1.9 +14 -14 xml-xerces/java/src/org/apache/xerces/impl/dv/xs/DayDV.java
Index: DayDV.java
===================================================================
RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/dv/xs/DayDV.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- DayDV.java 24 Feb 2004 22:44:24 -0000 1.8
+++ DayDV.java 26 Aug 2004 02:14:40 -0000 1.9
@@ -1,12 +1,12 @@
/*
* Copyright 1999-2002,2004 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.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -33,7 +33,7 @@
public Object getActualValue(String content, ValidationContext context) throws InvalidDatatypeValueException {
try{
- return new DateTimeData(parse(content), this);
+ return parse(content);
} catch(Exception ex){
throw new InvalidDatatypeValueException("cvc-datatype-valid.1.2.1", new Object[]{content, "gDay"});
}
@@ -49,9 +49,9 @@
* @return normalized date representation
* @exception SchemaDateTimeException Invalid lexical representation
*/
- protected int[] parse(String str) throws SchemaDateTimeException {
+ protected DateTimeData parse(String str) throws SchemaDateTimeException {
+ DateTimeData date = new DateTimeData(this);
int len = str.length();
- int[] date=new int[TOTAL_SIZE];
int[] timeZone = new int[2];
if (str.charAt(0)!='-' || str.charAt(1)!='-' || str.charAt(2)!='-') {
@@ -59,10 +59,10 @@
}
//initialize values
- date[CY]=YEAR;
- date[M]=MONTH;
+ date.year=YEAR;
+ date.month=MONTH;
- date[D]=parseInt(str, 3,5);
+ date.day=parseInt(str, 3,5);
if ( DAY_SIZE<len ) {
int sign = findUTCSign(str, DAY_SIZE, len);
@@ -77,7 +77,7 @@
//validate and normalize
validateDateTime(date, timeZone);
- if ( date[utc]!=0 && date[utc]!='Z' ) {
+ if ( date.utc!=0 && date.utc!='Z' ) {
normalize(date, timeZone);
}
return date;
@@ -89,13 +89,13 @@
* @param date gDay object
* @return lexical representation of gDay: ---DD with an optional time zone sign
*/
- protected String dateToString(int[] date) {
+ protected String dateToString(DateTimeData date) {
StringBuffer message = new StringBuffer(6);
message.append('-');
message.append('-');
message.append('-');
- append(message, date[D], 2);
- append(message, (char)date[utc], 0);
+ append(message, date.day, 2);
+ append(message, (char)date.utc, 0);
return message.toString();
}
1.10 +76 -67 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.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- DurationDV.java 24 Feb 2004 22:44:24 -0000 1.9
+++ DurationDV.java 26 Aug 2004 02:14:40 -0000 1.10
@@ -1,12 +1,12 @@
/*
* Copyright 1999-2002,2004 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.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -34,15 +34,15 @@
// see 3.2.6 duration W3C schema datatype specs
//
// the dates are in format: {CCYY,MM,DD, H, S, M, MS, timezone}
- private final static int[][] DATETIMES= {
- {1696, 9, 1, 0, 0, 0, 0, 'Z'},
- {1697, 2, 1, 0, 0, 0, 0, 'Z'},
- {1903, 3, 1, 0, 0, 0, 0, 'Z'},
- {1903, 7, 1, 0, 0, 0, 0, 'Z'}};
+ private final static DateTimeData[] DATETIMES= {
+ new DateTimeData(1696, 9, 1, 0, 0, 0, 'Z', null),
+ new DateTimeData(1697, 2, 1, 0, 0, 0, 'Z', null),
+ new DateTimeData(1903, 3, 1, 0, 0, 0, 'Z', null),
+ new DateTimeData(1903, 7, 1, 0, 0, 0, 'Z', null)};
public Object getActualValue(String content, ValidationContext context) throws InvalidDatatypeValueException{
try{
- return new DateTimeData(parse(content), this);
+ return parse(content);
} catch (Exception ex) {
throw new InvalidDatatypeValueException("cvc-datatype-valid.1.2.1", new Object[]{content, "duration"});
}
@@ -56,9 +56,9 @@
* @return normalized date representation
* @exception SchemaDateTimeException Invalid lexical representation
*/
- protected int[] parse(String str) throws SchemaDateTimeException{
+ protected DateTimeData parse(String str) throws SchemaDateTimeException{
int len = str.length();
- int[] date=new int[TOTAL_SIZE];
+ DateTimeData date= new DateTimeData(this);
int start = 0;
char c=str.charAt(start++);
@@ -66,7 +66,7 @@
throw new SchemaDateTimeException();
}
else {
- date[utc]=(c=='-')?'-':0;
+ date.utc=(c=='-')?'-':0;
if ( c=='-' && str.charAt(start++)!='P' ) {
throw new SchemaDateTimeException();
}
@@ -74,7 +74,7 @@
int negate = 1;
//negative duration
- if ( date[utc]=='-' ) {
+ if ( date.utc=='-' ) {
negate = -1;
}
@@ -89,7 +89,7 @@
int end = indexOf (str, start, endDate, 'Y');
if ( end!=-1 ) {
//scan year
- date[CY]=negate * parseInt(str,start,end);
+ date.year=negate * parseInt(str,start,end);
start = end+1;
designator = true;
}
@@ -97,7 +97,7 @@
end = indexOf (str, start, endDate, 'M');
if ( end!=-1 ) {
//scan month
- date[M]=negate * parseInt(str,start,end);
+ date.month=negate * parseInt(str,start,end);
start = end+1;
designator = true;
}
@@ -105,7 +105,7 @@
end = indexOf (str, start, endDate, 'D');
if ( end!=-1 ) {
//scan day
- date[D]=negate * parseInt(str,start,end);
+ date.day=negate * parseInt(str,start,end);
start = end+1;
designator = true;
}
@@ -122,7 +122,7 @@
end = indexOf (str, ++start, len, 'H');
if ( end!=-1 ) {
//scan hours
- date[h]=negate * parseInt(str,start,end);
+ date.hour=negate * parseInt(str,start,end);
start=end+1;
designator = true;
}
@@ -130,7 +130,7 @@
end = indexOf (str, start, len, 'M');
if ( end!=-1 ) {
//scan min
- date[m]=negate * parseInt(str,start,end);
+ date.minute=negate * parseInt(str,start,end);
start=end+1;
designator = true;
}
@@ -138,14 +138,7 @@
end = indexOf (str, start, len, 'S');
if ( end!=-1 ) {
//scan seconds
- int mlsec = indexOf (str, start, end, '.');
- if ( mlsec >0 ) {
- date[s] = negate * parseInt (str, start, mlsec);
- date[ms] = negate * parseInt (str, mlsec+1, end);
- }
- else {
- date[s]=negate * parseInt(str, start,end);
- }
+ date.second = negate * parseSecond(str, start, end);
start=end+1;
designator = true;
}
@@ -170,14 +163,14 @@
* @param date2 Unnormalized duration
* @param strict (min/max)Exclusive strict == true ( LESS_THAN ) or ( GREATER_THAN )
* (min/max)Inclusive strict == false (LESS_EQUAL) or (GREATER_EQUAL)
- * @return INDETERMINATE if the order relationship between date1 and date2 is indeterminate.
- * EQUAL if the order relation between date1 and date2 is EQUAL.
+ * @return INDETERMINATE if the order relationship between date1 and date2 is indeterminate.
+ * EQUAL if the order relation between date1 and date2 is EQUAL.
* If the strict parameter is true, return LESS_THAN if date1 is less than date2 and
- * return GREATER_THAN if date1 is greater than date2.
+ * return GREATER_THAN if date1 is greater than date2.
* If the strict parameter is false, return LESS_THAN if date1 is less than OR equal to date2 and
- * return GREATER_THAN if date1 is greater than OR equal to date2
+ * return GREATER_THAN if date1 is greater than OR equal to date2
*/
- protected short compareDates(int[] date1, int[] date2, boolean strict) {
+ protected short compareDates(DateTimeData date1, DateTimeData date2, boolean strict) {
//REVISIT: this is unoptimazed vs of comparing 2 durations
// Algorithm is described in 3.2.6.2 W3C Schema Datatype specs
@@ -192,11 +185,13 @@
return 0;
}
- int[][] result = new int[2][TOTAL_SIZE];
+ DateTimeData[] result = new DateTimeData[2];
+ result[0] = new DateTimeData(this);
+ result[1] = new DateTimeData(this);
//long comparison algorithm is required
- int[] tempA = addDuration (date1, DATETIMES[0], result[0]);
- int[] tempB = addDuration (date2, DATETIMES[0], result[1]);
+ DateTimeData tempA = addDuration (date1, DATETIMES[0], result[0]);
+ DateTimeData tempB = addDuration (date2, DATETIMES[0], result[1]);
resultA = compareOrder(tempA, tempB);
if ( resultA == INDETERMINATE ) {
return INDETERMINATE;
@@ -245,7 +240,7 @@
return resultA;
}
- private int[] addDuration(int[] date, int[] addto, int[] duration) {
+ private DateTimeData addDuration(DateTimeData date, DateTimeData addto, DateTimeData duration) {
//REVISIT: some code could be shared between normalize() and this method,
// however is it worth moving it? The structures are different...
@@ -253,76 +248,90 @@
resetDateObj(duration);
//add months (may be modified additionaly below)
- int temp = addto[M] + date[M];
- duration[M] = modulo (temp, 1, 13);
+ int temp = addto.month + date.month;
+ duration.month = modulo (temp, 1, 13);
int carry = fQuotient (temp, 1, 13);
//add years (may be modified additionaly below)
- duration[CY]=addto[CY] + date[CY] + carry;
-
+ duration.year=addto.year + date.year + carry;
+
//add seconds
- temp = addto[s] + date[s];
- carry = fQuotient (temp, 60);
- duration[s] = mod(temp, 60, carry);
+ double dtemp = addto.second + date.second;
+ carry = (int)Math.floor(dtemp/60);
+ duration.second = dtemp - carry*60;
//add minutes
- temp = addto[m] +date[m] + carry;
+ temp = addto.minute +date.minute + carry;
carry = fQuotient (temp, 60);
- duration[m]= mod(temp, 60, carry);
+ duration.minute= mod(temp, 60, carry);
//add hours
- temp = addto[h] + date[h] + carry;
+ temp = addto.hour + date.hour + carry;
carry = fQuotient(temp, 24);
- duration[h] = mod(temp, 24, carry);
+ duration.hour = mod(temp, 24, carry);
- duration[D]=addto[D] + date[D] + carry;
+ duration.day=addto.day + date.day + carry;
while ( true ) {
- temp=maxDayInMonthFor(duration[CY], duration[M]);
- if ( duration[D] < 1 ) { //original duration was negative
- duration[D] = duration[D] + maxDayInMonthFor(duration[CY], duration[M]-1);
+ temp=maxDayInMonthFor(duration.year, duration.month);
+ if ( duration.day < 1 ) { //original duration was negative
+ duration.day = duration.day + maxDayInMonthFor(duration.year, duration.month-1);
carry=-1;
}
- else if ( duration[D] > temp ) {
- duration[D] = duration[D] - temp;
+ else if ( duration.day > temp ) {
+ duration.day = duration.day - temp;
carry=1;
}
else {
break;
}
- temp = duration[M]+carry;
- duration[M] = modulo(temp, 1, 13);
- duration[CY] = duration[CY]+fQuotient(temp, 1, 13);
+ temp = duration.month+carry;
+ duration.month = modulo(temp, 1, 13);
+ duration.year = duration.year+fQuotient(temp, 1, 13);
}
- duration[utc]='Z';
+ duration.utc='Z';
return duration;
}
- protected String dateToString(int[] date) {
+ protected double parseSecond(String buffer, int start, int end)
+ throws NumberFormatException {
+ int dot = -1;
+ for (int i = start; i < end; i++) {
+ char ch = buffer.charAt(i);
+ if (ch == '.')
+ dot = i;
+ else if (ch > '9' || ch < '0')
+ throw new NumberFormatException("'"+buffer.toString()+"' has wrong format");
+ }
+ if (dot+1 == end) {
+ throw new NumberFormatException("'"+buffer.toString()+"' has wrong format");
+ }
+ return Double.parseDouble(buffer.substring(start, end));
+ }
+
+ protected String dateToString(DateTimeData date) {
StringBuffer message = new StringBuffer(30);
int negate = 1;
- if ( date[CY]<0 ) {
+ if ( date.year<0 ) {
message.append('-');
negate=-1;
}
message.append('P');
- message.append(negate * date[CY]);
+ message.append(negate * date.year);
message.append('Y');
- message.append(negate * date[M]);
+ message.append(negate * date.month);
message.append('M');
- message.append(negate * date[D]);
+ message.append(negate * date.day);
message.append('D');
message.append('T');
- message.append(negate * date[h]);
+ message.append(negate * date.hour);
message.append('H');
- message.append(negate * date[m]);
+ message.append(negate * date.minute);
message.append('M');
- message.append(negate * date[s]);
- message.append('.');
- message.append(negate * date[ms]);
+ message.append(negate * date.second);
message.append('S');
return message.toString();
1.9 +15 -15 xml-xerces/java/src/org/apache/xerces/impl/dv/xs/MonthDayDV.java
Index: MonthDayDV.java
===================================================================
RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/dv/xs/MonthDayDV.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- MonthDayDV.java 24 Feb 2004 22:44:24 -0000 1.8
+++ MonthDayDV.java 26 Aug 2004 02:14:40 -0000 1.9
@@ -1,12 +1,12 @@
/*
* Copyright 1999-2002,2004 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.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -41,7 +41,7 @@
*/
public Object getActualValue(String content, ValidationContext context) throws InvalidDatatypeValueException {
try{
- return new DateTimeData(parse(content), this);
+ return parse(content);
} catch(Exception ex){
throw new InvalidDatatypeValueException("cvc-datatype-valid.1.2.1", new Object[]{content, "gMonthDay"});
}
@@ -56,25 +56,25 @@
* @return normalized date representation
* @exception SchemaDateTimeException Invalid lexical representation
*/
- protected int[] parse(String str) throws SchemaDateTimeException{
+ protected DateTimeData parse(String str) throws SchemaDateTimeException{
+ DateTimeData date = new DateTimeData(this);
int len = str.length();
- int[] date=new int[TOTAL_SIZE];
int[] timeZone = new int[2];
//initialize
- date[CY]=YEAR;
+ date.year=YEAR;
if (str.charAt(0)!='-' || str.charAt(1)!='-') {
throw new SchemaDateTimeException("Invalid format for gMonthDay: "+str);
}
- date[M]=parseInt(str, 2, 4);
+ date.month=parseInt(str, 2, 4);
int start=4;
if (str.charAt(start++)!='-') {
throw new SchemaDateTimeException("Invalid format for gMonthDay: " + str);
}
- date[D]=parseInt(str, start, start+2);
+ date.day=parseInt(str, start, start+2);
if ( MONTHDAY_SIZE<len ) {
int sign = findUTCSign(str, MONTHDAY_SIZE, len);
@@ -89,7 +89,7 @@
validateDateTime(date, timeZone);
- if ( date[utc]!=0 && date[utc]!='Z' ) {
+ if ( date.utc!=0 && date.utc!='Z' ) {
normalize(date, timeZone);
}
return date;
@@ -101,14 +101,14 @@
* @param date gmonthDay object
* @return lexical representation of month: --MM-DD with an optional time zone sign
*/
- protected String dateToString(int[] date) {
+ protected String dateToString(DateTimeData date) {
StringBuffer message = new StringBuffer(8);
message.append('-');
message.append('-');
- append(message, date[M], 2);
+ append(message, date.month, 2);
message.append('-');
- append(message, date[D], 2);
- append(message, (char)date[utc], 0);
+ append(message, date.day, 2);
+ append(message, (char)date.utc, 0);
return message.toString();
}
1.11 +21 -21 xml-xerces/java/src/org/apache/xerces/impl/dv/xs/MonthDV.java
Index: MonthDV.java
===================================================================
RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/dv/xs/MonthDV.java,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- MonthDV.java 24 Feb 2004 22:44:24 -0000 1.10
+++ MonthDV.java 26 Aug 2004 02:14:40 -0000 1.11
@@ -1,12 +1,12 @@
/*
* Copyright 1999-2002,2004 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.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -38,7 +38,7 @@
*/
public Object getActualValue(String content, ValidationContext context) throws InvalidDatatypeValueException{
try{
- return new DateTimeData(parse(content), this);
+ return parse(content);
} catch(Exception ex){
throw new InvalidDatatypeValueException("cvc-datatype-valid.1.2.1", new Object[]{content, "gMonth"});
}
@@ -53,19 +53,19 @@
* @return normalized date representation
* @exception SchemaDateTimeException Invalid lexical representation
*/
- protected int[] parse(String str) throws SchemaDateTimeException{
+ protected DateTimeData parse(String str) throws SchemaDateTimeException{
+ DateTimeData date = new DateTimeData(this);
int len = str.length();
- int[] date=new int[TOTAL_SIZE];
int[] timeZone = new int[2];
//set constants
- date[CY]=YEAR;
- date[D]=DAY;
+ date.year=YEAR;
+ date.day=DAY;
if (str.charAt(0)!='-' || str.charAt(1)!='-') {
throw new SchemaDateTimeException("Invalid format for gMonth: "+str);
}
int stop = 4;
- date[M]=parseInt(str,2,stop);
+ date.month=parseInt(str,2,stop);
// REVISIT: allow both --MM and --MM-- now.
// need to remove the following 4 lines to disallow --MM--
@@ -86,7 +86,7 @@
//validate and normalize
validateDateTime(date, timeZone);
- if ( date[utc]!=0 && date[utc]!='Z' ) {
+ if ( date.utc!=0 && date.utc!='Z' ) {
normalize(date, timeZone);
}
return date;
@@ -104,19 +104,19 @@
* @param date2
* @return less, greater, equal, indeterminate
*/
- protected short compareDates(int[] date1, int[] date2) {
+ protected short compareDates(DateTimeData date1, DateTimeData date2) {
- if ( date1[utc]==date2[utc] ) {
- return (short)((date1[M]>=date2[M])?(date1[M]>date2[M])?1:0:-1);
+ if ( date1.utc==date2.utc ) {
+ return (short)((date1.month>=date2.month)?(date1.month>date2.month)?1:0:-1);
}
- if ( date1[utc]=='Z' || date2[utc]=='Z' ) {
+ if ( date1.utc=='Z' || date2.utc=='Z' ) {
- if ( date1[M]==date2[M] ) {
+ if ( date1.month==date2.month ) {
//--05--Z and --05--
return INDETERMINATE;
}
- if ( (date1[M]+1 == date2[M] || date1[M]-1 == date2[M]) ) {
+ if ( (date1.month+1 == date2.month || date1.month-1 == date2.month) ) {
//--05--Z and (--04-- or --05--)
//REVISIT: should this case be less than or equal?
// maxExclusive should fail but what about maxInclusive
@@ -125,7 +125,7 @@
}
}
- if ( date1[M]<date2[M] ) {
+ if ( date1.month<date2.month ) {
return -1;
}
else {
@@ -140,12 +140,12 @@
* @param date month object
* @return lexical representation of month: --MM with an optional time zone sign
*/
- protected String dateToString(int[] date) {
+ protected String dateToString(DateTimeData date) {
StringBuffer message = new StringBuffer(5);
message.append('-');
message.append('-');
- append(message, date[M], 2);
- append(message, (char)date[utc], 0);
+ append(message, date.month, 2);
+ append(message, (char)date.utc, 0);
return message.toString();
}
1.9 +17 -20 xml-xerces/java/src/org/apache/xerces/impl/dv/xs/TimeDV.java
Index: TimeDV.java
===================================================================
RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/dv/xs/TimeDV.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- TimeDV.java 24 Feb 2004 22:44:24 -0000 1.8
+++ TimeDV.java 26 Aug 2004 02:14:40 -0000 1.9
@@ -1,12 +1,12 @@
/*
* Copyright 1999-2002,2004 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.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -37,7 +37,7 @@
*/
public Object getActualValue(String content, ValidationContext context) throws InvalidDatatypeValueException{
try{
- return new DateTimeData(parse(content), this);
+ return parse(content);
} catch(Exception ex){
throw new InvalidDatatypeValueException("cvc-datatype-valid.1.2.1", new Object[]{content, "time"});
}
@@ -53,23 +53,23 @@
* @return normalized time representation
* @exception SchemaDateTimeException Invalid lexical representation
*/
- protected int[] parse(String str) throws SchemaDateTimeException{
+ protected DateTimeData parse(String str) throws SchemaDateTimeException{
+ DateTimeData date = new DateTimeData(this);
int len = str.length();
- int[] date = new int[TOTAL_SIZE];
int[] timeZone = new int[2];
// time
// initialize to default values
- date[CY]=YEAR;
- date[M]=MONTH;
- date[D]=DAY;
+ date.year=YEAR;
+ date.month=MONTH;
+ date.day=DAY;
getTime(str, 0, len, date, timeZone);
//validate and normalize
validateDateTime(date, timeZone);
- if ( date[utc]!=0 ) {
+ if ( date.utc!=0 ) {
normalize(date, timeZone);
}
return date;
@@ -81,19 +81,16 @@
* @param date time object
* @return lexical representation of time: hh:mm:ss.sss with an optional time zone sign
*/
- protected String dateToString(int[] date) {
+ protected String dateToString(DateTimeData date) {
StringBuffer message = new StringBuffer(16);
- append(message, date[h], 2);
+ append(message, date.hour, 2);
message.append(':');
- append(message, date[m], 2);
+ append(message, date.month, 2);
message.append(':');
- append(message, date[s], 2);
- message.append('.');
- message.append(date[ms]);
- append(message, (char)date[utc], 0);
+ append(message, date.second);
+
+ append(message, (char)date.utc, 0);
return message.toString();
}
}
-
-
1.9 +15 -15 xml-xerces/java/src/org/apache/xerces/impl/dv/xs/YearDV.java
Index: YearDV.java
===================================================================
RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/dv/xs/YearDV.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- YearDV.java 24 Feb 2004 22:44:24 -0000 1.8
+++ YearDV.java 26 Aug 2004 02:14:41 -0000 1.9
@@ -1,12 +1,12 @@
/*
* Copyright 1999-2002,2004 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.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -38,7 +38,7 @@
*/
public Object getActualValue(String content, ValidationContext context) throws InvalidDatatypeValueException{
try{
- return new DateTimeData(parse(content), this);
+ return parse(content);
} catch(Exception ex){
throw new InvalidDatatypeValueException("cvc-datatype-valid.1.2.1", new Object[]{content, "gYear"});
}
@@ -53,9 +53,9 @@
* @return normalized date representation
* @exception SchemaDateTimeException Invalid lexical representation
*/
- protected int[] parse(String str) throws SchemaDateTimeException{
+ protected DateTimeData parse(String str) throws SchemaDateTimeException{
+ DateTimeData date = new DateTimeData(this);
int len = str.length();
- int[] date = new int[TOTAL_SIZE];
int[] timeZone = new int[2];
// check for preceding '-' sign
@@ -65,21 +65,21 @@
}
int sign = findUTCSign(str, start, len);
if (sign == -1) {
- date[CY]=parseIntYear(str, len);
+ date.year=parseIntYear(str, len);
}
else {
- date[CY]=parseIntYear(str, sign);
+ date.year=parseIntYear(str, sign);
getTimeZone (str, date, sign, len, timeZone);
}
//initialize values
- date[M]=MONTH;
- date[D]=1;
+ date.month=MONTH;
+ date.day=1;
//validate and normalize
validateDateTime(date, timeZone);
- if ( date[utc]!=0 && date[utc]!='Z' ) {
+ if ( date.utc!=0 && date.utc!='Z' ) {
normalize(date, timeZone);
}
return date;
@@ -91,10 +91,10 @@
* @param date year object
* @return lexical representation of month: CCYY with optional time zone sign
*/
- protected String dateToString(int[] date) {
+ protected String dateToString(DateTimeData date) {
StringBuffer message = new StringBuffer(5);
- append(message, date[CY], 4);
- append(message, (char)date[utc], 0);
+ append(message, date.year, 4);
+ append(message, (char)date.utc, 0);
return message.toString();
}
1.9 +13 -13 xml-xerces/java/src/org/apache/xerces/impl/dv/xs/YearMonthDV.java
Index: YearMonthDV.java
===================================================================
RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/dv/xs/YearMonthDV.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- YearMonthDV.java 24 Feb 2004 22:44:24 -0000 1.8
+++ YearMonthDV.java 26 Aug 2004 02:14:41 -0000 1.9
@@ -1,12 +1,12 @@
/*
* Copyright 1999-2002,2004 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.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -37,7 +37,7 @@
*/
public Object getActualValue(String content, ValidationContext context) throws InvalidDatatypeValueException{
try{
- return new DateTimeData(parse(content), this);
+ return parse(content);
} catch(Exception ex){
throw new InvalidDatatypeValueException("cvc-datatype-valid.1.2.1", new Object[]{content, "gYearMonth"});
}
@@ -52,32 +52,32 @@
* @return normalized date representation
* @exception SchemaDateTimeException Invalid lexical representation
*/
- protected int[] parse(String str) throws SchemaDateTimeException{
+ protected DateTimeData parse(String str) throws SchemaDateTimeException{
+ DateTimeData date = new DateTimeData(this);
int len = str.length();
- int[] date = new int[TOTAL_SIZE];
int[] timeZone = new int[2];
// get date
int end = getYearMonth(str, 0, len, date);
- date[D] = DAY;
+ date.day = DAY;
parseTimeZone (str, end, len, date, timeZone);
//validate and normalize
validateDateTime(date, timeZone);
- if ( date[utc]!=0 && date[utc]!='Z' ) {
+ if ( date.utc!=0 && date.utc!='Z' ) {
normalize(date, timeZone);
}
return date;
}
- protected String dateToString(int[] date) {
+ protected String dateToString(DateTimeData date) {
StringBuffer message = new StringBuffer(25);
- append(message, date[CY], 4);
+ append(message, date.year, 4);
message.append('-');
- append(message, date[M], 2);
- append(message, (char)date[utc], 0);
+ append(message, date.month, 2);
+ append(message, (char)date.utc, 0);
return message.toString();
}
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-cvs-help@xml.apache.org