cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1163598 - in /cxf/branches/2.4.x-fixes: ./ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/wadl/ rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/
Date Wed, 31 Aug 2011 12:13:28 GMT
Author: sergeyb
Date: Wed Aug 31 12:13:27 2011
New Revision: 1163598

URL: http://svn.apache.org/viewvc?rev=1163598&view=rev
Log:
Merged revisions 1163593 via svnmerge from 
https://svn.apache.org/repos/asf/cxf/trunk

........
  r1163593 | sergeyb | 2011-08-31 13:08:14 +0100 (Wed, 31 Aug 2011) | 1 line
  
  [CXF-3770] Support for param options
........

Added:
    cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/BookEnum.java
      - copied unchanged from r1163593, cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/BookEnum.java
Modified:
    cxf/branches/2.4.x-fixes/   (props changed)
    cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/wadl/WadlGenerator.java
    cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/BookStore.java
    cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/WadlGeneratorTest.java

Propchange: cxf/branches/2.4.x-fixes/
------------------------------------------------------------------------------
    svn:mergeinfo = /cxf/trunk:1163593

Propchange: cxf/branches/2.4.x-fixes/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.

Modified: cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/wadl/WadlGenerator.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/wadl/WadlGenerator.java?rev=1163598&r1=1163597&r2=1163598&view=diff
==============================================================================
--- cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/wadl/WadlGenerator.java
(original)
+++ cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/wadl/WadlGenerator.java
Wed Aug 31 12:13:27 2011
@@ -568,13 +568,39 @@ public class WadlGenerator implements Re
             type = InjectionUtils.getActualType(genericType);
             sb.append(" repeating=\"true\"");
         }
+        
         String value = XmlSchemaPrimitiveUtils.getSchemaRepresentation(type);
+        if (value == null && type.isEnum()) {
+            value = "xs:string";
+        }
         if (value != null) {
             sb.append(" type=\"").append(value).append("\"");
         }
-        addDocsAndCloseElement(sb, anns, "param", DocTarget.PARAM, true);
+        if (type.isEnum()) {
+            sb.append(">");
+            handleDocs(anns, sb, DocTarget.PARAM, true);
+            setEnumOptions(sb, type);
+            sb.append("</param>");
+        } else {
+            addDocsAndCloseElement(sb, anns, "param", DocTarget.PARAM, true);
+        }
     }
 
+    private void setEnumOptions(StringBuilder sb, Class<?> enumClass) {
+        try {
+            Method m = enumClass.getMethod("values", new Class[]{});
+            Object[] values = (Object[])m.invoke(null, new Object[]{});
+            m = enumClass.getMethod("toString", new Class[]{});
+            for (Object o : values) {
+                String str = (String)m.invoke(o, new Object[]{});
+                sb.append("<option value=\"" + str + "\"/>");
+            }
+            
+        } catch (Throwable ex) {
+            // ignore
+        }
+    }
+    
     private void addDocsAndCloseElement(StringBuilder sb, Annotation[] anns, String elementName,
                                         String category, boolean allowDefault) {
         if (isDocAvailable(anns)) {

Modified: cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/BookStore.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/BookStore.java?rev=1163598&r1=1163597&r2=1163598&view=diff
==============================================================================
--- cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/BookStore.java
(original)
+++ cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/BookStore.java
Wed Aug 31 12:13:27 2011
@@ -85,6 +85,7 @@ public class BookStore {
                         @HeaderParam("hid") int headerId,
                         @CookieParam("cid") int cookieId,
                         @QueryParam("provider.bar") int queryParam,
+                        @QueryParam("bookstate") BookEnum state,
                         @QueryParam("a") List<String> queryList,
                         @Context HttpHeaders headers,
                         @Description("InputBook")      

Modified: cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/WadlGeneratorTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/WadlGeneratorTest.java?rev=1163598&r1=1163597&r2=1163598&view=diff
==============================================================================
--- cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/WadlGeneratorTest.java
(original)
+++ cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/WadlGeneratorTest.java
Wed Aug 31 12:13:27 2011
@@ -20,8 +20,11 @@ package org.apache.cxf.jaxrs.model.wadl;
 
 import java.io.StringReader;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.Collections;
+import java.util.HashSet;
 import java.util.List;
+import java.util.Set;
 
 import javax.ws.rs.core.HttpHeaders;
 import javax.ws.rs.core.MediaType;
@@ -44,7 +47,6 @@ import org.apache.cxf.service.model.Endp
 import org.apache.cxf.transport.servlet.ServletDestination;
 import org.easymock.classextension.EasyMock;
 import org.easymock.classextension.IMocksControl;
-
 import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
@@ -403,9 +405,11 @@ public class WadlGeneratorTest extends A
         
         checkDocs(requestEls.get(0), "", "Request", "");
         
-        verifyParameters(requestEls.get(0), 3, 
+        verifyParameters(requestEls.get(0), 4, 
                          new Param("hid", "header", "xs:int"),
                          new Param("provider.bar", "query", "xs:int"),
+                         new Param("bookstate", "query", "xs:string",
+                                 new HashSet<String>(Arrays.asList("NEW", "USED", "OLD"))),
                          new Param("a", "query", "xs:string", true));
         
         verifyXmlJsonRepresentations(requestEls.get(0), book2El, "InputBook");
@@ -564,6 +568,17 @@ public class WadlGeneratorTest extends A
         assertEquals(p.getType(), paramEl.getAttribute("style"));
         assertEquals(p.getSchemaType(), paramEl.getAttribute("type"));
         assertEquals(p.isRepeating(), Boolean.valueOf(paramEl.getAttribute("repeating")));
+        Set<String> options = p.getOptions();
+        if (options != null) {
+            Set<String> actualOptions = new HashSet<String>();
+            List<Element> els = DOMUtils.getChildrenWithNamespace(paramEl, WadlGenerator.WADL_NS);
+            assertFalse(els.isEmpty());
+            assertEquals(options.size(), els.size());
+            for (Element op : els) {
+                actualOptions.add(op.getAttribute("value"));
+            }
+            assertEquals(options, actualOptions);
+        }
         String docs = p.getDocs();
         if (docs != null) {
             checkDocs(paramEl, "", docs, "");
@@ -614,10 +629,18 @@ public class WadlGeneratorTest extends A
         private String schemaType;
         private String docs;
         private boolean repeating;
+        private Set<String> options;
         public Param(String name, String type, String schemaType) {
             this(name, type, schemaType, false);
         }
         
+        public Param(String name, String type, String schemaType, Set<String> opts)
{
+            this.name = name;
+            this.type = type;
+            this.schemaType = schemaType;
+            this.options = opts;
+        }
+        
         public Param(String name, String type, String schemaType, boolean repeating) {
             this(name, type, schemaType, repeating, null);
         }
@@ -635,6 +658,10 @@ public class WadlGeneratorTest extends A
             this.repeating = repeating;
         }
         
+        public Set<String> getOptions() {
+            return options;
+        }
+        
         public String getName() {
             return name;
         }



Mime
View raw message