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 ba...@apache.org on 2006/12/19 02:13:33 UTC

svn commit: r488478 - in /webservices/axis2/trunk/java/modules/jaxws: src/org/apache/axis2/jaxws/description/builder/ test/org/apache/axis2/jaxws/description/builder/ test/org/apache/axis2/jaxws/framework/

Author: barrettj
Date: Mon Dec 18 17:13:33 2006
New Revision: 488478

URL: http://svn.apache.org/viewvc?view=rev&rev=488478
Log:
Correctly handle parameters that are arrays, either of primitive types or objects.

Added:
    webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/description/builder/ParameterParsingTests.java
      - copied, changed from r488152, webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/description/builder/GenericsParsingTests.java
Removed:
    webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/description/builder/GenericsParsingTests.java
Modified:
    webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/description/builder/ParameterDescriptionComposite.java
    webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/framework/JAXWSTest.java

Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/description/builder/ParameterDescriptionComposite.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/description/builder/ParameterDescriptionComposite.java?view=diff&rev=488478&r1=488477&r2=488478
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/description/builder/ParameterDescriptionComposite.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/description/builder/ParameterDescriptionComposite.java Mon Dec 18 17:13:33 2006
@@ -89,7 +89,11 @@
     
     private Class loadClassFromPDC(String classToLoad) {
         Class returnClass = null;
-        ClassLoader classLoader = null; 
+        ClassLoader classLoader = null;
+        
+        // If this is an array, then create a string version as described by Class.getName.
+        // For example, "Foo[][]" becomes "[[LFoo".  Note that arrays of primitives must also be parsed.
+        classToLoad = reparseIfArray(classToLoad);
         
         if (getMethodDescriptionCompositeRef() != null) {
             if (getMethodDescriptionCompositeRef().getDescriptionBuilderCompositeRef() != null){
@@ -117,8 +121,86 @@
         return returnClass;
     }
     
-
-	/**
+    /**
+     * If the parameter represents and array, then the returned string is in a format that
+     * a Class.forName(String) can be done on it.  This format is described by Class.getName().
+     * If the parameter does not represent an array, the parememter is returned unmodified.
+     * 
+     * Note that arrays of primitives are processed as well as arrays of objects.
+     * @param classToLoad
+     * @return
+     */
+	private String reparseIfArray(String classToLoad) {
+	    
+        String reparsedClassName = classToLoad;
+        if (isClassAnArray(classToLoad)) {
+            String baseType = getBaseArrayClassName(classToLoad);
+            String dimensionPrefix = getArrayDimensionPrefix(classToLoad);
+            if (getPrimitiveTypeArrayEncoding(baseType) != null) {
+                reparsedClassName = dimensionPrefix + getPrimitiveTypeArrayEncoding(baseType);
+            }
+            else {
+                reparsedClassName = dimensionPrefix + "L" + baseType + ";";  
+            }
+        }
+        return reparsedClassName;
+    }
+    /**
+     * Answers if the String representing the class contains an array declaration.
+     * For example "Foo[][]" would return true, as would "int[]".
+     * @param className
+     * @return
+     */
+    private boolean isClassAnArray(String className) {
+        if (className != null && className.indexOf("[") > 0) {
+            return true;
+        }
+        else {
+            return false;
+        }
+    }
+    /** 
+     * For an class name that is an array, return the non-array declaration portion.
+     * For example "my.package.Foo[][]" would return "my.package.Foo". Returns null if
+     * the argument does not contain an array declaration.
+     * @param fullClassName
+     * @return
+     */
+    private String getBaseArrayClassName(String fullClassName) {
+        String baseArrayClassName = null;
+        if (fullClassName != null) {
+            int firstArrayDimension = fullClassName.indexOf("[");
+            if (firstArrayDimension > 0) {
+                baseArrayClassName = fullClassName.substring(0, firstArrayDimension);
+            }
+        }
+        return baseArrayClassName;
+    }
+    /**
+     * Return a prefix suitable for passing to Class.forName(String) for an array.  Each array dimension
+     * represented by "[]" will be represented by a single "[".
+     * @param arrayClassName
+     * @return
+     */
+    private String getArrayDimensionPrefix(String arrayClassName) {
+        StringBuffer arrayDimPrefix = new StringBuffer();
+        
+        if (arrayClassName != null) {
+            int arrayDimIndex = arrayClassName.indexOf("[]");
+            while (arrayDimIndex > 0) {
+                arrayDimPrefix.append("[");
+                // Skip over this "[]" and see if there are any more.
+                int startNext = arrayDimIndex + 2;
+                arrayDimIndex = arrayClassName.indexOf("[]", startNext);
+            }
+        }
+        
+        if (arrayDimPrefix.length() > 0)
+            return arrayDimPrefix.toString();
+        else
+            return null;
+    }
+    /**
 	 * @return Returns the webParamAnnot.
 	 */
 	public WebParamAnnot getWebParamAnnot() {
@@ -201,32 +283,88 @@
 	public void setMethodDescriptionCompositeRef(MethodDescriptionComposite mdc) {
 		this.parentMDC = mdc;
 	}
-
+    
+    private static final String INT_PRIMITIVE = "int";
+    private static final String BYTE_PRIMITIVE = "byte";
+    private static final String CHAR_PRIMITIVE = "char";
+    private static final String SHORT_PRIMITIVE = "short";
+    private static final String BOOLEAN_PRIMITIVE = "boolean";
+    private static final String LONG_PRIMITIVE = "long";
+    private static final String FLOAT_PRIMITIVE = "float";
+    private static final String DOUBLE_PRIMITIVE = "double";
+    private static final String VOID_PRIMITIVE = "void";
+
+    /**
+     * For primitives, return the appropriate primitive class.  Note that arrays of primitives are
+     * handled differently, like arrays of objects.  Only non-array primitives are processed by this
+     * method.
+     * @param classType
+     * @return
+     */
 	private Class getPrimitiveClass(String classType) {
 		
 		Class paramClass = null;
 
-		if (classType.equals("int")) {
+		if (INT_PRIMITIVE.equals(classType)) {
 			paramClass = int.class;
-		} else if (classType.equals("byte")) {
+		} else if (BYTE_PRIMITIVE.equals(classType)) {
 			paramClass = byte.class;
-		} else if (classType.equals("char")) {
+		} else if (CHAR_PRIMITIVE.equals(classType)) {
 			paramClass = char.class;
-		} else if (classType.equals("short")) {
+		} else if (SHORT_PRIMITIVE.equals(classType)) {
 			paramClass = short.class;
-		} else if (classType.equals("boolean")) {
+		} else if (BOOLEAN_PRIMITIVE.equals(classType)) {
 			paramClass = boolean.class;
-		} else if (classType.equals("long")) {
+		} else if (LONG_PRIMITIVE.equals(classType)) {
 			paramClass = long.class;
-		} else if (classType.equals("float")) {
+		} else if (FLOAT_PRIMITIVE.equals(classType)) {
 			paramClass = float.class;
-		} else if (classType.equals("double")) {
+		} else if (DOUBLE_PRIMITIVE.equals(classType)) {
 			paramClass = double.class;
-		} else if (classType.equals("void")) {
+		} else if (VOID_PRIMITIVE.equals(classType)) {
 			paramClass = void.class;
 		}
 		return paramClass;
 	}
+    /**
+     * Returns the encoding used to represent a Class for an array of 
+     * a primitive type.  For example, an array of boolean is represented by "Z".  
+     * This is as described in the javadoc for Class.getName().  If the argument is
+     * not a primitive type, a null will be returned.
+     * 
+     * Note that arrays of voids are not allowed; a null will be returned.
+     * @param primitiveType
+     * @return
+     */
+    private String getPrimitiveTypeArrayEncoding(String primitiveType) {
+        String encoding = null;
+        
+        if (BOOLEAN_PRIMITIVE.equals(primitiveType)) {
+            encoding = "Z";
+        }
+        else if (BYTE_PRIMITIVE.equals(primitiveType)) {
+            encoding = "B";
+        }
+        else if (CHAR_PRIMITIVE.equals(primitiveType)) {
+            encoding = "C";
+        }
+        else if (DOUBLE_PRIMITIVE.equals(primitiveType)) {
+            encoding = "D";
+        }
+        else if (FLOAT_PRIMITIVE.equals(primitiveType)) {
+            encoding = "F";
+        }
+        else if (INT_PRIMITIVE.equals(primitiveType)) {
+            encoding = "I";
+        }
+        else if (LONG_PRIMITIVE.equals(primitiveType)) {
+            encoding = "J";
+        }
+        else if (SHORT_PRIMITIVE.equals(primitiveType)) {
+            encoding = "S";
+        }
+        return encoding;
+    }
 	
 	/**
 	 * Convenience method for unit testing. We will print all of the 

Copied: webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/description/builder/ParameterParsingTests.java (from r488152, webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/description/builder/GenericsParsingTests.java)
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/description/builder/ParameterParsingTests.java?view=diff&rev=488478&p1=webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/description/builder/GenericsParsingTests.java&r1=488152&p2=webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/description/builder/ParameterParsingTests.java&r2=488478
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/description/builder/GenericsParsingTests.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/description/builder/ParameterParsingTests.java Mon Dec 18 17:13:33 2006
@@ -18,43 +18,167 @@
  */
 package org.apache.axis2.jaxws.description.builder;
 
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.xml.ws.Holder;
+
 import junit.framework.TestCase;
 
 /**
  * Tests the parsing of Generics that are used in the DescriptionBuilderComposite
  * processing.
  */
-public class GenericsParsingTests extends TestCase {
-    private static String JAXWS_HOLDER = "javax.xml.ws.Holder";
+public class ParameterParsingTests extends TestCase {
     
     public void testHolder() {
-        String holderInputString = JAXWS_HOLDER + "<java.lang.Object>";
+        String holderInputString = "javax.xml.ws.Holder<java.lang.Object>";
+        ParameterDescriptionComposite pdc = new ParameterDescriptionComposite();
+        pdc.setParameterType(holderInputString);
+        assertEquals("javax.xml.ws.Holder<java.lang.Object>", pdc.getParameterType());
+        
         assertTrue(ParameterDescriptionComposite.isHolderType(holderInputString));
+        assertTrue(pdc.isHolderType());
         String holderResultString = ParameterDescriptionComposite.getRawType(holderInputString);
-        assertEquals(JAXWS_HOLDER, holderResultString);
-        
+        assertEquals("javax.xml.ws.Holder", holderResultString);
+        holderResultString = pdc.getRawType();
+        assertEquals("javax.xml.ws.Holder", holderResultString);
+        javax.xml.ws.Holder validateHolder = new javax.xml.ws.Holder();
+        assertEquals(validateHolder.getClass(), pdc.getParameterTypeClass());
+              
         String actualTypeResult = ParameterDescriptionComposite.getHolderActualType(holderInputString);
         assertEquals("java.lang.Object", actualTypeResult);
+        actualTypeResult = pdc.getHolderActualType();
+        assertEquals("java.lang.Object", actualTypeResult);
+        java.lang.Object validateObject = new java.lang.Object();
+        assertEquals(validateObject.getClass(), pdc.getHolderActualTypeClass());
+    }
+    
+    public void testHolderMyObject() {
+        ParameterDescriptionComposite pdc = new ParameterDescriptionComposite();
+        pdc.setParameterType("javax.xml.ws.Holder<org.apache.axis2.jaxws.description.builder.MyObject>");
+        assertEquals("javax.xml.ws.Holder<org.apache.axis2.jaxws.description.builder.MyObject>", pdc.getParameterType());
+        
+        assertTrue(pdc.isHolderType());
+        assertEquals("javax.xml.ws.Holder", pdc.getRawType());
+        assertEquals(Holder.class, pdc.getParameterTypeClass());
+        
+        assertEquals("org.apache.axis2.jaxws.description.builder.MyObject", pdc.getHolderActualType());
+        assertEquals(MyObject.class, pdc.getHolderActualTypeClass());
     }
 
     public void testNonHolderGenric() {
-        String inputString = "java.util.List<my.package.MyClass>";
-        assertFalse(ParameterDescriptionComposite.isHolderType(inputString));
-        String genericType = ParameterDescriptionComposite.getRawType(inputString);
+        String inputString = "java.util.List<org.apache.axis2.jaxws.description.builder.MyObject>";
+        ParameterDescriptionComposite pdc = new ParameterDescriptionComposite();
+        pdc.setParameterType(inputString);
+        assertEquals("java.util.List<org.apache.axis2.jaxws.description.builder.MyObject>", pdc.getParameterType());
+        
+        assertFalse(pdc.isHolderType());
+        String genericType = pdc.getRawType();
         assertEquals("java.util.List", genericType);
+        assertEquals(java.util.List.class, pdc.getParameterTypeClass());
+        
         // This should be null since the generic is not a Holder type
-        String actualParam = ParameterDescriptionComposite.getHolderActualType(inputString);
+        String actualParam = pdc.getHolderActualType();
         assertNull(actualParam);
+        assertNull(pdc.getHolderActualTypeClass());
     }
     
     public void testHolderGeneric() {
-        String holderInputString = JAXWS_HOLDER + "<java.util.List<java.lang.Object>>";
-        assertTrue(ParameterDescriptionComposite.isHolderType(holderInputString));
-        String holderResultString = ParameterDescriptionComposite.getRawType(holderInputString);
-        assertEquals(JAXWS_HOLDER, holderResultString);
+        String holderInputString = "javax.xml.ws.Holder<java.util.List<java.lang.Object>>";
+        ParameterDescriptionComposite pdc = new ParameterDescriptionComposite();
+        pdc.setParameterType(holderInputString);
+        assertEquals("javax.xml.ws.Holder<java.util.List<java.lang.Object>>", pdc.getParameterType());
         
-        String actualTypeResult = ParameterDescriptionComposite.getHolderActualType(holderInputString);
+        assertTrue(pdc.isHolderType());
+        String holderResultString = pdc.getRawType();
+        assertEquals("javax.xml.ws.Holder", holderResultString);
+        assertEquals(Holder.class, pdc.getParameterTypeClass());
+        
+        String actualTypeResult = pdc.getHolderActualType();
         assertEquals("java.util.List", actualTypeResult);
+        assertEquals(List.class, pdc.getHolderActualTypeClass());
+    }
+    
+    public void testPrimitives() {
+        String[] primitivesToTest = {"boolean", "byte", "char", "double", "float", "int", "long", "short"};
+        Class[] primitiveClasses = {boolean.class, byte.class, char.class, double.class, float.class, int.class, long.class, short.class};
+        
+        for (int i = 0; i < primitivesToTest.length; i++) {
+            assertFalse(ParameterDescriptionComposite.isHolderType(primitivesToTest[i]));
+            assertNull(ParameterDescriptionComposite.getRawType(primitivesToTest[i]));
+            ParameterDescriptionComposite pdc = new ParameterDescriptionComposite();
+            pdc.setParameterType(primitivesToTest[i]);
+            assertEquals(primitiveClasses[i], pdc.getParameterTypeClass());
+        }
+    }
+    
+    public void testPrimitiveArrays() {
+        String[] primitivesToTest = {"boolean[]", "byte[]", "char[]", "double[]", "float[]", "int[]", "long[]", "short[]"};
+        Class[] primitiveClasses = {boolean[].class, byte[].class, char[].class, double[].class, float[].class, int[].class, long[].class, short[].class};
+        
+        for (int i = 0; i < primitivesToTest.length; i++) {
+            ParameterDescriptionComposite pdc = new ParameterDescriptionComposite();
+            pdc.setParameterType(primitivesToTest[i]);
+            assertEquals(primitiveClasses[i], pdc.getParameterTypeClass());
+        }
+    }
+    
+    public void testPrimitiveMultiDimArrays() {
+        String[] primitivesToTest = {"boolean[][]", "byte[][][]", "char[][][][]", "double[][][][][]", "float[][][][][][]", "int[]", "long[]", "short[]"};
+        Class[] primitiveClasses = {boolean[][].class, byte[][][].class, char[][][][].class, double[][][][][].class, float[][][][][][].class, int[].class, long[].class, short[].class};
+        for (int i = 0; i < primitivesToTest.length; i++) {
+            ParameterDescriptionComposite pdc = new ParameterDescriptionComposite();
+            pdc.setParameterType(primitivesToTest[i]);
+            assertEquals(primitiveClasses[i], pdc.getParameterTypeClass());
+        }
+    }
+    
+    public void testJavaLangObjectArrays() {
+        ParameterDescriptionComposite pdcObject = new ParameterDescriptionComposite();
+        pdcObject.setParameterType("java.lang.Object[]");
+        Object[] verifyObject = new Object[5];
+        assertEquals(verifyObject.getClass(), pdcObject.getParameterTypeClass());
+        
+        ParameterDescriptionComposite pdcString = new ParameterDescriptionComposite();
+        pdcString.setParameterType("java.lang.String[][][]");
+        String[][][] verifyString = new String[5][1][3];
+        assertEquals(verifyString.getClass(), pdcString.getParameterTypeClass());
+
+        ParameterDescriptionComposite pdcInteger = new ParameterDescriptionComposite();
+        pdcInteger.setParameterType("java.lang.Integer[][][][]");
+        Integer[][][][] verifyInteger = new Integer[5][1][3][12];
+        assertEquals(verifyInteger.getClass(), pdcInteger.getParameterTypeClass());
+    }
+    
+    public void testMyObjectArray() {
+        ParameterDescriptionComposite pdc = new ParameterDescriptionComposite();
+        pdc.setParameterType("org.apache.axis2.jaxws.description.builder.MyObject[][]");
+        MyObject[][] myObject = new MyObject[2][3];
+        assertEquals(myObject.getClass(), pdc.getParameterTypeClass());
+    }
+    
+    public void testHolderOfPrimitiveArray() {
+        ParameterDescriptionComposite pdc = new ParameterDescriptionComposite();
+        pdc.setParameterType("javax.xml.ws.Holder<byte[]>");
+        assertEquals("javax.xml.ws.Holder<byte[]>", pdc.getParameterType());
         
+        assertEquals(Holder.class, pdc.getParameterTypeClass());
+        byte [] validateByteArray = new byte[10];
+        assertEquals(validateByteArray.getClass(), pdc.getHolderActualTypeClass());
+    }
+    
+    public void testHolderOfMyObjectArray() {
+        ParameterDescriptionComposite pdc = new ParameterDescriptionComposite();
+        pdc.setParameterType("javax.xml.ws.Holder<org.apache.axis2.jaxws.description.builder.MyObject[][]>");
+        assertEquals("javax.xml.ws.Holder<org.apache.axis2.jaxws.description.builder.MyObject[][]>", pdc.getParameterType());
+        
+        assertEquals(Holder.class, pdc.getParameterTypeClass());
+        MyObject[][] validateMyObject = new MyObject[5][10];
+        assertEquals(validateMyObject.getClass(), pdc.getHolderActualTypeClass());
     }
 }
+
+class MyObject {
+    
+}
\ No newline at end of file

Modified: webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/framework/JAXWSTest.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/framework/JAXWSTest.java?view=diff&rev=488478&r1=488477&r2=488478
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/framework/JAXWSTest.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/framework/JAXWSTest.java Mon Dec 18 17:13:33 2006
@@ -42,7 +42,7 @@
 import org.apache.axis2.jaxws.description.WSDLTests;
 import org.apache.axis2.jaxws.description.WrapperPackageTests;
 import org.apache.axis2.jaxws.description.builder.DescriptionBuilderTests;
-import org.apache.axis2.jaxws.description.builder.GenericsParsingTests;
+import org.apache.axis2.jaxws.description.builder.ParameterParsingTests;
 import org.apache.axis2.jaxws.description.impl.ServiceDescriptionImplTests;
 import org.apache.axis2.jaxws.dispatch.DispatchTestSuite;
 import org.apache.axis2.jaxws.dispatch.SOAP12Dispatch;
@@ -116,7 +116,7 @@
         suite.addTestSuite(ServiceAnnotationTests.class);
         suite.addTestSuite(WSDLTests.class);
         suite.addTestSuite(DescriptionBuilderTests.class);
-        suite.addTestSuite(GenericsParsingTests.class);
+        suite.addTestSuite(ParameterParsingTests.class);
         suite.addTestSuite(ServiceDescriptionImplTests.class);
         suite.addTestSuite(WSDLDescriptionTests.class);
         suite.addTestSuite(AnnotationDescriptionTests.class);



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