ankitp 2005/05/06 11:41:23
Modified: java/src/org/apache/xerces/jaxp/datatype DurationImpl.java
XMLGregorianCalendarImpl.java
Log:
bug fixes
- reset on XMLGregorianCalendar
- compare duration
- gMonth lexical value fix
Revision Changes Path
1.3 +75 -10
xml-xerces/java/src/org/apache/xerces/jaxp/datatype/DurationImpl.java
Index: DurationImpl.java
===================================================================
RCS file:
/home/cvs/xml-xerces/java/src/org/apache/xerces/jaxp/datatype/DurationImpl.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- DurationImpl.java 6 May 2005 16:05:02 -0000 1.2
+++ DurationImpl.java 6 May 2005 18:41:23 -0000 1.3
@@ -865,20 +865,85 @@
rhsCalendar.add(GregorianCalendar.HOUR_OF_DAY, rhs.getHours() *
rhs.getSign());
rhsCalendar.add(GregorianCalendar.MINUTE, rhs.getMinutes() *
rhs.getSign());
rhsCalendar.add(GregorianCalendar.SECOND, rhs.getSeconds() *
rhs.getSign());
-
- if (lhsCalendar.before(rhsCalendar)) {
- return DatatypeConstants.LESSER;
- }
-
- if (lhsCalendar.after(rhsCalendar)) {
- return DatatypeConstants.GREATER;
- }
+
if (lhsCalendar.equals(rhsCalendar)) {
return DatatypeConstants.EQUAL;
}
- return DatatypeConstants.INDETERMINATE;
+ return compareDates(this, rhs);
+ }
+
+ /**
+ * Compares 2 given durations. (refer to W3C Schema Datatypes "3.2.6
duration")
+ *
+ * @param duration1 Unnormalized duration
+ * @param duration2 Unnormalized duration
+ * @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.
+ * 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
+ */
+ private int compareDates(Duration duration1, Duration duration2) {
+
+ int resultA = DatatypeConstants.INDETERMINATE;
+ int resultB = DatatypeConstants.INDETERMINATE;
+
+ XMLGregorianCalendar tempA =
(XMLGregorianCalendar)TEST_POINTS[0].clone();
+ XMLGregorianCalendar tempB =
(XMLGregorianCalendar)TEST_POINTS[0].clone();
+
+ //long comparison algorithm is required
+ tempA.add(duration1);
+ tempB.add(duration2);
+ resultA = tempA.compare(tempB);
+ if ( resultA == DatatypeConstants.INDETERMINATE ) {
+ return DatatypeConstants.INDETERMINATE;
+ }
+
+ tempA = (XMLGregorianCalendar)TEST_POINTS[1].clone();
+ tempB = (XMLGregorianCalendar)TEST_POINTS[1].clone();
+
+ tempA.add(duration1);
+ tempB.add(duration2);
+ resultB = tempA.compare(tempB);
+ resultA = compareResults(resultA, resultB);
+ if (resultA == DatatypeConstants.INDETERMINATE) {
+ return DatatypeConstants.INDETERMINATE;
+ }
+
+ tempA = (XMLGregorianCalendar)TEST_POINTS[2].clone();
+ tempB = (XMLGregorianCalendar)TEST_POINTS[2].clone();
+
+ tempA.add(duration1);
+ tempB.add(duration2);
+ resultB = tempA.compare(tempB);
+ resultA = compareResults(resultA, resultB);
+ if (resultA == DatatypeConstants.INDETERMINATE) {
+ return DatatypeConstants.INDETERMINATE;
+ }
+
+ tempA = (XMLGregorianCalendar)TEST_POINTS[3].clone();
+ tempB = (XMLGregorianCalendar)TEST_POINTS[3].clone();
+
+ tempA.add(duration1);
+ tempB.add(duration2);
+ resultB = tempA.compare(tempB);
+ resultA = compareResults(resultA, resultB);
+
+ return resultA;
+ }
+
+ private int compareResults(int resultA, int resultB){
+
+ if ( resultB == DatatypeConstants.INDETERMINATE ) {
+ return DatatypeConstants.INDETERMINATE;
+ }
+ else if ( resultA!=resultB) {
+ return DatatypeConstants.INDETERMINATE;
+ }
+ return resultA;
}
/**
1.3 +35 -15
xml-xerces/java/src/org/apache/xerces/jaxp/datatype/XMLGregorianCalendarImpl.java
Index: XMLGregorianCalendarImpl.java
===================================================================
RCS file:
/home/cvs/xml-xerces/java/src/org/apache/xerces/jaxp/datatype/XMLGregorianCalendarImpl.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- XMLGregorianCalendarImpl.java 6 May 2005 16:05:02 -0000 1.2
+++ XMLGregorianCalendarImpl.java 6 May 2005 18:41:23 -0000 1.3
@@ -408,11 +408,26 @@
// GDAY
// Fix 4971612: invalid SCCS macro substitution in data string
format = "---%D" + "%z";
- } else if (lexRepLength >= 6 &&
- lexRep.charAt(5) == '-' && lexRep.charAt(4) == '-') {
+ } else if (lexRepLength == 4 || (lexRepLength >= 6 &&
(lexRep.charAt(4) == '+' || (lexRep.charAt(4) == '-' && (lexRep.charAt(5) ==
'-' || lexRepLength == 10))))) {
// GMonth
// Fix 4971612: invalid SCCS macro substitution in data string
format = "--%M--%z";
+ Parser p = new Parser(format, lexRep);
+ try {
+ p.parse();
+ // check for validity
+ if (!isValid()) {
+ throw new IllegalArgumentException(
+
DatatypeMessageFormatter.formatMessage(null,"InvalidXGCRepresentation", new
Object[]{lexicalRepresentation})
+ //"\"" + lexicalRepresentation + "\" is not a valid
representation of an XML Gregorian Calendar value."
+ );
+ }
+ save();
+ return;
+ }
+ catch(IllegalArgumentException e) {
+ format = "--%M%z";
+ }
} else {
// GMonthDay or invalid lexicalRepresentation
format = "--%M-%D" + "%z";
@@ -461,6 +476,7 @@
//"\"" + lexicalRepresentation + "\" is not a
valid representation of an XML Gregorian Calendar value."
);
}
+ save();
}
/**
@@ -555,6 +571,8 @@
*/
}
+
+ save();
}
@@ -616,6 +634,7 @@
*/
}
+ save();
}
/**
@@ -696,6 +715,7 @@
// Calendar ZONE_OFFSET and DST_OFFSET fields are in milliseconds.
int offsetInMinutes = (cal.get(Calendar.ZONE_OFFSET) +
cal.get(Calendar.DST_OFFSET)) / (60 * 1000);
this.setTimezone(offsetInMinutes);
+ save();
}
// Factories
@@ -1427,11 +1447,11 @@
*/
public int compare(XMLGregorianCalendar rhs) {
- XMLGregorianCalendar lhs = this;
+ //MLGregorianCalendar lhs = this;
int result = DatatypeConstants.INDETERMINATE;
- XMLGregorianCalendarImpl P = (XMLGregorianCalendarImpl) lhs;
- XMLGregorianCalendarImpl Q = (XMLGregorianCalendarImpl) rhs;
+ XMLGregorianCalendar P = this;
+ XMLGregorianCalendar Q = rhs;
if (P.getTimezone() == Q.getTimezone()) {
// Optimization:
@@ -1455,14 +1475,14 @@
}
// C. step 1
- XMLGregorianCalendar MinQ =
Q.normalizeToTimezone(DatatypeConstants.MIN_TIMEZONE_OFFSET);
+ XMLGregorianCalendar MinQ = normalizeToTimezone(Q,
DatatypeConstants.MIN_TIMEZONE_OFFSET);
result = internalCompare(P, MinQ);
if (result == DatatypeConstants.LESSER) {
return result;
}
// C. step 2
- XMLGregorianCalendar MaxQ =
Q.normalizeToTimezone(DatatypeConstants.MAX_TIMEZONE_OFFSET);
+ XMLGregorianCalendar MaxQ = normalizeToTimezone(Q,
DatatypeConstants.MAX_TIMEZONE_OFFSET);
result = internalCompare(P, MaxQ);
if (result == DatatypeConstants.GREATER) {
return result;
@@ -1473,18 +1493,18 @@
} else { // Q.getTimezone() != DatatypeConstants.FIELD_UNDEFINED
// P has no timezone and Q does.
if (Q.getTimezone() != 0 ) {
- Q = (XMLGregorianCalendarImpl)
Q.normalizeToTimezone(Q.getTimezone());
+ Q = (XMLGregorianCalendarImpl) normalizeToTimezone(Q,
Q.getTimezone());
}
// D. step 1
- XMLGregorianCalendar MaxP =
P.normalizeToTimezone(DatatypeConstants.MAX_TIMEZONE_OFFSET);
+ XMLGregorianCalendar MaxP = normalizeToTimezone(P,
DatatypeConstants.MAX_TIMEZONE_OFFSET);
result = internalCompare(MaxP, Q);
if (result == DatatypeConstants.LESSER) {
return result;
}
// D. step 2
- XMLGregorianCalendar MinP =
P.normalizeToTimezone(DatatypeConstants.MIN_TIMEZONE_OFFSET);
+ XMLGregorianCalendar MinP = normalizeToTimezone(P,
DatatypeConstants.MIN_TIMEZONE_OFFSET);
result = internalCompare(MinP, Q);
if (result == DatatypeConstants.GREATER) {
return result;
@@ -1503,7 +1523,7 @@
*/
public XMLGregorianCalendar normalize() {
- XMLGregorianCalendar normalized = normalizeToTimezone(timezone);
+ XMLGregorianCalendar normalized = normalizeToTimezone(this,
timezone);
// if timezone was undefined, leave it undefined
if (getTimezone() == DatatypeConstants.FIELD_UNDEFINED) {
@@ -1524,10 +1544,10 @@
* <p>2000-03-04T23:00:00+03:00 normalizes to 2000-03-04T20:00:00Z</p>
* <p>Implements W3C XML Schema Part 2, Section 3.2.7.3 (A).</p>
*/
- private XMLGregorianCalendar normalizeToTimezone(int timezone) {
+ private XMLGregorianCalendar normalizeToTimezone(XMLGregorianCalendar
cal, int timezone) {
int minutes = timezone;
- XMLGregorianCalendar result = (XMLGregorianCalendar) this.clone();
+ XMLGregorianCalendar result = (XMLGregorianCalendar) cal.clone();
// normalizing to UTC time negates the timezone offset before
// addition.
@@ -1691,7 +1711,7 @@
}
XMLGregorianCalendar gc = this;
if (timezone != 0) {
- gc = this.normalizeToTimezone(getTimezone());
+ gc = normalizeToTimezone(this, getTimezone());
}
return gc.getYear() + gc.getMonth() + gc.getDay() +
gc.getHour() + gc.getMinute() + gc.getSecond();
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]