You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commons-cvs@xml.apache.org by mr...@apache.org on 2008/11/10 05:57:42 UTC

svn commit: r712609 - /xml/commons/branches/tck-jaxp-1_3_0/java/external/src/javax/xml/datatype/DatatypeFactory.java

Author: mrglavas
Date: Sun Nov  9 20:57:42 2008
New Revision: 712609

URL: http://svn.apache.org/viewvc?rev=712609&view=rev
Log:
Correcting the default implementations of newDurationYearMonth() and newDurationDayTime()
so that they behave according to the JAXP specification. They must reject lexical values
which are not valid instances of xs:yearMonthDuration and xs:dayTimeDuration.

Modified:
    xml/commons/branches/tck-jaxp-1_3_0/java/external/src/javax/xml/datatype/DatatypeFactory.java

Modified: xml/commons/branches/tck-jaxp-1_3_0/java/external/src/javax/xml/datatype/DatatypeFactory.java
URL: http://svn.apache.org/viewvc/xml/commons/branches/tck-jaxp-1_3_0/java/external/src/javax/xml/datatype/DatatypeFactory.java?rev=712609&r1=712608&r2=712609&view=diff
==============================================================================
--- xml/commons/branches/tck-jaxp-1_3_0/java/external/src/javax/xml/datatype/DatatypeFactory.java (original)
+++ xml/commons/branches/tck-jaxp-1_3_0/java/external/src/javax/xml/datatype/DatatypeFactory.java Sun Nov  9 20:57:42 2008
@@ -296,7 +296,18 @@
      * @throws NullPointerException If <code>lexicalRepresentation</code> is <code>null</code>.
      */
     public Duration newDurationDayTime(final String lexicalRepresentation) {
-
+        if (lexicalRepresentation == null) {
+            throw new NullPointerException("The lexical representation cannot be null.");
+        }
+        // The lexical representation must match the pattern [^YM]*(T.*)?
+        int pos = lexicalRepresentation.indexOf('T');
+        int length = (pos >= 0) ? pos : lexicalRepresentation.length();
+        for (int i = 0; i < length; ++i) {
+            char c = lexicalRepresentation.charAt(i);
+            if (c == 'Y' || c == 'M') {
+                throw new IllegalArgumentException("Invalid dayTimeDuration value: " + lexicalRepresentation);
+            }
+        }
         return newDuration(lexicalRepresentation);
     }
 
@@ -503,7 +514,17 @@
      * @throws NullPointerException If <code>lexicalRepresentation</code> is <code>null</code>.
      */
     public Duration newDurationYearMonth(final String lexicalRepresentation) {
-
+        if (lexicalRepresentation == null) {
+            throw new NullPointerException("The lexical representation cannot be null.");
+        }
+        // The lexical representation must match the pattern [^DT]*.
+        int length = lexicalRepresentation.length();
+        for (int i = 0; i < length; ++i) {
+            char c = lexicalRepresentation.charAt(i);
+            if (c == 'D' || c == 'T') {
+                throw new IllegalArgumentException("Invalid yearMonthDuration value: " + lexicalRepresentation);
+            }
+        }
         return newDuration(lexicalRepresentation);
     }