cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r795106 - in /cxf/branches/2.2.x-fixes: ./ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/wadl/ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/ rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/
Date Fri, 17 Jul 2009 14:50:37 GMT
Author: sergeyb
Date: Fri Jul 17 14:50:37 2009
New Revision: 795106

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

........
  r795104 | sergeyb | 2009-07-17 15:41:42 +0100 (Fri, 17 Jul 2009) | 1 line
  
  JAX-RS : minor WADL gen updates (handling recursive subresources and parameter beans)
........

Modified:
    cxf/branches/2.2.x-fixes/   (props changed)
    cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/wadl/WadlGenerator.java
    cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java
    cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/BookStore.java
    cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/WadlGeneratorTest.java

Propchange: cxf/branches/2.2.x-fixes/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Fri Jul 17 14:50:37 2009
@@ -1 +1 @@
-/cxf/trunk:782728-782730,783097,783294,783396,784059,784181-784184,784893,784895,785279-785282,785468,785621,785624,785651,785734,785866,786142,786271-786272,786395,786512,786514,786582-786583,786638,786647,786850,787200,787269,787277-787279,787290-787291,787305,787323,787366,787849,788030,788060,788187,788444,788451,788703,788752,788774,788819-788820,789013,789371,789387,789420,789527-789530,789704-789705,789788,789811,789896-789901,790074,790094,790134,790188,790294,790553,790637-790644,790868,791301,791354,791538,791753,791947,792007,792096,792183,792261-792265,792271,792604,792683-792685,792975,792985,793059,793570,794297,794396,794680,794728,794771,794778-794780,795044
+/cxf/trunk:782728-782730,783097,783294,783396,784059,784181-784184,784893,784895,785279-785282,785468,785621,785624,785651,785734,785866,786142,786271-786272,786395,786512,786514,786582-786583,786638,786647,786850,787200,787269,787277-787279,787290-787291,787305,787323,787366,787849,788030,788060,788187,788444,788451,788703,788752,788774,788819-788820,789013,789371,789387,789420,789527-789530,789704-789705,789788,789811,789896-789901,790074,790094,790134,790188,790294,790553,790637-790644,790868,791301,791354,791538,791753,791947,792007,792096,792183,792261-792265,792271,792604,792683-792685,792975,792985,793059,793570,794297,794396,794680,794728,794771,794778-794780,795044,795104

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

Modified: cxf/branches/2.2.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.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/wadl/WadlGenerator.java?rev=795106&r1=795105&r2=795106&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/wadl/WadlGenerator.java
(original)
+++ cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/wadl/WadlGenerator.java
Fri Jul 17 14:50:37 2009
@@ -119,10 +119,10 @@
             proxy = ReflectionInvokationHandler.createProxyWrapper(context, JAXBContextProxy.class);
         }
         Map<Class<?>, QName> clsMap = new IdentityHashMap<Class<?>,
QName>();
-        
+        Set<ClassResourceInfo> visitedResources = new HashSet<ClassResourceInfo>();
         for (ClassResourceInfo cri : cris) {
             handleResource(sbResources, jaxbTypes, proxy, clsMap,
-                           cri, cri.getURITemplate().getValue());
+                           cri, cri.getURITemplate().getValue(), visitedResources);
         }
         sbResources.append("</resources>");
         
@@ -170,7 +170,9 @@
     }
     
     private void handleResource(StringBuilder sb, Set<Class<?>> jaxbTypes, JAXBContextProxy
jaxbProxy,
-                                Map<Class<?>, QName> clsMap, ClassResourceInfo
cri, String path) {
+                                Map<Class<?>, QName> clsMap, ClassResourceInfo
cri, String path,
+                                Set<ClassResourceInfo> visitedResources) {
+        visitedResources.add(cri);
         sb.append("<resource path=\"").append(path).append("\">");
         
         List<OperationResourceInfo> sortedOps = sortOperationsByPath(
@@ -181,11 +183,11 @@
             if (ori.getHttpMethod() == null) {
                 Class<?> cls = ori.getMethodToInvoke().getReturnType();
                 ClassResourceInfo subcri = cri.findResource(cls, cls);
-                if (subcri != null) {
+                if (subcri != null && !visitedResources.contains(subcri)) {
                     handleResource(sb, jaxbTypes, jaxbProxy, clsMap, subcri, 
-                                   ori.getURITemplate().getValue());
+                                   ori.getURITemplate().getValue(), visitedResources);
                 } else {
-                    handleDynamicSubresource(sb, jaxbTypes, jaxbProxy, clsMap, ori);
+                    handleDynamicSubresource(sb, jaxbTypes, jaxbProxy, clsMap, ori, subcri);
                 }
                 continue;
             }
@@ -249,9 +251,14 @@
     }
     
     private void handleDynamicSubresource(StringBuilder sb, Set<Class<?>> jaxbTypes,

-                 JAXBContextProxy jaxbProxy, Map<Class<?>, QName> clsMap, OperationResourceInfo
ori) {
+                 JAXBContextProxy jaxbProxy, Map<Class<?>, QName> clsMap, OperationResourceInfo
ori,
+                 ClassResourceInfo subcri) {
         
-        sb.append("<!-- Dynamic subresource -->");
+        if (subcri != null) {
+            sb.append("<!-- Recursive subresource -->");
+        } else {
+            sb.append("<!-- Dynamic subresource -->");    
+        }
         sb.append("<resource path=\"").append(ori.getURITemplate().getValue()).append("\">");
         if (ori.getMethodToInvoke().getParameterTypes().length != 0) {
             sb.append("<request>");
@@ -289,6 +296,19 @@
     }
     
     private void writeParam(StringBuilder sb, Parameter pm, OperationResourceInfo ori) {
+        Class<?> type = ori.getMethodToInvoke().getParameterTypes()[pm.getIndex()];
+        if (!"".equals(pm.getName())) {
+            doWriteParam(sb, pm, type);
+        } else {
+            Map<Parameter, Class<?>> pms = InjectionUtils.getParametersFromBeanClass(type,
pm.getType());
+            for (Map.Entry<Parameter, Class<?>> entry : pms.entrySet()) {   
+                doWriteParam(sb, entry.getKey(), entry.getValue());
+            }
+        }
+    }
+    
+    private void doWriteParam(StringBuilder sb, Parameter pm, Class<?> type) {
+        
         sb.append("<param name=\"").append(pm.getName()).append("\" ");
         String style = ParameterType.PATH == pm.getType() ? "template" 
                        : ParameterType.FORM == pm.getType() ? "query"
@@ -297,7 +317,6 @@
         if (pm.getDefaultValue() != null) {
             sb.append(" default=\"").append(pm.getDefaultValue()).append("\"");
         }
-        Class<?> type = ori.getMethodToInvoke().getParameterTypes()[pm.getIndex()];
         String value = XmlSchemaPrimitiveUtils.getSchemaRepresentation(type);
         if (value != null) {
             sb.append(" type=\"").append(value).append("\"");

Modified: cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java?rev=795106&r1=795105&r2=795106&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java
(original)
+++ cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java
Fri Jul 17 14:50:37 2009
@@ -37,6 +37,7 @@
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.HashSet;
+import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.ResourceBundle;
@@ -82,6 +83,7 @@
 import org.apache.cxf.jaxrs.impl.tl.ThreadLocalServletContext;
 import org.apache.cxf.jaxrs.impl.tl.ThreadLocalUriInfo;
 import org.apache.cxf.jaxrs.model.AbstractResourceInfo;
+import org.apache.cxf.jaxrs.model.Parameter;
 import org.apache.cxf.jaxrs.model.ParameterType;
 import org.apache.cxf.jaxrs.provider.ProviderFactory;
 import org.apache.cxf.message.Message;
@@ -809,6 +811,23 @@
         }
     }
     
+    public static Map<Parameter, Class<?>> getParametersFromBeanClass(Class<?>
beanClass, 
+                                                                      ParameterType type)
{
+        Map<Parameter, Class<?>> params = new LinkedHashMap<Parameter, Class<?>>();
+        for (Method m : beanClass.getMethods()) {
+            if (m.getName().startsWith("get") && m.getParameterTypes().length ==
0 
+                && m.getName().length() > 3) {
+                String propertyName = m.getName().substring(3).toLowerCase();
+                if ("class".equals(propertyName)) {
+                    continue;
+                }
+                params.put(new Parameter(type, propertyName), m.getReturnType());
+            }
+        }
+        return params;
+    }
+    
+    
     public static boolean isPrimitive(Class<?> type) {
         return type.isPrimitive() 
             || Number.class.isAssignableFrom(type)

Modified: cxf/branches/2.2.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.2.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/BookStore.java?rev=795106&r1=795105&r2=795106&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/BookStore.java
(original)
+++ cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/BookStore.java
Fri Jul 17 14:50:37 2009
@@ -27,6 +27,7 @@
 import javax.ws.rs.Path;
 import javax.ws.rs.PathParam;
 import javax.ws.rs.Produces;
+import javax.ws.rs.QueryParam;
 import javax.ws.rs.core.Context;
 import javax.ws.rs.core.HttpHeaders;
 
@@ -37,7 +38,7 @@
 
     @GET 
     @Produces("text/plain")
-    public String getName(@PathParam("id") Long id) {
+    public String getName(@PathParam("id") Long id, @QueryParam("") QueryBean query) {
         return "store";
     }
     
@@ -64,4 +65,21 @@
         return new Chapter(1);
     }
     
+    @Path("itself")
+    public BookStore getItself() {
+        return this;
+    }
+    
+    public static class QueryBean {
+        private int a;
+        private int b;
+        
+        public int getA() {
+            return a;
+        }
+        
+        public int getB() {
+            return b;
+        }
+    }
 }

Modified: cxf/branches/2.2.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.2.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/WadlGeneratorTest.java?rev=795106&r1=795105&r2=795106&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/WadlGeneratorTest.java
(original)
+++ cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/WadlGeneratorTest.java
Fri Jul 17 14:50:37 2009
@@ -132,20 +132,36 @@
         
         List<Element> resourceEls = DOMUtils.getChildrenWithName(resource, 
                                          WadlGenerator.WADL_NS, "resource");
-        assertEquals(4, resourceEls.size());        
+        assertEquals(5, resourceEls.size());        
         assertEquals("/", resourceEls.get(0).getAttribute("path"));
         assertEquals("/books/{bookid}", resourceEls.get(1).getAttribute("path"));
         assertEquals("/chapter", resourceEls.get(2).getAttribute("path"));
         assertEquals("/booksubresource", resourceEls.get(3).getAttribute("path"));
+        assertEquals("/itself", resourceEls.get(4).getAttribute("path"));
         
         
         List<Element> methodEls = DOMUtils.getChildrenWithName(resourceEls.get(0),

                                                                WadlGenerator.WADL_NS, "method");
+        
         assertEquals(1, methodEls.size());
         assertEquals("GET", methodEls.get(0).getAttribute("name"));
-                                                           
         
-        List<Element> paramsEls = DOMUtils.getChildrenWithName(resourceEls.get(1),

+        List<Element> paramsEls = DOMUtils.getChildrenWithName(resourceEls.get(0),

+                                                               WadlGenerator.WADL_NS, "param");
+        assertEquals(1, paramsEls.size());
+        checkParameter(paramsEls.get(0), "id", "template");
+        
+        List<Element> requestEls = DOMUtils.getChildrenWithName(methodEls.get(0), 
+                                                               WadlGenerator.WADL_NS, "request");
+        assertEquals(1, requestEls.size());
+        
+        paramsEls = DOMUtils.getChildrenWithName(requestEls.get(0), 
+                                                 WadlGenerator.WADL_NS, "param");
+        assertEquals(2, paramsEls.size());
+        checkParameter(paramsEls.get(0), "a", "query");
+        checkParameter(paramsEls.get(1), "b", "query");
+        
+        paramsEls = DOMUtils.getChildrenWithName(resourceEls.get(1), 
                                                                WadlGenerator.WADL_NS, "param");
         assertEquals(3, paramsEls.size());
         checkParameter(paramsEls.get(0), "id", "template");
@@ -157,7 +173,7 @@
         assertEquals(1, methodEls.size());
         assertEquals("POST", methodEls.get(0).getAttribute("name"));
         
-        List<Element> requestEls = DOMUtils.getChildrenWithName(methodEls.get(0), 
+        requestEls = DOMUtils.getChildrenWithName(methodEls.get(0), 
                                                                 WadlGenerator.WADL_NS, "request");
         assertEquals(1, requestEls.size());
         List<Element> repEls = DOMUtils.getChildrenWithName(requestEls.get(0), 



Mime
View raw message