cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject cxf git commit: [CXF-6491] Avoiding listing all the representation media types if a method is generated per every request representation
Date Thu, 09 Jul 2015 13:30:23 GMT
Repository: cxf
Updated Branches:
  refs/heads/3.0.x-fixes 963f56b26 -> c780d3a6a


[CXF-6491] Avoiding listing all the representation media types if a method is generated per
every request representation


Project: http://git-wip-us.apache.org/repos/asf/cxf/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/c780d3a6
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/c780d3a6
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/c780d3a6

Branch: refs/heads/3.0.x-fixes
Commit: c780d3a6acbccbb93ddbff03f946b1a782972e5c
Parents: 963f56b
Author: Sergey Beryozkin <sberyozkin@talend.com>
Authored: Thu Jul 9 14:24:51 2015 +0100
Committer: Sergey Beryozkin <sberyozkin@talend.com>
Committed: Thu Jul 9 14:29:07 2015 +0100

----------------------------------------------------------------------
 .../cxf/tools/wadlto/jaxrs/SourceGenerator.java | 28 +++++++++++---------
 .../jaxrs/src/test/resources/wadl/bookstore.xml |  2 +-
 2 files changed, 16 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/c780d3a6/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxrs/SourceGenerator.java
----------------------------------------------------------------------
diff --git a/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxrs/SourceGenerator.java
b/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxrs/SourceGenerator.java
index a3a24c5..2d4bed0 100644
--- a/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxrs/SourceGenerator.java
+++ b/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxrs/SourceGenerator.java
@@ -217,7 +217,7 @@ public class SourceGenerator {
     private Map<String, String> schemaTypeMap = Collections.emptyMap();
     private Map<String, String> mediaTypesMap = Collections.emptyMap();
     private Bus bus;
-    private boolean supportMultipleXmlReps;
+    private boolean supportMultipleRepsWithElements;
     private boolean validateWadl;    
     private SchemaCollection schemaCollection = new SchemaCollection();
     private String encoding;
@@ -231,7 +231,7 @@ public class SourceGenerator {
     }
     
     public void setSupportMultipleXmlReps(boolean support) {
-        supportMultipleXmlReps = support;
+        supportMultipleRepsWithElements = support;
     }
     
     public void setWadlNamespace(String ns) {
@@ -688,7 +688,7 @@ public class SourceGenerator {
         List<Element> requestEls = getWadlElements(methodEl, "request");
         Element firstRequestEl = requestEls.size() >= 1 ? requestEls.get(0) : null;
         List<Element> allRequestReps = getWadlElements(firstRequestEl, "representation");
-        List<Element> xmlRequestReps = getXmlReps(allRequestReps, info.getGrammarInfo());
+        List<Element> requestRepsWithElements = getRepsWithElements(allRequestReps,
info.getGrammarInfo());
         
         final String methodNameLowerCase = methodEl.getAttribute("name").toLowerCase();
         String id = methodEl.getAttribute("id");
@@ -699,17 +699,19 @@ public class SourceGenerator {
         final boolean suspendedAsync = responseRequired ? false
             : isMethodMatched(suspendedAsyncMethods, methodNameLowerCase, id);
         
-        boolean jaxpSourceRequired = xmlRequestReps.size() > 1 && !supportMultipleXmlReps;
-        int numOfMethods = jaxpSourceRequired ? 1 : xmlRequestReps.size(); 
+        boolean jaxpSourceRequired = requestRepsWithElements.size() > 1 && !supportMultipleRepsWithElements;
+        int numOfMethods = jaxpSourceRequired ? 1 : requestRepsWithElements.size(); 
         for (int i = 0; i < numOfMethods; i++) {
             
-            Element inXmlRep = xmlRequestReps.get(i);
-                        
+            List<Element> requestReps = allRequestReps;
+            
+            Element requestRepWithElement = requestRepsWithElements.get(i);
             String suffixName = "";
-            if (!jaxpSourceRequired && inXmlRep != null && xmlRequestReps.size()
> 1) {
-                String value = inXmlRep.getAttribute("element");
+            if (!jaxpSourceRequired && requestRepWithElement != null && requestRepsWithElements.size()
> 1) {
+                String value = requestRepWithElement.getAttribute("element");
                 int index = value.indexOf(":");
                 suffixName = value.substring(index + 1).replace("-", "");
+                requestReps = Collections.singletonList(requestRepWithElement);
             }
             if (writeAnnotations(info.isInterfaceGenerated())) {
                 sbCode.append(TAB);
@@ -721,7 +723,7 @@ public class SourceGenerator {
                     } else {
                         // TODO : write a custom annotation class name based on HttpMethod
   
                     }
-                    writeFormatAnnotations(allRequestReps, sbCode, imports, true);
+                    writeFormatAnnotations(requestReps, sbCode, imports, true);
                     writeFormatAnnotations(getWadlElements(getOKResponse(responseEls), "representation"),
                             sbCode, imports, false);
                 }
@@ -783,7 +785,7 @@ public class SourceGenerator {
             List<Element> inParamElements = getParameters(resourceEl, info.getInheritedParams(),
                         !isRoot && !isResourceElement && resourceEl.getAttribute("id").length()
> 0);
             
-            Element repElement = getActualRepElement(allRequestReps, inXmlRep); 
+            Element repElement = getActualRepElement(allRequestReps, requestRepWithElement);

             writeRequestTypes(firstRequestEl, classPackage, repElement, inParamElements,

                     jaxpSourceRequired, sbCode, imports, info, suspendedAsync);
             sbCode.append(")");
@@ -805,7 +807,7 @@ public class SourceGenerator {
             || methodNames.size() == 1 && "*".equals(methodNames.iterator().next());
     }
 
-    private List<Element> getXmlReps(List<Element> repElements, GrammarInfo gInfo)
{
+    private List<Element> getRepsWithElements(List<Element> repElements, GrammarInfo
gInfo) {
         Set<String> values = new HashSet<String>(repElements.size());
         List<Element> xmlReps = new ArrayList<Element>();
         for (Element el : repElements) {
@@ -947,7 +949,7 @@ public class SourceGenerator {
         }
         
         String elementType = responseRequired ? null : getElementRefName(
-                getActualRepElement(repElements, getXmlReps(repElements, info.getGrammarInfo()).get(0)),

+                getActualRepElement(repElements, getRepsWithElements(repElements, info.getGrammarInfo()).get(0)),

                 info, imports, true);
         if (elementType != null) {
             sbCode.append(elementType + " ");

http://git-wip-us.apache.org/repos/asf/cxf/blob/c780d3a6/tools/wadlto/jaxrs/src/test/resources/wadl/bookstore.xml
----------------------------------------------------------------------
diff --git a/tools/wadlto/jaxrs/src/test/resources/wadl/bookstore.xml b/tools/wadlto/jaxrs/src/test/resources/wadl/bookstore.xml
index ebf8bcd..69a8108 100644
--- a/tools/wadlto/jaxrs/src/test/resources/wadl/bookstore.xml
+++ b/tools/wadlto/jaxrs/src/test/resources/wadl/bookstore.xml
@@ -145,7 +145,7 @@
                 <method name="POST" id="addBookOrBook2">
                     <request>
                         <representation mediaType="application/xml" element="prefix1:thebook"/>
-                        <representation mediaType="application/xml" element="prefix1:the-Book2"/>
+                        <representation mediaType="application/v2+xml" element="prefix1:the-Book2"/>
                         <representation mediaType="application/json"/>
                     </request>
                     <response status="201"/>


Mime
View raw message