cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1177631 - in /cxf/trunk: rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/codegen/SourceGenerator.java tools/wadlto/jaxrs/src/test/resources/wadl/bookstore.xml
Date Fri, 30 Sep 2011 12:36:47 GMT
Author: sergeyb
Date: Fri Sep 30 12:36:47 2011
New Revision: 1177631

URL: http://svn.apache.org/viewvc?rev=1177631&view=rev
Log:
[CXF-3797] Better support for optional or repeating query parametets, thanks to Christos Fragoulides

Modified:
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/codegen/SourceGenerator.java
    cxf/trunk/tools/wadlto/jaxrs/src/test/resources/wadl/bookstore.xml

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/codegen/SourceGenerator.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/codegen/SourceGenerator.java?rev=1177631&r1=1177630&r2=1177631&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/codegen/SourceGenerator.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/codegen/SourceGenerator.java
Fri Sep 30 12:36:47 2011
@@ -106,6 +106,7 @@ public class SourceGenerator {
     private static final Map<String, Class<?>> HTTP_METHOD_ANNOTATIONS;
     private static final Map<String, Class<?>> PARAM_ANNOTATIONS;
     private static final Set<String> RESOURCE_LEVEL_PARAMS;
+    private static final Map<String, String> AUTOBOXED_PRIMITIVES_MAP;
     
     static {
         HTTP_METHOD_ANNOTATIONS = new HashMap<String, Class<?>>();
@@ -125,6 +126,15 @@ public class SourceGenerator {
         RESOURCE_LEVEL_PARAMS = new HashSet<String>();
         RESOURCE_LEVEL_PARAMS.add("template");
         RESOURCE_LEVEL_PARAMS.add("matrix");
+        
+        AUTOBOXED_PRIMITIVES_MAP = new HashMap<String, String>();
+        AUTOBOXED_PRIMITIVES_MAP.put(byte.class.getSimpleName(), Byte.class.getSimpleName());
+        AUTOBOXED_PRIMITIVES_MAP.put(short.class.getSimpleName(), Short.class.getSimpleName());
+        AUTOBOXED_PRIMITIVES_MAP.put(int.class.getSimpleName(), Integer.class.getSimpleName());
+        AUTOBOXED_PRIMITIVES_MAP.put(long.class.getSimpleName(), Long.class.getSimpleName());
+        AUTOBOXED_PRIMITIVES_MAP.put(float.class.getSimpleName(), Float.class.getSimpleName());
+        AUTOBOXED_PRIMITIVES_MAP.put(double.class.getSimpleName(), Double.class.getSimpleName());
+        AUTOBOXED_PRIMITIVES_MAP.put(boolean.class.getSimpleName(), Boolean.class.getSimpleName());
     }
 
     private Comparator<String> importsComparator;
@@ -719,8 +729,14 @@ public class SourceGenerator {
                 writeAnnotation(sbCode, imports, paramAnn, name, false, false);
                 sbCode.append(" ");
             }
+            boolean isRepeating = Boolean.valueOf(paramEl.getAttribute("repeating"));
             String type = getPrimitiveType(paramEl);
-            if (Boolean.valueOf(paramEl.getAttribute("repeating"))) {
+            if (paramAnn == QueryParam.class
+                && (isRepeating || !Boolean.valueOf(paramEl.getAttribute("required")))
   
+                && AUTOBOXED_PRIMITIVES_MAP.containsKey(type)) {
+                type = AUTOBOXED_PRIMITIVES_MAP.get(type);
+            }
+            if (isRepeating) {
                 addImport(imports, List.class.getName());
                 type = "List<" + type + ">";
             }

Modified: cxf/trunk/tools/wadlto/jaxrs/src/test/resources/wadl/bookstore.xml
URL: http://svn.apache.org/viewvc/cxf/trunk/tools/wadlto/jaxrs/src/test/resources/wadl/bookstore.xml?rev=1177631&r1=1177630&r2=1177631&view=diff
==============================================================================
--- cxf/trunk/tools/wadlto/jaxrs/src/test/resources/wadl/bookstore.xml (original)
+++ cxf/trunk/tools/wadlto/jaxrs/src/test/resources/wadl/bookstore.xml Fri Sep 30 12:36:47
2011
@@ -97,9 +97,9 @@
        <param name="hid" style="header" type="xs:int">
         <doc>header param</doc>
        </param>
-       <param name="provider.bar" style="query" type="xs:int"/>
+       <param name="provider.bar" style="query" required="true" type="xs:int"/>
        <param name="a" style="query" repeating="true" type="xs:string"/>
-
+       <param name="b" style="query" repeating="true" type="xs:long"/> 
        <representation mediaType="application/xml" element="prefix1:theBook2">
         <doc>InputBook</doc>
        </representation>



Mime
View raw message