You are viewing a plain text version of this content. The canonical link for it is here.
Posted to woden-dev@ws.apache.org by jk...@apache.org on 2007/01/31 18:14:21 UTC

svn commit: r501904 - in /incubator/woden/trunk/java: src/javax/xml/namespace/ test/javax/xml/namespace/ test/org/apache/woden/tests/

Author: jkaputin
Date: Wed Jan 31 09:14:19 2007
New Revision: 501904

URL: http://svn.apache.org/viewvc?view=rev&rev=501904
Log:
WODEN-125 Modified behaviour of the valueOf method
to confirm to the Javadoc. That is, the namespaceURI
and localPart portions of the string literal are
not validated as URI and NCName respectively.

Modified:
    incubator/woden/trunk/java/src/javax/xml/namespace/QName.java
    incubator/woden/trunk/java/test/javax/xml/namespace/QNameTest.java
    incubator/woden/trunk/java/test/org/apache/woden/tests/AllWodenTests.java
    incubator/woden/trunk/java/test/org/apache/woden/tests/AllWodenTestsDOM.java
    incubator/woden/trunk/java/test/org/apache/woden/tests/AllWodenTestsOM.java

Modified: incubator/woden/trunk/java/src/javax/xml/namespace/QName.java
URL: http://svn.apache.org/viewvc/incubator/woden/trunk/java/src/javax/xml/namespace/QName.java?view=diff&rev=501904&r1=501903&r2=501904
==============================================================================
--- incubator/woden/trunk/java/src/javax/xml/namespace/QName.java (original)
+++ incubator/woden/trunk/java/src/javax/xml/namespace/QName.java Wed Jan 31 09:14:19 2007
@@ -25,18 +25,16 @@
  * as specified in <a href="http://www.w3.org/TR/xmlschema-2/#QName">XML
  * Schema Part2: Datatypes specification</a>.
  * <p>
- * The WSDL4J version of QName has been copied and updated for Apache Woden.
- * It now conforms to the version 1.1 QName described in the Javadoc at 
- * <code>
- * "http://java.sun.com/j2ee/1.4/docs/api/javax/xml/namespace/QName.html".
- * </code>
+ * The WSDL4J version of QName has been copied and updated for Apache Woden to
+ * match the QName class defined for Java 5.0. 
+ * @see "http://java.sun.com/j2se/1.5.0/docs/api/javax/xml/namespace/QName.html".
  * <p>
  * The value of a QName contains a <b>namespaceURI</b>, a <b>localPart</b> 
  * and a <b>prefix</b>.
  * The localPart provides the local part of the qualified name. The
  * namespaceURI is a URI reference identifying the namespace. The prefix 
  * corresponds to a namespace declaration 'xmlns:somePrefix' in the underlying xml. 
- *
+ * <p>
  * Note: Some of this impl code was taken from Axis.
  * <p>
  * The constructors throw an IllegalArgumentException if the 'localPart' 
@@ -47,6 +45,12 @@
  * The constructor that does take a 'prefix' argument will throw an 
  * IllegalArgumentException if a null value is used (i.e. the absence 
  * of any 'prefix' must be specified explicitly as the empty string "").
+ * <p>
+ * The <code>valueOf</code> method behaves like the constructors in that 
+ * a null value will throw an IllegalArgumentException, but an empty string "" 
+ * value treated as a localPart which is allowed to retain compatibility with 
+ * v1.0 QName.
+ * <p>
  * To support the deserialization of objects that were serialized with an
  * older version of QName (i.e. without a 'prefix' field), the 
  * <code>readObject</code> method will check if the 'prefix' 
@@ -106,14 +110,15 @@
   /**
    * Constructor for the QName.
    * Takes a localPart, a namespace and a prefix. If the namespace is
-   * null, it defaults to the empty string "". The prefix cannot be 
-   * null. If there is no prefix, an empty string "" must be used.
+   * null, it defaults to the empty string "". The localPart and prefix
+   * cannot be null. If they are, an IllegalArgumentException is thrown.
+   * If there is no prefix, an empty string "" must be specified.
    *
    * @param namespaceURI Namespace URI for the QName
    * @param localPart Local part of the QName.
    * @param prefix the xmlns-declared prefix for this namespaceURI
    * 
-   * @throws IllegalArgumentException if localPart is null.
+   * @throws IllegalArgumentException if localPart or prefix is null.
    */
   public QName(String namespaceURI, String localPart, String prefix)
   {
@@ -232,6 +237,7 @@
    * part being optional.
    * If the Namespace URI .equals(""), only the local part should be 
    * provided.
+   * An empty string "" value will be treated as the localPart.
    * <p>
    * The prefix value CANNOT be represented in the String and will be 
    * set to "".
@@ -254,40 +260,19 @@
                   "Invalid QName literal - null string.");
     }
 
-    if (s.equals(""))
-    {
-      throw new IllegalArgumentException(
-                  "Invalid QName literal - empty string.");
-    }
-    
-    int a = s.indexOf("{");
-    int b = s.lastIndexOf("{");
-    int c = s.indexOf("}");
-    int d = s.lastIndexOf("}");
-    
-    if(   a > 0                //'{' is not the first character
-       || a != b               //more than one '{' exists
-       || a != -1 && c == -1   //'{' not matched by a '}'
-       || a == -1 && c != -1   //'}' not matched by a '{'
-       || c != d               //more than one '}' exists
-       || c == s.length() - 1  //namespace only, no local part
-      )
-    {
-        throw new IllegalArgumentException(
-                "Invalid QName literal '" + s + "'.");
-    }
-    
-    //We have confirmed that if the qname-as-string contains 
-    //'{' and '}' braces then they are correctly formatted.
-    
-    if (s.charAt(0) == '{')
-    {
-        //namespace and local part
-        return new QName(s.substring(1, c), s.substring(c + 1));
-    }
-    else
-    {
-        //local part only
+    if(s.indexOf("{") == 0) {
+        int rightBrace = s.indexOf("}");
+        if(rightBrace == -1 || rightBrace == s.length() - 1)
+        {
+            //No matching right brace or no local part after right brace
+            throw new IllegalArgumentException(
+                    "Invalid QName literal '" + s + "'.");
+        } else {
+            //namespace and local part
+            return new QName(s.substring(1, rightBrace), s.substring(rightBrace + 1));
+        }
+    } else {
+        //treat the whole string as the local part
         return new QName(s);
     }
   }

Modified: incubator/woden/trunk/java/test/javax/xml/namespace/QNameTest.java
URL: http://svn.apache.org/viewvc/incubator/woden/trunk/java/test/javax/xml/namespace/QNameTest.java?view=diff&rev=501904&r1=501903&r2=501904
==============================================================================
--- incubator/woden/trunk/java/test/javax/xml/namespace/QNameTest.java (original)
+++ incubator/woden/trunk/java/test/javax/xml/namespace/QNameTest.java Wed Jan 31 09:14:19 2007
@@ -274,6 +274,10 @@
         {
             fail("QName was not instantiated.");
         }
+        
+        assertEquals("Input string literal must match the output of toString()",
+                "{myNamespace}myLocalPart",
+                qname.toString() );
     }
     
     public void testValueOfGoodLocalPartOnly()
@@ -287,6 +291,10 @@
                         qname.getLocalPart().equals("myLocalPart") &&
                         qname.getPrefix().equals(emptyString))
                       );
+            
+            assertEquals("Input string literal must match the output of toString()",
+                    "myLocalPart",
+                    qname.toString() );
         }
         else
         {
@@ -304,115 +312,113 @@
             b = true;
         }
         
-        assertTrue("Expected an IllegalArgumentException because " +
-                   "qname string argument cannot be null.",
+        assertTrue("Expected an IllegalArgumentException because the string literal cannot be null.",
                    b);
     }
     
-    public void testValueOfBadEmptyString()
+    public void testValueOfBadUnmatchedLeftBrace()
     {
-        boolean b = false;
-        
         try {
-            qname = QName.valueOf("");
+            qname = QName.valueOf("{myNamespacemyLocalPart");
         } catch (IllegalArgumentException e) {
-            b = true;
+            return;
         }
-        
-        assertTrue("Expected an IllegalArgumentException because " +
-                   "qname string argument cannot be the empty string \"\".",
-                   b);
+        fail("Expected an IllegalArgumentException because the starting left brace is not matched by a right brace: " + "\"{myNamespacemyLocalPart\"");
     }
     
-    public void testValueOfBadLeftBraceNotLeftmost()
+    /* TODO these tests commented out for now (M7), because different QName impls get loaded depending on the
+     * environment (e.g. Ant 1.7.0, Java 5.0) and as they all differ slightly, some of these testcases which
+     * pass for the Woden QName class will fail for other QName implementations. Will need to either
+     * use a classloader to ensure that the Woden QName class is always used for these testcases or maybe
+     * just delete these testcases and keep the minimal testcases above for the valueOf() method. 
+     * Note, it only seems to be the testcases for the valueOf() method that are affected.
+     * 
+    public void testValueOfBadNoLocalpart()
     {
-        boolean b = false;
-        
         try {
-            qname = QName.valueOf("x{myNamespace}myLocalPart");
+            qname = QName.valueOf("{myNamespace}");
         } catch (IllegalArgumentException e) {
-            b = true;
+            return;
         }
-        
-        assertTrue("Expected an IllegalArgumentException because " +
-                   "'{' is not the leftmost character.",
-                   b);
+        fail("Expected an IllegalArgumentException because there is no local part: " + "\"{myNamespace}\"");
     }
     
-    public void testValueOfBadMultipleLeftBraces()
+    public void testValueOfGoodLeftBraceNotLeftmost()
     {
-        boolean b = false;
-        
+        //this is junk, but it is permitted according to the QName Javadoc
         try {
-            qname = QName.valueOf("{myNam{espace}myLocalPart");
+            qname = QName.valueOf("x{myNamespace}myLocalPart");
         } catch (IllegalArgumentException e) {
-            b = true;
+            fail("The QName literal is not illegal: " + "\"x{myNamespace}myLocalPart\"");
         }
         
-        assertTrue("Expected an IllegalArgumentException because " +
-                   "there is more that one '{'.",
-                   b);
+        assertTrue("QName created from string literal is incorrect.",
+                 (qname.getNamespaceURI().equals(emptyString) && 
+                  qname.getLocalPart().equals("x{myNamespace}myLocalPart") &&
+                  qname.getPrefix().equals(emptyString)) );
+        
+        assertEquals("Input string literal must match the output of toString()",
+                "x{myNamespace}myLocalPart",
+                qname.toString() );
     }
     
-    public void testValueOfBadUnmatchedLeftBrace()
+    public void testValueOfGoodMultipleLeftBraces()
     {
-        boolean b = false;
-        
+        //this is junk, but it is permitted according to the QName Javadoc
         try {
-            qname = QName.valueOf("{myNamespacemyLocalPart");
+            qname = QName.valueOf("{myNam{espace}myLocalPart");
         } catch (IllegalArgumentException e) {
-            b = true;
+            fail("The QName literal is not illegal: " + "\"{myNam{espace}myLocalPart\"");
         }
         
-        assertTrue("Expected an IllegalArgumentException because " +
-                   "a '{' does not have a matching '}'.",
-                   b);
+        assertTrue("QName created from string literal is incorrect.",
+                (qname.getNamespaceURI().equals("myNam{espace") && 
+                 qname.getLocalPart().equals("myLocalPart") && 
+                 qname.getPrefix().equals(emptyString)) );
+        
+        assertEquals("Input string literal must match the output of toString()",
+                "{myNam{espace}myLocalPart",
+                qname.toString() );
     }
     
-    public void testValueOfBadUnmatchedRightBrace()
+    public void testValueOfGoodUnmatchedRightBrace()
     {
-        boolean b = false;
-        
+        //this is junk, but it is permitted according to the QName Javadoc
         try {
             qname = QName.valueOf("myNamespace}myLocalPart");
         } catch (IllegalArgumentException e) {
-            b = true;
+            fail("The QName literal is not illegal: " + "\"myNamespace}myLocalPart\"");
         }
         
-        assertTrue("Expected an IllegalArgumentException because " +
-                   "a '}' does not have a matching '{'.",
-                   b);
+        assertTrue("QName created from string literal is incorrect.",
+                (qname.getNamespaceURI().equals(emptyString) && 
+                 qname.getLocalPart().equals("myNamespace}myLocalPart") &&
+                 qname.getPrefix().equals(emptyString)) );
+        
+        assertEquals("Input string literal must match the output of toString()",
+                "myNamespace}myLocalPart",
+                qname.toString() );
     }
 
-    public void testValueOfBadMultipleRightBraces()
+    public void testValueOfGoodMultipleRightBraces()
     {
-        boolean b = false;
-        
+        //this is junk, but it is permitted according to the QName Javadoc
         try {
             qname = QName.valueOf("{myNam}espace}myLocalPart");
         } catch (IllegalArgumentException e) {
-            b = true;
+            fail("The QName literal is not illegal: " + "\"{myNam}espace}myLocalPart\"");
         }
         
-        assertTrue("Expected an IllegalArgumentException because " +
-                   "there is more that one '}'.",
-                   b);
-    }
-    
-    public void testValueOfBadNoLocalpart()
-    {
-        boolean b = false;
+        assertTrue("QName created from string literal is incorrect.",
+                (qname.getNamespaceURI().equals("myNam") && 
+                 qname.getLocalPart().equals("espace}myLocalPart") &&
+                 qname.getPrefix().equals(emptyString)) );
         
-        try {
-            qname = QName.valueOf("{myNamespace}");
-        } catch (IllegalArgumentException e) {
-            b = true;
-        }
-        
-        assertTrue("Expected an IllegalArgumentException because " +
-                   "the string only has a namespaceURI, but no localPart.",
-                   b);
+        assertEquals("Input string literal must match the output of toString()",
+                "{myNam}espace}myLocalPart",
+                qname.toString() );
     }
+    */
 
     /* ************************************************
      * Tests for deserializing.

Modified: incubator/woden/trunk/java/test/org/apache/woden/tests/AllWodenTests.java
URL: http://svn.apache.org/viewvc/incubator/woden/trunk/java/test/org/apache/woden/tests/AllWodenTests.java?view=diff&rev=501904&r1=501903&r2=501904
==============================================================================
--- incubator/woden/trunk/java/test/org/apache/woden/tests/AllWodenTests.java (original)
+++ incubator/woden/trunk/java/test/org/apache/woden/tests/AllWodenTests.java Wed Jan 31 09:14:19 2007
@@ -16,14 +16,15 @@
  */
 package org.apache.woden.tests;
 
-import org.apache.woden.ant.ObjectIdTable;
-import org.apache.woden.ant.ObjectIdTableTest;
-import org.apache.woden.types.NCNameTest;
-import org.apache.woden.wsdl20.xml.ChildElementCreationTest;
+import javax.xml.namespace.QNameTest;
 
 import junit.framework.Test;
 import junit.framework.TestSuite;
 
+import org.apache.woden.ant.ObjectIdTableTest;
+import org.apache.woden.types.NCNameTest;
+import org.apache.woden.wsdl20.xml.ChildElementCreationTest;
+
 public class AllWodenTests extends TestSuite 
 {
   /**
@@ -45,7 +46,20 @@
    */
   public AllWodenTests()
   {
-    super("AllWodenTests");
+      super("AllWodenTests");
+    
+      String ver = System.getProperty("java.version");
+      if(ver.startsWith("1.4"))
+      {
+          /*
+           * From Java 5.0 the QName class is included in the jre and loaded
+           * by the bootstrap classloader, so we don't want to run Woden's QName
+           * tests against the Java 5 implementation. However, we are running in a 
+           * 1.4 jvm now, so the Woden QName class will be loaded and we do want to
+           * run the Woden junit tests for this class.
+           */
+          addTest(QNameTest.suite());
+      }
     
       addTest(AllWodenTestsDOM.suite());
       addTest(AllWodenTestsOM.suite());

Modified: incubator/woden/trunk/java/test/org/apache/woden/tests/AllWodenTestsDOM.java
URL: http://svn.apache.org/viewvc/incubator/woden/trunk/java/test/org/apache/woden/tests/AllWodenTestsDOM.java?view=diff&rev=501904&r1=501903&r2=501904
==============================================================================
--- incubator/woden/trunk/java/test/org/apache/woden/tests/AllWodenTestsDOM.java (original)
+++ incubator/woden/trunk/java/test/org/apache/woden/tests/AllWodenTestsDOM.java Wed Jan 31 09:14:19 2007
@@ -16,8 +16,6 @@
  */
 package org.apache.woden.tests;
 
-import javax.xml.namespace.QNameTest;
-
 import junit.framework.Test;
 import junit.framework.TestSuite;
 
@@ -96,18 +94,6 @@
   public AllWodenTestsDOM()
   {
     super("AllWodenTestsDOM");
-
-    String ver = System.getProperty("java.version");
-    if(ver.startsWith("1.4"))
-    {
-        /*
-         * From Java 1.5.0 the QName class is included in the jre and loaded
-         * by the bootstrap classloader. However, we are running a 1.4 jvm
-         * now, so the Woden QName class will be loaded and we do want to
-         * run the junit tests for this class.
-         */
-        addTest(QNameTest.suite());
-    }
 
 	addTest(WSDLFactoryTest.suite());
     addTest(WSDLReaderTest.suite());

Modified: incubator/woden/trunk/java/test/org/apache/woden/tests/AllWodenTestsOM.java
URL: http://svn.apache.org/viewvc/incubator/woden/trunk/java/test/org/apache/woden/tests/AllWodenTestsOM.java?view=diff&rev=501904&r1=501903&r2=501904
==============================================================================
--- incubator/woden/trunk/java/test/org/apache/woden/tests/AllWodenTestsOM.java (original)
+++ incubator/woden/trunk/java/test/org/apache/woden/tests/AllWodenTestsOM.java Wed Jan 31 09:14:19 2007
@@ -16,8 +16,6 @@
  */
 package org.apache.woden.tests;
 
-import javax.xml.namespace.QNameTest;
-
 import junit.framework.Test;
 import junit.framework.TestSuite;
 
@@ -48,16 +46,6 @@
   public AllWodenTestsOM(){
     super("AllWodenTestsOM");
 
-    String ver = System.getProperty("java.version");
-    if(ver.startsWith("1.4")){
-        /*
-         * From Java 1.5.0 the QName class is included in the jre and loaded
-         * by the bootstrap classloader. However, we are running a 1.4 jvm
-         * now, so the Woden QName class will be loaded and we do want to
-         * run the junit tests for this class.
-         */
-        addTest(QNameTest.suite());
-    }
     addTest(OMWSDLFactoryTest.suite());
 	addTest(OMWSDLReaderTest.suite());
 	addTest(OMW3CTestSuiteTest.suite());



---------------------------------------------------------------------
To unsubscribe, e-mail: woden-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: woden-dev-help@ws.apache.org