cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1163593 - in /cxf/trunk/rt/frontend/jaxrs/src: main/java/org/apache/cxf/jaxrs/model/wadl/ test/java/org/apache/cxf/jaxrs/model/wadl/
Date Wed, 31 Aug 2011 12:08:15 GMT
Author: sergeyb
Date: Wed Aug 31 12:08:14 2011
New Revision: 1163593

URL: http://svn.apache.org/viewvc?rev=1163593&view=rev
Log:
[CXF-3770] Support for param options

Added:
    cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/BookEnum.java
  (with props)
Modified:
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/wadl/WadlGenerator.java
    cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/BookStore.java
    cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/WadlGeneratorTest.java

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/wadl/WadlGenerator.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/wadl/WadlGenerator.java?rev=1163593&r1=1163592&r2=1163593&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/wadl/WadlGenerator.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/wadl/WadlGenerator.java
Wed Aug 31 12:08:14 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)) {

Added: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/BookEnum.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/BookEnum.java?rev=1163593&view=auto
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/BookEnum.java
(added)
+++ cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/BookEnum.java
Wed Aug 31 12:08:14 2011
@@ -0,0 +1,25 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.cxf.jaxrs.model.wadl;
+
+public enum BookEnum {
+    NEW,
+    USED,
+    OLD
+}

Propchange: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/BookEnum.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/BookEnum.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/BookStore.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/BookStore.java?rev=1163593&r1=1163592&r2=1163593&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/BookStore.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/BookStore.java
Wed Aug 31 12:08:14 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/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/WadlGeneratorTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/WadlGeneratorTest.java?rev=1163593&r1=1163592&r2=1163593&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/WadlGeneratorTest.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/WadlGeneratorTest.java
Wed Aug 31 12:08:14 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