mrglavas 2005/09/06 19:44:18
Modified: java/src/org/apache/xerces/jaxp/datatype DurationImpl.java
XMLGregorianCalendarImpl.java
Log:
Fixing JIRA Issue #1097:
http://issues.apache.org/jira/browse/XERCESJ-1097
Because of a change in behaviour to BigDecimal.toString() in J2SE 5.0 we
cannot
rely on it to correctly generate the lexical form of XMLGregorianCalendar.
Copying
over the BigDecimal formatting code from DurationImpl which will work
regardless
of the JDK level.
Revision Changes Path
1.5 +2 -2
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.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- DurationImpl.java 17 May 2005 20:59:48 -0000 1.4
+++ DurationImpl.java 7 Sep 2005 02:44:18 -0000 1.5
@@ -756,7 +756,7 @@
if (seconds != null &&
seconds.toBigInteger().compareTo(maxintAsBigInteger) == 1) {
throw new UnsupportedOperationException(
DatatypeMessageFormatter.formatMessage(null,
"TooLarge",
- new Object[]{this.getClass().getName() +
"#compare(Duration duration)" + DatatypeConstants.SECONDS.toString(),
seconds.toString()})
+ new Object[]{this.getClass().getName() +
"#compare(Duration duration)" + DatatypeConstants.SECONDS.toString(),
toString(seconds)})
//this.getClass().getName() +
"#compare(Duration duration)"
//+ " seconds too large to be
supported by this implementation "
1.5 +39 -2
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.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- XMLGregorianCalendarImpl.java 17 May 2005 20:59:48 -0000 1.4
+++ XMLGregorianCalendarImpl.java 7 Sep 2005 02:44:18 -0000 1.5
@@ -2957,7 +2957,7 @@
case 's':
printNumber(buf,getSecond(),2);
if (getFractionalSecond() != null) {
- String frac = getFractionalSecond().toString();
+ String frac = toString(getFractionalSecond());
//skip leading zero.
buf.append(frac.substring(1, frac.length()));
}
@@ -3023,6 +3023,43 @@
out.append('0');
out.append(s);
}
+
+ /**
+ * <p>Turns [EMAIL PROTECTED] BigDecimal} to a string representation.</p>
+ *
+ * <p>Due to a behavior change in the [EMAIL PROTECTED]
BigDecimal#toString()}
+ * method in JDK1.5, this had to be implemented here.</p>
+ *
+ * @param bd <code>BigDecimal</code> to format as a <code>String</code>
+ *
+ * @return <code>String</code> representation of
<code>BigDecimal</code>
+ */
+ private String toString(BigDecimal bd) {
+ String intString = bd.unscaledValue().toString();
+ int scale = bd.scale();
+
+ if (scale == 0) {
+ return intString;
+ }
+
+ /* Insert decimal point */
+ StringBuffer buf;
+ int insertionPoint = intString.length() - scale;
+ if (insertionPoint == 0) { /* Point goes right before intVal */
+ return "0." + intString;
+ } else if (insertionPoint > 0) { /* Point goes inside intVal */
+ buf = new StringBuffer(intString);
+ buf.insert(insertionPoint, '.');
+ } else { /* We must insert zeros between point and intVal */
+ buf = new StringBuffer(3 - insertionPoint + intString.length());
+ buf.append("0.");
+ for (int i = 0; i < -insertionPoint; i++) {
+ buf.append('0');
+ }
+ buf.append(intString);
+ }
+ return buf.toString();
+ }
/**
* Compute <code>value*signum</code> where value==null is treated as
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]