cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1187384 - in /cxf/branches/2.4.x-fixes: ./ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/codegen/ tools/wadlto/jaxrs/src/test/java/org/apache/cxf/tools/wadlto/jaxrs/ tools/wadlto/jaxrs/src/test/resources/wadl/
Date Fri, 21 Oct 2011 15:02:12 GMT
Author: sergeyb
Date: Fri Oct 21 15:02:11 2011
New Revision: 1187384

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

........
  r1187376 | sergeyb | 2011-10-21 15:46:10 +0100 (Fri, 21 Oct 2011) | 1 line
  
  [CXF-3854] Applying the patch with spme mofifications on behalf of Lars Weber, thanks
........

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/ext/codegen/SourceGenerator.java
    cxf/branches/2.4.x-fixes/tools/wadlto/jaxrs/src/test/java/org/apache/cxf/tools/wadlto/jaxrs/JAXRSContainerTest.java
    cxf/branches/2.4.x-fixes/tools/wadlto/jaxrs/src/test/resources/wadl/bookstoreImportResultType.xml

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

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/ext/codegen/SourceGenerator.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/codegen/SourceGenerator.java?rev=1187384&r1=1187383&r2=1187384&view=diff
==============================================================================
--- cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/codegen/SourceGenerator.java
(original)
+++ cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/codegen/SourceGenerator.java
Fri Oct 21 15:02:11 2011
@@ -247,23 +247,17 @@ public class SourceGenerator {
         
     }
     
-    //TODO: similar procedure should work for representation, method and param
-    // thus some of the code here will need to be moved into a sep function to be
-    // reused by relevant handlers
     private Element getResourceElement(Application app, Element resElement,
                                        GrammarInfo gInfo, Set<String> typeClassNames,
                                        String type, File srcDir) {
         if (type.length() > 0) {
             if (type.startsWith("#")) {
-                String refId = type.substring(1);
-                List<Element> resourceTypes = getWadlElements(app.getAppElement(),
"resource_type");
-                for (Element resourceType : resourceTypes) {
-                    if (refId.equals(resourceType.getAttribute("id"))) {
-                        Element realElement = (Element)resourceType.cloneNode(true);
-                        DOMUtils.setAttribute(realElement, "id", resElement.getAttribute("id"));
-                        DOMUtils.setAttribute(realElement, "path", resElement.getAttribute("path"));
-                        return realElement;
-                    }
+                Element resourceType = resolveLocalReference(app.getAppElement(), "resource_type",
type);
+                if (resourceType != null) {
+                    Element realElement = (Element)resourceType.cloneNode(true);
+                    DOMUtils.setAttribute(realElement, "id", resElement.getAttribute("id"));
+                    DOMUtils.setAttribute(realElement, "path", resElement.getAttribute("path"));
+                    return realElement;
                 }
             } else {
                 URI wadlRef = URI.create(type);
@@ -284,6 +278,27 @@ public class SourceGenerator {
         
     }
     
+    private Element getWadlElement(Element wadlEl) {
+        String href = wadlEl.getAttribute("href");
+        if (href.length() > 0 && href.startsWith("#")) {
+            return resolveLocalReference(wadlEl.getOwnerDocument().getDocumentElement(),

+                                         wadlEl.getLocalName(), href);
+        } else { 
+            return wadlEl;
+        }
+    }
+    
+    private Element resolveLocalReference(Element appEl, String elementName, String localRef)
{
+        String refId = localRef.substring(1);
+        List<Element> resourceTypes = getWadlElements(appEl, elementName);
+        for (Element resourceType : resourceTypes) {
+            if (refId.equals(resourceType.getAttribute("id"))) {
+                return resourceType;
+            }
+        }
+        return null;
+    }
+    
     private GrammarInfo getGrammarInfo(Application app, List<SchemaInfo> schemaElements)
{
         
         if (schemaElements == null || schemaElements.isEmpty()) {
@@ -339,8 +354,20 @@ public class SourceGenerator {
         String resourceId = resourceName != null 
             ? resourceName : rElement.getAttribute("id");
         if (resourceId.length() == 0) {
-            resourceId = DEFAULT_RESOURCE_NAME;
+            String path = rElement.getAttribute("path");
+            if (path.length() > 0) {
+                path = path.replaceAll("[\\{\\}_]*", "");
+                String[] split = path.split("/");
+                for (int i = 0; i < split.length; i++) {
+                    if (split[i].length() > 0) {
+                        resourceId += split[i].toUpperCase().charAt(0) + split[i].substring(1);
+                    }
+                }
+            } else {
+                resourceId = DEFAULT_RESOURCE_NAME;    
+            }
         }
+        
         boolean expandedQName = resourceId.startsWith("{") ? true : false;
         QName qname = convertToQName(resourceId, expandedQName);
         String namespaceURI = possiblyConvertNamespaceURI(qname.getNamespaceURI(), expandedQName);
@@ -825,9 +852,19 @@ public class SourceGenerator {
     }
     
     private List<Element> getWadlElements(Element parent, String name) {
-        return parent != null 
+        List<Element> elements = parent != null 
             ? DOMUtils.getChildrenWithName(parent, WadlGenerator.WADL_NS, name)
             : CastUtils.cast(Collections.emptyList(), Element.class);
+        if (!"resource".equals(name)) {    
+            for (int i = 0; i < elements.size(); i++) {
+                Element el = elements.get(i);
+                Element realEl = getWadlElement(el);
+                if (el != realEl) {
+                    elements.set(i, realEl);
+                }
+            }
+        }
+        return elements;
     }
     
     private String getPrimitiveType(Element paramEl) {

Modified: cxf/branches/2.4.x-fixes/tools/wadlto/jaxrs/src/test/java/org/apache/cxf/tools/wadlto/jaxrs/JAXRSContainerTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.4.x-fixes/tools/wadlto/jaxrs/src/test/java/org/apache/cxf/tools/wadlto/jaxrs/JAXRSContainerTest.java?rev=1187384&r1=1187383&r2=1187384&view=diff
==============================================================================
--- cxf/branches/2.4.x-fixes/tools/wadlto/jaxrs/src/test/java/org/apache/cxf/tools/wadlto/jaxrs/JAXRSContainerTest.java
(original)
+++ cxf/branches/2.4.x-fixes/tools/wadlto/jaxrs/src/test/java/org/apache/cxf/tools/wadlto/jaxrs/JAXRSContainerTest.java
Fri Oct 21 15:02:11 2011
@@ -186,7 +186,7 @@ public class JAXRSContainerTest extends 
             
             List<File> files = FileUtils.getFilesRecurse(output, ".+\\." + "class"
+ "$");
             assertEquals(4, files.size());
-            assertTrue(checkContains(files, "application" + ".Resource.class"));
+            assertTrue(checkContains(files, "application" + ".Bookstore.class"));
             assertTrue(checkContains(files, "superbooks" + ".Book.class"));
             assertTrue(checkContains(files, "superbooks" + ".ObjectFactory.class"));
             assertTrue(checkContains(files, "superbooks" + ".package-info.class"));
@@ -300,6 +300,35 @@ public class JAXRSContainerTest extends 
     }
     
     @Test    
+    public void testCodeGenNoIds2() {
+        try {
+            JAXRSContainer container = new JAXRSContainer(null);
+
+            ToolContext context = new ToolContext();
+            context.put(WadlToolConstants.CFG_OUTPUTDIR, output.getCanonicalPath());
+            context.put(WadlToolConstants.CFG_WADLURL, getLocation("/wadl/multipleResources.xml"));
+            context.put(WadlToolConstants.CFG_COMPILE, "true");
+            
+            container.setContext(context);
+            container.execute();
+
+            assertNotNull(output.list());
+            
+            List<File> javaFiles = FileUtils.getFilesRecurse(output, ".+\\." + "java"
+ "$");
+            assertEquals(2, javaFiles.size());
+            assertTrue(checkContains(javaFiles, "application.Bookstore.java"));
+            assertTrue(checkContains(javaFiles, "application.Books.java"));
+            List<File> classFiles = FileUtils.getFilesRecurse(output, ".+\\." + "class"
+ "$");
+            assertEquals(2, classFiles.size());
+            assertTrue(checkContains(classFiles, "application.Bookstore.class"));
+            assertTrue(checkContains(classFiles, "application.Books.class"));
+        } catch (Exception e) {
+            e.printStackTrace();
+            fail();
+        }
+    }
+    
+    @Test    
     public void testCodeGenWithResourceSet() {
         try {
             JAXRSContainer container = new JAXRSContainer(null);

Modified: cxf/branches/2.4.x-fixes/tools/wadlto/jaxrs/src/test/resources/wadl/bookstoreImportResultType.xml
URL: http://svn.apache.org/viewvc/cxf/branches/2.4.x-fixes/tools/wadlto/jaxrs/src/test/resources/wadl/bookstoreImportResultType.xml?rev=1187384&r1=1187383&r2=1187384&view=diff
==============================================================================
--- cxf/branches/2.4.x-fixes/tools/wadlto/jaxrs/src/test/resources/wadl/bookstoreImportResultType.xml
(original)
+++ cxf/branches/2.4.x-fixes/tools/wadlto/jaxrs/src/test/resources/wadl/bookstoreImportResultType.xml
Fri Oct 21 15:02:11 2011
@@ -23,15 +23,18 @@
     <include href="schemas/book.xsd"/>
  </grammars>
  
+ <method name="POST" id="addBook">
+      <request>
+       <representation mediaType="application/xml" element="prefix1:thebook"/>
+      </request>
+ </method>
+ 
  <resource_type id="main-resource">
     <resource path="/books/{bookid}">
      <param name="bookid" style="template" type="xs:int"/>
      
-     <method name="POST" id="addBook">
-      <request>
-       <representation mediaType="application/xml" element="prefix1:thebook"/>
-      </request>
-     </method>
+     <method href="#addBook"/>
+     
     </resource>
  </resource_type>
  



Mime
View raw message