cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject git commit: [CXF-5941, CXF-5961] Controlling the order of inherited parameters, fixing the regression, patches from Alexey Markevich applied with some extra code
Date Thu, 21 Aug 2014 09:42:25 GMT
Repository: cxf
Updated Branches:
  refs/heads/master 913eff1bc -> 198f33bad


[CXF-5941, CXF-5961] Controlling the order of inherited parameters, fixing the regression,
patches from Alexey Markevich applied with some extra code


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

Branch: refs/heads/master
Commit: 198f33badeea10168051eed33becafa727e0e9aa
Parents: 913eff1
Author: Sergey Beryozkin <sberyozkin@talend.com>
Authored: Thu Aug 21 10:42:06 2014 +0100
Committer: Sergey Beryozkin <sberyozkin@talend.com>
Committed: Thu Aug 21 10:42:06 2014 +0100

----------------------------------------------------------------------
 .../cxf/tools/wadlto/jaxrs/JAXRSContainer.java  | 17 ++++++++++--
 .../cxf/tools/wadlto/jaxrs/SourceGenerator.java | 17 +++++++++---
 .../cxf/tools/wadlto/jaxrs/jaxrs-toolspec.xml   | 27 ++++++++------------
 .../tools/wadlto/jaxrs/JAXRSContainerTest.java  |  2 +-
 .../cxf/tools/wadlto/jaxrs/WADLToJavaTest.java  |  1 +
 .../jaxrs/src/test/resources/wadl/test.xml      |  2 +-
 6 files changed, 43 insertions(+), 23 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/198f33ba/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxrs/JAXRSContainer.java
----------------------------------------------------------------------
diff --git a/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxrs/JAXRSContainer.java
b/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxrs/JAXRSContainer.java
index c8ab714..5d13b3b 100644
--- a/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxrs/JAXRSContainer.java
+++ b/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxrs/JAXRSContainer.java
@@ -33,6 +33,7 @@ import java.util.Set;
 
 import org.xml.sax.InputSource;
 
+import org.apache.cxf.common.util.StringUtils;
 import org.apache.cxf.common.util.URIParserUtil;
 import org.apache.cxf.helpers.IOUtils;
 import org.apache.cxf.tools.common.AbstractCXFToolContainer;
@@ -152,9 +153,13 @@ public class JAXRSContainer extends AbstractCXFToolContainer {
 
         sg.setSuspendedAsyncMethods(getSuspendedAsyncMethods());
         sg.setResponseMethods(getResponseMethods());
-        
+                
         sg.setGenerateEnums(context.optionSet(WadlToolConstants.CFG_GENERATE_ENUMS));
-        sg.setInheritResourceParams(context.optionSet(WadlToolConstants.CFG_INHERIT_PARAMS));
+        boolean inheritResourceParams = context.optionSet(WadlToolConstants.CFG_INHERIT_PARAMS);
+        sg.setInheritResourceParams(inheritResourceParams);
+        if (inheritResourceParams) {
+            sg.setInheritResourceParamsFirst(isInheritResourceParamsFirst());
+        }
         sg.setSkipSchemaGeneration(context.optionSet(WadlToolConstants.CFG_NO_TYPES));
         
         boolean noVoidForEmptyResponses = context.optionSet(WadlToolConstants.CFG_NO_VOID_FOR_EMPTY_RESPONSES);
@@ -238,6 +243,14 @@ public class JAXRSContainer extends AbstractCXFToolContainer {
             return Collections.emptySet();
         }
     }
+    private boolean isInheritResourceParamsFirst() {
+        Object value = context.get(WadlToolConstants.CFG_INHERIT_PARAMS);
+        if (StringUtils.isEmpty((String)value)) {
+            return true;
+        } else {
+            return "first".equals(value.toString().trim());
+        }
+    }
     
     //TODO: this belongs to JAXB Databinding, should we just reuse 
     // org.apache.cxf.tools.wsdlto.databinding.jaxb ?

http://git-wip-us.apache.org/repos/asf/cxf/blob/198f33ba/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 0e927a3..6ec8dc1 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
@@ -191,6 +191,7 @@ public class SourceGenerator {
     private boolean generateEnums;
     private boolean skipSchemaGeneration;
     private boolean inheritResourceParams;
+    private boolean inheritResourceParamsFirst;
     private boolean useVoidForEmptyResponses = true;
     private boolean generateResponseIfHeadersSet;
     
@@ -830,6 +831,7 @@ public class SourceGenerator {
             }
             inParamElements.add(el);
         }
+        int inheritedCount = 0;
         for (Element inherited : inheritedParams) {
             boolean duplicate = false;
             for (Element in : inParamElements) {
@@ -839,7 +841,12 @@ public class SourceGenerator {
                 }
             }
             if (!duplicate) {
-                inParamElements.add(inherited);
+                if (inheritResourceParamsFirst && inheritedCount < inParamElements.size())
{
+                    inParamElements.set(inheritedCount, inherited);
+                } else {
+                    inParamElements.add(inherited);
+                }
+                inheritedCount++;
             }
         }
         inheritedParams.addAll(newInheritedParams);
@@ -1015,7 +1022,7 @@ public class SourceGenerator {
                 String required = paramEl.getAttribute("required");
                 if (Multipart.class.equals(paramAnn) && "false".equals(required))
{
                     writeAnnotation(sbCode, imports, paramAnn, null, false, false);
-                    sbCode.append("(value = \"").append(name).append("\", required = \"false\"").append(')');
+                    sbCode.append("(value = \"").append(name).append("\", required = false").append(')');
                 } else {
                     writeAnnotation(sbCode, imports, paramAnn, name, false, false);
                 }
@@ -1329,7 +1336,7 @@ public class SourceGenerator {
                 Element paramEl = DOMUtils.getFirstChildWithName(repElement, getWadlNamespace(),
"param");
                 if (paramEl != null) {
                     String type = getPrimitiveType(paramEl, info, imports);
-                    type = addListIfRepeating(type, isRepeatingParam(paramEl), imports);
+                    return addListIfRepeating(type, isRepeatingParam(paramEl), imports);
                 }
             }
         }
@@ -1674,6 +1681,10 @@ public class SourceGenerator {
         this.inheritResourceParams = inherit;
     }
     
+    public void setInheritResourceParamsFirst(boolean inherit) {
+        this.inheritResourceParamsFirst = inherit;
+    }
+    
     public void setSchemaPackageMap(Map<String, String> map) {
         this.schemaPackageMap = map;
     }

http://git-wip-us.apache.org/repos/asf/cxf/blob/198f33ba/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxrs/jaxrs-toolspec.xml
----------------------------------------------------------------------
diff --git a/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxrs/jaxrs-toolspec.xml
b/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxrs/jaxrs-toolspec.xml
index a894c4c..63f1586 100644
--- a/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxrs/jaxrs-toolspec.xml
+++ b/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxrs/jaxrs-toolspec.xml
@@ -143,13 +143,13 @@ Examples:
                 </annotation>
                 <switch>impl</switch>
             </option>
-            <option id="async" maxOccurs="unbounded">
+            <option id="async" maxOccurs="1">
                 <annotation>
                     Specifies a comma separated list of method names or identifiers 
                     which need to support suspended asynchronous invocations            
        
                 </annotation>
                 <associatedArgument placement="immediate">
-                    <annotation>methodNames</annotation>
+                    <annotation> methodNames</annotation>
                 </associatedArgument>
                 <switch>async</switch>
             </option>
@@ -162,9 +162,14 @@ Examples:
             </option>
             <option id="inheritResourceParams" maxOccurs="1">
                 <annotation>
-                    Specifies that resource-level (path or matrix) parameters
-                    can be inherited by child resources
+                    Specifies that path or matrix parameters can be inherited by child resources.
+                    By default the inherited parameters will be listed first in a method
parameter list.
+                    The "last" qualifier can be used to reverse the order.
                 </annotation>
+                <associatedArgument placement="immediate">
+                    <annotation> first|last</annotation>
+                    <valueenum>first|last</valueenum>
+                </associatedArgument>
                 <switch>inheritResourceParams</switch>
             </option>
             <option id="notypes" maxOccurs="1">
@@ -201,26 +206,16 @@ Examples:
                 </annotation>
                 <switch>generateResponseIfHeadersSet</switch>
             </option>
-            <option id="generateResponseForMethods" maxOccurs="unbounded">
+            <option id="generateResponseForMethods" maxOccurs="1">
                 <annotation>
                     Specifies a comma separated list of method names or identifiers 
                     which need to have JAXRS Response return type generated             
       
                 </annotation>
                 <associatedArgument placement="immediate">
-                    <annotation>methodNames</annotation>
+                    <annotation> methodNames</annotation>
                 </associatedArgument>
                 <switch>generateResponseForMethods</switch>
             </option>
-            <option id="async" maxOccurs="unbounded">
-                <annotation>
-                    Specifies a comma separated list of method names or identifiers 
-                    which need to support suspended asynchronous invocations            
        
-                </annotation>
-                <associatedArgument placement="immediate">
-                    <annotation>methodNames</annotation>
-                </associatedArgument>
-                <switch>async</switch>
-            </option>
             <option id="xjc" maxOccurs="unbounded">
                 <annotation>
                     Specifies a comma separated list of arguments that are passed directly
to XJC when the

http://git-wip-us.apache.org/repos/asf/cxf/blob/198f33ba/tools/wadlto/jaxrs/src/test/java/org/apache/cxf/tools/wadlto/jaxrs/JAXRSContainerTest.java
----------------------------------------------------------------------
diff --git a/tools/wadlto/jaxrs/src/test/java/org/apache/cxf/tools/wadlto/jaxrs/JAXRSContainerTest.java
b/tools/wadlto/jaxrs/src/test/java/org/apache/cxf/tools/wadlto/jaxrs/JAXRSContainerTest.java
index a0416b8..c06a9f6 100644
--- a/tools/wadlto/jaxrs/src/test/java/org/apache/cxf/tools/wadlto/jaxrs/JAXRSContainerTest.java
+++ b/tools/wadlto/jaxrs/src/test/java/org/apache/cxf/tools/wadlto/jaxrs/JAXRSContainerTest.java
@@ -101,7 +101,7 @@ public class JAXRSContainerTest extends ProcessorTestBase {
             context.put(WadlToolConstants.CFG_SCHEMA_TYPE_MAP, 
                         "{http://www.w3.org/2001/XMLSchema}anyType=" 
                         + "java.io.InputStream");
-            context.put(WadlToolConstants.CFG_INHERIT_PARAMS, "true");
+            context.put(WadlToolConstants.CFG_INHERIT_PARAMS, "=last");
             
             container.setContext(context);
             container.execute();

http://git-wip-us.apache.org/repos/asf/cxf/blob/198f33ba/tools/wadlto/jaxrs/src/test/java/org/apache/cxf/tools/wadlto/jaxrs/WADLToJavaTest.java
----------------------------------------------------------------------
diff --git a/tools/wadlto/jaxrs/src/test/java/org/apache/cxf/tools/wadlto/jaxrs/WADLToJavaTest.java
b/tools/wadlto/jaxrs/src/test/java/org/apache/cxf/tools/wadlto/jaxrs/WADLToJavaTest.java
index 51c3fbd..0d51674 100644
--- a/tools/wadlto/jaxrs/src/test/java/org/apache/cxf/tools/wadlto/jaxrs/WADLToJavaTest.java
+++ b/tools/wadlto/jaxrs/src/test/java/org/apache/cxf/tools/wadlto/jaxrs/WADLToJavaTest.java
@@ -46,6 +46,7 @@ public class WADLToJavaTest extends ProcessorTestBase {
                 "-tMap",
                 "{http://www.w3.org/2001/XMLSchema}date=java.util.List..String",
                 "-async getName,delete",
+                "-inheritResourceParams first",
                 "-compile",
                 getLocation("/wadl/bookstore.xml"),
             };

http://git-wip-us.apache.org/repos/asf/cxf/blob/198f33ba/tools/wadlto/jaxrs/src/test/resources/wadl/test.xml
----------------------------------------------------------------------
diff --git a/tools/wadlto/jaxrs/src/test/resources/wadl/test.xml b/tools/wadlto/jaxrs/src/test/resources/wadl/test.xml
index b70b9ef..5604970 100644
--- a/tools/wadlto/jaxrs/src/test/resources/wadl/test.xml
+++ b/tools/wadlto/jaxrs/src/test/resources/wadl/test.xml
@@ -2,7 +2,7 @@
 	<grammars />
 	<resources>
 		<resource id="Test" path="/repository">
-
+            <param name="top" style="template" type="xs:string"/>
 			<method name="GET" id="listRepositories">
 				<response>
 					<representation mediaType="application/json" />


Mime
View raw message