cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1124167 - in /cxf/trunk: rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/codegen/ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/wadl/ tools/wadlto/jaxrs/src/test/resources/wadl/
Date Wed, 18 May 2011 10:12:36 GMT
Author: sergeyb
Date: Wed May 18 10:12:36 2011
New Revision: 1124167

URL: http://svn.apache.org/viewvc?rev=1124167&view=rev
Log:
[CXF-3948] More consistent support for simple and extended QName resource ids

Modified:
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/codegen/CodeGeneratorProvider.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/codegen/SourceGenerator.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/wadl/WadlGenerator.java
    cxf/trunk/tools/wadlto/jaxrs/src/test/resources/wadl/bookstore.xml
    cxf/trunk/tools/wadlto/jaxrs/src/test/resources/wadl/bookstoreImport.xml
    cxf/trunk/tools/wadlto/jaxrs/src/test/resources/wadl/bookstoreImportCatalog.xml

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/codegen/CodeGeneratorProvider.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/codegen/CodeGeneratorProvider.java?rev=1124167&r1=1124166&r2=1124167&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/codegen/CodeGeneratorProvider.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/codegen/CodeGeneratorProvider.java
Wed May 18 10:12:36 2011
@@ -40,6 +40,7 @@ import javax.ws.rs.core.Response;
 import javax.ws.rs.core.UriBuilder;
 import javax.ws.rs.core.UriInfo;
 
+import org.apache.cxf.Bus;
 import org.apache.cxf.common.logging.LogUtils;
 import org.apache.cxf.helpers.FileUtils;
 import org.apache.cxf.helpers.IOUtils;
@@ -67,14 +68,20 @@ public class CodeGeneratorProvider imple
     
     private Comparator<String> importsComparator;
     private UriInfo ui;
+    private String resourcePackageName;
+    private String resourceName;
     private boolean generateInterfaces = true;
-    
+    private Bus bus;
     
     @Context
     public void setUriInfo(UriInfo uriInfo) {
         this.ui = uriInfo;
     }
     
+    public void setBus(Bus bus) {
+        this.bus = bus;
+    }
+    
     public Response handleRequest(Message m, ClassResourceInfo resourceClass) {
         
         if (!"GET".equals(m.get(Message.HTTP_REQUEST_METHOD))) {
@@ -126,6 +133,9 @@ public class CodeGeneratorProvider imple
                 SourceGenerator sg = new SourceGenerator(properties);
                 sg.setGenerateInterfaces(generateInterfaces);
                 sg.setImportsComparator(importsComparator);
+                sg.setResourceName(resourceName);
+                sg.setPackageName(resourcePackageName);
+                sg.setBus(bus);
                 sg.generateSource(wadl, srcDir, codeType);
                 
                 zipSource(srcDir, zipDir);
@@ -260,4 +270,11 @@ public class CodeGeneratorProvider imple
         this.generateInterfaces = generateInterfaces;
     }
     
+    public void setPackageName(String name) {
+        this.resourcePackageName = name;
+    }
+    
+    public void setResourceName(String name) {
+        this.resourceName = name;
+    }
 }

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/codegen/SourceGenerator.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/codegen/SourceGenerator.java?rev=1124167&r1=1124166&r2=1124167&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/codegen/SourceGenerator.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/codegen/SourceGenerator.java
Wed May 18 10:12:36 2011
@@ -253,14 +253,11 @@ public class SourceGenerator {
         if (resourceId.length() == 0) {
             resourceId = DEFAULT_RESOURCE_NAME;
         }
-        //TODO: if it's expanded QName then use PackageUtils.getPackageNameByNameSpaceURI
-        // otherwise assume the last segment after the last dot is the name of the class
-        // and the package name is before the last dot
-        QName qname = JAXRSUtils.convertStringToQName(resourceId);
-        String namespaceURI = qname.getNamespaceURI();
+        boolean expandedQName = resourceId.startsWith("{") ? true : false;
+        QName qname = convertToQName(resourceId, expandedQName);
+        String namespaceURI = possiblyConvertNamespaceURI(qname.getNamespaceURI(), expandedQName);
         
-        if (getSchemaClassName(PackageUtils.getPackageNameByNameSpaceURI(namespaceURI), 
-                               gInfo, qname.getLocalPart(), typeClassNames) != null) {
+        if (getSchemaClassName(namespaceURI, gInfo, qname.getLocalPart(), typeClassNames)
!= null) {
             return; 
         }
         
@@ -303,12 +300,26 @@ public class SourceGenerator {
         
         for (Element subEl : childEls) {
             String id = subEl.getAttribute("id");
-            if (id.length() > 0 && !resourceId.equals(id) && !id.startsWith("{java"))
{
+            if (id.length() > 0 && !resourceId.equals(id) && !id.startsWith("{java")
+                && !id.startsWith("java")) {
                 writeResourceClass(subEl, typeClassNames, gInfo, src, false, interfaceIsGenerated);
             }
         }
     }
     
+    private QName convertToQName(String resourceId, boolean expandedQName) {
+        QName qname = null;
+        if (expandedQName) {
+            qname = JAXRSUtils.convertStringToQName(resourceId);
+        } else {
+            int lastIndex = resourceId.lastIndexOf(".");
+            qname = lastIndex == -1 ? new QName(resourceId) 
+                                    : new QName(resourceId.substring(0, lastIndex),
+                                                resourceId.substring(lastIndex + 1));
+        }
+        return qname;
+    }
+    
     private String getClassType(boolean interfaceIsGenerated) {
         return interfaceIsGenerated ? "interface" : "class";
     }
@@ -444,13 +455,15 @@ public class SourceGenerator {
             responseTypeAvailable = writeResponseType(responseEls, sbCode, imports, typeClassNames,
gInfo);
             sbCode.append(id);
         } else {
-            QName qname = JAXRSUtils.convertStringToQName(id);
-            String packageName = PackageUtils.getPackageNameByNameSpaceURI(qname.getNamespaceURI());
+            boolean expandedQName = id.startsWith("{");
+            QName qname = convertToQName(id, expandedQName);
+            String packageName = possiblyConvertNamespaceURI(qname.getNamespaceURI(), expandedQName);
+            
             String clsSimpleName = getSchemaClassName(packageName, gInfo, qname.getLocalPart(),

                                                       typeClassNames);
             String localName = clsSimpleName == null ? qname.getLocalPart() 
                 : clsSimpleName.substring(packageName.length() + 1);
-            String subResponseNs = clsSimpleName == null ? getClassPackageName(qname.getNamespaceURI())

+            String subResponseNs = clsSimpleName == null ? getClassPackageName(packageName)

                 : clsSimpleName.substring(0, packageName.length());
             String parentId = ((Element)resourceEl.getParentNode()).getAttribute("id");
             writeSubResponseType(id.equals(parentId), subResponseNs, localName, sbCode, imports);
@@ -476,6 +489,10 @@ public class SourceGenerator {
         sbCode.append(getLineSep()).append(getLineSep());
     }
 
+    private String possiblyConvertNamespaceURI(String nsURI, boolean expandedQName) {
+        return expandedQName ? PackageUtils.getPackageNameByNameSpaceURI(nsURI) : nsURI;
+    }
+    
     private void generateEmptyMethodBody(StringBuilder sbCode, boolean responseTypeAvailable)
{
         sbCode.append(" {");
         sbCode.append(getLineSep()).append(TAB).append(TAB);

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=1124167&r1=1124166&r2=1124167&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 May 18 10:12:36 2011
@@ -272,7 +272,8 @@ public class WadlGenerator implements Re
                 : jaxbQname.getNamespaceURI();
             String localName = jaxbQname == null ? serviceClass.getSimpleName()
                 : jaxbQname.getLocalPart();
-            sb.append(" id=\"").append("{" + pName + "}" + localName).append("\"");
+            String finalName = jaxbQname == null ? pName + "." : "{" + pName + "}";
+            sb.append(" id=\"").append(finalName + localName).append("\"");
         }
         sb.append(">");
     }

Modified: cxf/trunk/tools/wadlto/jaxrs/src/test/resources/wadl/bookstore.xml
URL: http://svn.apache.org/viewvc/cxf/trunk/tools/wadlto/jaxrs/src/test/resources/wadl/bookstore.xml?rev=1124167&r1=1124166&r2=1124167&view=diff
==============================================================================
--- cxf/trunk/tools/wadlto/jaxrs/src/test/resources/wadl/bookstore.xml (original)
+++ cxf/trunk/tools/wadlto/jaxrs/src/test/resources/wadl/bookstore.xml Wed May 18 10:12:36
2011
@@ -46,7 +46,7 @@
   </xs:schema>
  </grammars>
  <resources base="http://localhost:8080/baz">
-   <resource path="/bookstore/{id}" id="{org.apache.cxf.jaxrs.model.wadl}BookStore">
+   <resource path="/bookstore/{id}" id="org.apache.cxf.jaxrs.model.wadl.BookStore">
      <doc xml:lang="en-us" title="book store resource">super resource</doc>
      <param name="id" style="template" type="xs:long"/>
 
@@ -145,7 +145,7 @@
    </resource>
 
    <!-- Dynamic subresource -->
-   <resource path="/books/{bookid}" id="{java.lang}Object">
+   <resource path="/books/{bookid}" id="java.lang.Object">
     <param name="id" style="template" type="xs:int"/>
     <param name="bookid" style="template" type="xs:int"/>
     <param name="mid" style="matrix" type="xs:int"/>
@@ -207,7 +207,7 @@
    </resource>
  </resource>
  
- <resource path="/form" id="{org.apache.cxf.jaxrs.model.wadl}FormInterface">
+ <resource path="/form" id="org.apache.cxf.jaxrs.model.wadl.FormInterface">
   
   <resource path="/form1">
    <method name="POST" id="form1">
@@ -235,7 +235,7 @@
  </resource>
 
  <!-- Recursive subresource -->
- <resource path="/itself" id="{org.apache.cxf.jaxrs.model.wadl}BookStore">
+ <resource path="/itself" id="org.apache.cxf.jaxrs.model.wadl.BookStore">
  </resource>
  
  </resource>

Modified: cxf/trunk/tools/wadlto/jaxrs/src/test/resources/wadl/bookstoreImport.xml
URL: http://svn.apache.org/viewvc/cxf/trunk/tools/wadlto/jaxrs/src/test/resources/wadl/bookstoreImport.xml?rev=1124167&r1=1124166&r2=1124167&view=diff
==============================================================================
--- cxf/trunk/tools/wadlto/jaxrs/src/test/resources/wadl/bookstoreImport.xml (original)
+++ cxf/trunk/tools/wadlto/jaxrs/src/test/resources/wadl/bookstoreImport.xml Wed May 18 10:12:36
2011
@@ -23,7 +23,7 @@
     <include href="schemas/book.xsd"/>
  </grammars>
  <resources base="http://localhost:8080/baz">
-   <resource path="/bookstore" id="{org.apache.cxf.jaxrs.model.wadl}BookStore">
+   <resource path="/bookstore" id="{wadl.model.jaxrs.cxf.apache.org}BookStore">
     
     <resource path="/books/{bookid}">
      <param name="bookid" style="template" type="xs:int"/>

Modified: cxf/trunk/tools/wadlto/jaxrs/src/test/resources/wadl/bookstoreImportCatalog.xml
URL: http://svn.apache.org/viewvc/cxf/trunk/tools/wadlto/jaxrs/src/test/resources/wadl/bookstoreImportCatalog.xml?rev=1124167&r1=1124166&r2=1124167&view=diff
==============================================================================
--- cxf/trunk/tools/wadlto/jaxrs/src/test/resources/wadl/bookstoreImportCatalog.xml (original)
+++ cxf/trunk/tools/wadlto/jaxrs/src/test/resources/wadl/bookstoreImportCatalog.xml Wed May
18 10:12:36 2011
@@ -23,7 +23,7 @@
     <include href="http://schemas/books/book.xsd"/>
  </grammars>
  <resources base="http://localhost:8080/baz">
-   <resource path="/bookstore" id="{org.apache.cxf.jaxrs.model.wadl}BookStore">
+   <resource path="/bookstore" id="{http://wadl.model.jaxrs.cxf.apache.org}BookStore">
     
     <resource path="/books/{bookid}">
      <param name="bookid" style="template" type="xs:int"/>



Mime
View raw message