cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r807295 - in /cxf/trunk/rt/frontend/jaxrs/src: main/java/org/apache/cxf/jaxrs/model/wadl/ main/java/org/apache/cxf/jaxrs/utils/ test/java/org/apache/cxf/jaxrs/model/wadl/ test/java/org/apache/cxf/jaxrs/utils/
Date Mon, 24 Aug 2009 16:22:57 GMT
Author: sergeyb
Date: Mon Aug 24 16:22:56 2009
New Revision: 807295

URL: http://svn.apache.org/viewvc?rev=807295&view=rev
Log:
JAXRS : updating ResourceUtils to collect all the available resource classes

Modified:
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/wadl/WadlGenerator.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/ResourceUtils.java
    cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/WadlGeneratorTest.java
    cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/ResourceUtilsTest.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=807295&r1=807294&r2=807295&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
Mon Aug 24 16:22:56 2009
@@ -338,9 +338,7 @@
                     sb.append("<!-- Primitive type : " + value + " -->");
                 }
                 sb.append("<representation");
-                if (!mt.isWildcardType()) {
-                    sb.append(" mediaType=\"").append(mt.toString()).append("\"");
-                }
+                sb.append(" mediaType=\"").append(mt.toString()).append("\"");
                 if (jaxbProxy != null && mt.getSubtype().contains("xml") &&
jaxbTypes.contains(type)) {
                     generateQName(sb, jaxbProxy, clsMap, type);
                 }

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/ResourceUtils.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/ResourceUtils.java?rev=807295&r1=807294&r2=807295&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/ResourceUtils.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/ResourceUtils.java
Mon Aug 24 16:22:56 2009
@@ -400,33 +400,43 @@
     public static Map<Class<?>, Type> getAllRequestResponseTypes(List<ClassResourceInfo>
cris, 
                                                                  boolean jaxbOnly) {
         Map<Class<?>, Type> types = new HashMap<Class<?>, Type>();
-        for (ClassResourceInfo root : cris) {
-            for (OperationResourceInfo ori : root.getMethodDispatcher().getOperationResourceInfos())
{
-                Class<?> cls = ori.getMethodToInvoke().getReturnType();
-                Type type = ori.getMethodToInvoke().getGenericReturnType();
-                if (jaxbOnly) {
-                    checkJaxbType(cls, types);
-                } else {
-                    types.put(cls, type);
-                }
-                for (Parameter pm : ori.getParameters()) {
-                    if (pm.getType() == ParameterType.REQUEST_BODY) {
-                        Class<?> inType = ori.getMethodToInvoke().getParameterTypes()[pm.getIndex()];
-                        Type type2 = ori.getMethodToInvoke().getGenericParameterTypes()[pm.getIndex()];
-                        if (jaxbOnly) {
-                            checkJaxbType(inType, types);
-                        } else {
-                            types.put(inType, type2);
-                        }
+        for (ClassResourceInfo resource : cris) {
+            getAllTypesForResource(resource, types, jaxbOnly);
+        }
+        return types;
+    }
+
+    private static void getAllTypesForResource(ClassResourceInfo resource, Map<Class<?>,
Type> types,
+                                               boolean jaxbOnly) {
+        for (OperationResourceInfo ori : resource.getMethodDispatcher().getOperationResourceInfos())
{
+            Class<?> cls = ori.getMethodToInvoke().getReturnType();
+            Type type = ori.getMethodToInvoke().getGenericReturnType();
+            if (jaxbOnly) {
+                checkJaxbType(cls, types);
+            } else {
+                types.put(cls, type);
+            }
+            for (Parameter pm : ori.getParameters()) {
+                if (pm.getType() == ParameterType.REQUEST_BODY) {
+                    Class<?> inType = ori.getMethodToInvoke().getParameterTypes()[pm.getIndex()];
+                    Type type2 = ori.getMethodToInvoke().getGenericParameterTypes()[pm.getIndex()];
+                    if (jaxbOnly) {
+                        checkJaxbType(inType, types);
+                    } else {
+                        types.put(inType, type2);
                     }
                 }
-                
             }
+            
         }
         
-        return types;
+        for (ClassResourceInfo sub : resource.getSubResources()) {
+            if (sub != resource) {
+                getAllTypesForResource(sub, types, jaxbOnly);
+            }
+        }
     }
-
+    
     private static void checkJaxbType(Class<?> type, Map<Class<?>, Type>
types) {
         JAXBElementProvider provider = new JAXBElementProvider();
         if (!InjectionUtils.isPrimitive(type) 

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=807295&r1=807294&r2=807295&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
Mon Aug 24 16:22:56 2009
@@ -18,8 +18,6 @@
  */
 package org.apache.cxf.jaxrs.model.wadl;
 
-import java.io.File;
-import java.io.FileOutputStream;
 import java.io.StringReader;
 import java.util.ArrayList;
 import java.util.List;
@@ -84,14 +82,14 @@
         assertNotNull(r);
         assertEquals(WadlGenerator.WADL_TYPE.toString(),
                      r.getMetadata().getFirst(HttpHeaders.CONTENT_TYPE));
-        File f = new File("test.xml");
-        f.delete();
-        f.createNewFile();
-        System.out.println(f.getAbsolutePath());
-        FileOutputStream fos = new FileOutputStream(f);
-        fos.write(r.getEntity().toString().getBytes());
-        fos.flush();
-        fos.close();
+//        File f = new File("test.xml");
+//        f.delete();
+//        f.createNewFile();
+//        System.out.println(f.getAbsolutePath());
+//        FileOutputStream fos = new FileOutputStream(f);
+//        fos.write(r.getEntity().toString().getBytes());
+//        fos.flush();
+//        fos.close();
     }
     
     @Test

Modified: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/ResourceUtilsTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/ResourceUtilsTest.java?rev=807295&r1=807294&r2=807295&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/ResourceUtilsTest.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/ResourceUtilsTest.java
Mon Aug 24 16:22:56 2009
@@ -20,6 +20,7 @@
 
 import java.lang.reflect.Constructor;
 import java.lang.reflect.Method;
+import java.lang.reflect.Type;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.List;
@@ -34,6 +35,9 @@
 import org.apache.cxf.jaxrs.model.ParameterType;
 import org.apache.cxf.jaxrs.model.UserOperation;
 import org.apache.cxf.jaxrs.model.UserResource;
+import org.apache.cxf.jaxrs.resources.Book;
+import org.apache.cxf.jaxrs.resources.BookInterface;
+import org.apache.cxf.jaxrs.resources.Chapter;
 
 import org.junit.Assert;
 import org.junit.Test;
@@ -77,4 +81,14 @@
         assertEquals("id", p.getName());
     }
     
+    @Test
+    public void testGetAllJaxbClasses() {
+        ClassResourceInfo cri1 = 
+            ResourceUtils.createClassResourceInfo(BookInterface.class, BookInterface.class,
true, true);
+        Map<Class<?>, Type> types = 
+            ResourceUtils.getAllRequestResponseTypes(Collections.singletonList(cri1), true);
+        assertEquals(2, types.size());
+        assertTrue(types.containsKey(Book.class));
+        assertTrue(types.containsKey(Chapter.class));
+    }
 }



Mime
View raw message