You are viewing a plain text version of this content. The canonical link for it is here.
Posted to axis-cvs@ws.apache.org by sc...@apache.org on 2008/01/09 17:15:20 UTC

svn commit: r610431 - in /webservices/axis2/trunk/java/modules/jaxws: src/org/apache/axis2/jaxws/utility/JavaUtils.java test/org/apache/axis2/jaxws/misc/NS2PkgTest.java

Author: scheu
Date: Wed Jan  9 08:15:12 2008
New Revision: 610431

URL: http://svn.apache.org/viewvc?rev=610431&view=rev
Log:
AXIS2-3431
Contributor:Rich Scheuerle
Fix to JavaUtils NS->PKG utility to support a namespace of "".
Added a validation test.

Modified:
    webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/utility/JavaUtils.java
    webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/misc/NS2PkgTest.java

Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/utility/JavaUtils.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/utility/JavaUtils.java?rev=610431&r1=610430&r2=610431&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/utility/JavaUtils.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/utility/JavaUtils.java Wed Jan  9 08:15:12 2008
@@ -19,6 +19,9 @@
 
 package org.apache.axis2.jaxws.utility;
 
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
 import java.net.MalformedURLException;
 import java.net.URL;
 import java.util.ArrayList;
@@ -27,6 +30,8 @@
 /** Common Java Utilites */
 public class JavaUtils extends org.apache.axis2.util.JavaUtils {
 
+    private static Log log = LogFactory.getLog(JavaUtils.class);
+    
     /** Private Constructor...All methods of this class are static */
     private JavaUtils() {
     }
@@ -40,6 +45,9 @@
     public static String getPackageFromNamespace(String namespace) {
         // The following steps correspond to steps described in the JAXB Specification
 
+        if (log.isDebugEnabled()) {
+            log.debug("namespace (" +namespace +")");
+        }
         // Step 1: Scan off the host name
         String hostname = null;
         String path = null;
@@ -57,6 +65,11 @@
                 hostname = namespace;
             }
         }
+        if (log.isDebugEnabled()) {
+            log.debug("hostname (" +hostname +")");
+            log.debug("path (" +path +")");
+        }
+        
 
         // Step 3: Tokenize the host name using ":" and "/"
         StringTokenizer st = new StringTokenizer(hostname, ":/");
@@ -95,16 +108,22 @@
 
         // Step 6: Tokenize the first word with "." and reverse the order. (the www is also removed).
         // TODO This is not exactly equivalent to the JAXB Rule.
-        StringTokenizer st2 = new StringTokenizer(words[0], ".");
         ArrayList<String> list = new ArrayList<String>();
-        while (st2.hasMoreTokens()) {
-            // Add the strings so they are in reverse order
-            list.add(0, st2.nextToken());
+        if (words.length > 0) {
+            StringTokenizer st2 = new StringTokenizer(words[0], ".");
+        
+            while (st2.hasMoreTokens()) {
+                // Add the strings so they are in reverse order
+                list.add(0, st2.nextToken());
+            }
         }
+        
         // Remove www
-        String last = list.get(list.size() - 1);
-        if (last.equals("www")) {
-            list.remove(list.size() - 1);
+        if (list.size() > 0) {
+            String last = list.get(list.size() - 1);
+            if (last.equals("www")) {
+                list.remove(list.size() - 1);
+            }
         }
         // Now each of words is represented by list
         for (int i = 1; i < words.length; i++) {
@@ -147,6 +166,10 @@
             } else {
                 name = name + "." + list.get(i);
             }
+        }
+        
+        if (log.isDebugEnabled()) {
+            log.debug("package name (" +name +")");
         }
         return name;
     }

Modified: webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/misc/NS2PkgTest.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/misc/NS2PkgTest.java?rev=610431&r1=610430&r2=610431&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/misc/NS2PkgTest.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/misc/NS2PkgTest.java Wed Jan  9 08:15:12 2008
@@ -27,7 +27,7 @@
 import junit.framework.TestCase;
 
 /**
- * Tests Namespace to Package Algorithmh
+ * Tests Namespace to Package Algorithm
  *
  */
 public class NS2PkgTest extends TestCase {
@@ -37,6 +37,22 @@
         String expectedPkg1 = "org.example.newbusiness";
         
         String pkg = JavaUtils.getPackageFromNamespace(ns1);
-        assertTrue(expectedPkg1.equals(pkg));
+        assertTrue("Expected " + expectedPkg1 + "Received " +pkg, expectedPkg1.equals(pkg));
+    }
+    
+    public void test02() throws Exception {
+        String ns1 = "urn://example-org/NewBusiness";
+        String expectedPkg1 = "org.example";
+        
+        String pkg = JavaUtils.getPackageFromNamespace(ns1);
+        assertTrue("Expected " + expectedPkg1 + "Received " +pkg, expectedPkg1.equals(pkg));
+    }
+    
+    public void test03() throws Exception {
+        String ns1 = "";
+        String expectedPkg1 = "";
+        
+        String pkg = JavaUtils.getPackageFromNamespace(ns1);
+        assertTrue("Expected " + expectedPkg1 + "Received " +pkg, expectedPkg1.equals(pkg));
     }
 }



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