[jbossws-commits] JBossWS SVN: r7744 - in stack/native/branches/jbossws-native-2.0.1.SP2_CP01_JBPAPP-929/src: test/java/org/jboss/test/ws/jaxws/xop and 1 other directory.

jbossws-commits at lists.jboss.org jbossws-commits at lists.jboss.org
Thu Jun 26 12:39:48 EDT 2008


Author: darran.lofthouse at jboss.com
Date: 2008-06-26 12:39:48 -0400 (Thu, 26 Jun 2008)
New Revision: 7744

Modified:
   stack/native/branches/jbossws-native-2.0.1.SP2_CP01_JBPAPP-929/src/main/java/org/jboss/ws/extensions/xop/jaxws/ReflectiveAttachmentRefScanner.java
   stack/native/branches/jbossws-native-2.0.1.SP2_CP01_JBPAPP-929/src/test/java/org/jboss/test/ws/jaxws/xop/MimeDeclarationTestCase.java
Log:
[JBPAPP-929] Attachment support for JAX-WS collections.

Modified: stack/native/branches/jbossws-native-2.0.1.SP2_CP01_JBPAPP-929/src/main/java/org/jboss/ws/extensions/xop/jaxws/ReflectiveAttachmentRefScanner.java
===================================================================
--- stack/native/branches/jbossws-native-2.0.1.SP2_CP01_JBPAPP-929/src/main/java/org/jboss/ws/extensions/xop/jaxws/ReflectiveAttachmentRefScanner.java	2008-06-26 16:37:32 UTC (rev 7743)
+++ stack/native/branches/jbossws-native-2.0.1.SP2_CP01_JBPAPP-929/src/main/java/org/jboss/ws/extensions/xop/jaxws/ReflectiveAttachmentRefScanner.java	2008-06-26 16:39:48 UTC (rev 7744)
@@ -30,6 +30,8 @@
 import java.awt.*;
 import java.lang.reflect.Field;
 import java.lang.reflect.Method;
+import java.lang.reflect.ParameterizedType;
+import java.lang.reflect.Type;
 import java.lang.annotation.Annotation;
 import java.util.ArrayList;
 import java.util.List;
@@ -82,7 +84,9 @@
          Class<?> type = field.getType();
 
          boolean exceptionToTheRule = isAttachmentDataType(type);
-
+         if (! exceptionToTheRule) {
+            type = getFieldComponentType(field);
+         }
          // only non JDK types are inspected except for byte[] and java.lang.String
          if( !alreadyScanned(field) && (exceptionToTheRule || !isJDKType(type)) )
          {
@@ -218,6 +222,31 @@
       scannedFields.clear();
    }
 
+   /**
+    * In the case of an array T[] or a List<T> returns T, else returns the field type
+    *
+    * @param clazz
+    * @return the type of the field, if the field is an array returns the component type,
+    * if the field is declared as List<T> returns T
+    */
+   private Class<?> getFieldComponentType(Field field) {
+	   Class<?> fieldType = field.getType();
+	   if (fieldType.isArray()) {
+		   return fieldType.getComponentType();
+	   } else if (List.class.isAssignableFrom(fieldType)) {
+		   if (field.getGenericType() instanceof ParameterizedType) {
+		   		ParameterizedType paramType = (ParameterizedType) field.getGenericType();
+		   		if ((paramType.getRawType() instanceof Class) && List.class.isAssignableFrom((Class<?>) paramType.getRawType())) {
+		   			Type[] actualTypes = paramType.getActualTypeArguments();
+		   			if (actualTypes.length == 1 && (actualTypes[0] instanceof Class)) {
+		   				return (Class<?>) actualTypes[0];
+		   			}
+		   		}
+		   }
+	   }
+	   return fieldType;
+   }
+
    private static boolean isAttachmentDataType(Class clazz) {
       for(Class cl : SUPPORTED_TYPES)
       {

Modified: stack/native/branches/jbossws-native-2.0.1.SP2_CP01_JBPAPP-929/src/test/java/org/jboss/test/ws/jaxws/xop/MimeDeclarationTestCase.java
===================================================================
--- stack/native/branches/jbossws-native-2.0.1.SP2_CP01_JBPAPP-929/src/test/java/org/jboss/test/ws/jaxws/xop/MimeDeclarationTestCase.java	2008-06-26 16:37:32 UTC (rev 7743)
+++ stack/native/branches/jbossws-native-2.0.1.SP2_CP01_JBPAPP-929/src/test/java/org/jboss/test/ws/jaxws/xop/MimeDeclarationTestCase.java	2008-06-26 16:39:48 UTC (rev 7744)
@@ -29,8 +29,10 @@
 import org.jboss.ws.extensions.xop.jaxws.AttachmentScanResult;
 
 import javax.xml.bind.annotation.XmlMimeType;
-import java.awt.*;
+
+import java.awt.Image;
 import java.lang.reflect.Method;
+import java.util.List;
 
 /**
  * Test the ReflectiveXOPScanner.
@@ -107,6 +109,20 @@
       assertFalse("MTOM should be disabled", XOPContext.isMTOMEnabled());
    }
 
+   public void testNestedArray() throws Exception
+   {
+      AttachmentScanResult  mimeType = SCANNER.scanBean(NestedArray.class);
+      assertNotNull("Unable to find xop declaration", mimeType);
+      assertEquals("text/plain", mimeType.getMimeType());
+   }
+
+   public void testNestedList() throws Exception
+   {
+      AttachmentScanResult  mimeType = SCANNER.scanBean(NestedList.class);
+      assertNotNull("Unable to find xop declaration", mimeType);
+      assertEquals("text/plain", mimeType.getMimeType());
+   }
+
    class FieldAnnotation
    {
       @XmlMimeType("text/xml")
@@ -157,4 +173,12 @@
       @XmlMimeType("text/plain")
       String data;
    }
+
+   class NestedArray {
+      Nested[] nested;
+   }
+
+   class NestedList {
+      List<Nested> nested;
+   }
 }




More information about the jbossws-commits mailing list