cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1376880 - in /cxf/branches/2.6.x-fixes: ./ tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/ tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxrs/ tools/wadlto/jaxrs/src/test/java/org/apache/cxf/tools/wadlto/jaxrs...
Date Fri, 24 Aug 2012 10:00:19 GMT
Author: sergeyb
Date: Fri Aug 24 10:00:18 2012
New Revision: 1376880

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

........
  r1376613 | sergeyb | 2012-08-23 18:58:00 +0100 (Thu, 23 Aug 2012) | 1 line
  
  [CXF-4485] Support for inheriting resource-level parameters
........

Modified:
    cxf/branches/2.6.x-fixes/   (props changed)
    cxf/branches/2.6.x-fixes/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/WadlToolConstants.java
    cxf/branches/2.6.x-fixes/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxrs/JAXRSContainer.java
    cxf/branches/2.6.x-fixes/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxrs/SourceGenerator.java
    cxf/branches/2.6.x-fixes/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxrs/jaxrs-toolspec.xml
    cxf/branches/2.6.x-fixes/tools/wadlto/jaxrs/src/test/java/org/apache/cxf/tools/wadlto/jaxrs/JAXRSContainerTest.java
    cxf/branches/2.6.x-fixes/tools/wadlto/jaxrs/src/test/resources/wadl/resourcesNoId.xml
    cxf/branches/2.6.x-fixes/tools/wadlto/jaxrs/src/test/resources/wadl/singleResourceWithRefs.xml

Propchange: cxf/branches/2.6.x-fixes/
------------------------------------------------------------------------------
  Merged /cxf/trunk:r1376613

Propchange: cxf/branches/2.6.x-fixes/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.

Modified: cxf/branches/2.6.x-fixes/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/WadlToolConstants.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.6.x-fixes/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/WadlToolConstants.java?rev=1376880&r1=1376879&r2=1376880&view=diff
==============================================================================
--- cxf/branches/2.6.x-fixes/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/WadlToolConstants.java
(original)
+++ cxf/branches/2.6.x-fixes/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/WadlToolConstants.java
Fri Aug 24 10:00:18 2012
@@ -49,6 +49,7 @@ public final class WadlToolConstants {
     
     public static final String CFG_WADL_NAMESPACE = "wadlNamespace";
     public static final String CFG_GENERATE_ENUMS = "generateEnums";
+    public static final String CFG_INHERIT_PARAMS = "inheritResourceParams";
     
     public static final String CFG_WADLURL = "wadl";
     

Modified: cxf/branches/2.6.x-fixes/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxrs/JAXRSContainer.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.6.x-fixes/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxrs/JAXRSContainer.java?rev=1376880&r1=1376879&r2=1376880&view=diff
==============================================================================
--- cxf/branches/2.6.x-fixes/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxrs/JAXRSContainer.java
(original)
+++ cxf/branches/2.6.x-fixes/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxrs/JAXRSContainer.java
Fri Aug 24 10:00:18 2012
@@ -149,9 +149,8 @@ public class JAXRSContainer extends Abst
         sg.setSchemaTypeMap(getSchemaTypeMap());
         sg.setMediaTypeMap(getMediaTypeMap());
 
-        if (context.optionSet(WadlToolConstants.CFG_GENERATE_ENUMS)) {
-            sg.setGenerateEnums(true);
-        }
+        sg.setGenerateEnums(context.optionSet(WadlToolConstants.CFG_GENERATE_ENUMS));
+        sg.setInheritResourceParams(context.optionSet(WadlToolConstants.CFG_INHERIT_PARAMS));
         sg.setSkipSchemaGeneration(context.optionSet(WadlToolConstants.CFG_NO_TYPES));
         
         // generate

Modified: cxf/branches/2.6.x-fixes/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxrs/SourceGenerator.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.6.x-fixes/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxrs/SourceGenerator.java?rev=1376880&r1=1376879&r2=1376880&view=diff
==============================================================================
--- cxf/branches/2.6.x-fixes/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxrs/SourceGenerator.java
(original)
+++ cxf/branches/2.6.x-fixes/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxrs/SourceGenerator.java
Fri Aug 24 10:00:18 2012
@@ -176,6 +176,7 @@ public class SourceGenerator {
     private String wadlNamespace = WadlGenerator.WADL_NS;
     private boolean generateEnums;
     private boolean skipSchemaGeneration;
+    private boolean inheritResourceParams;
     
     private Map<String, String> properties; 
     
@@ -556,15 +557,23 @@ public class SourceGenerator {
                               String currentPath) {
     //CHECKSTYLE:ON    
         List<Element> methodEls = getWadlElements(rElement, "method");
-       
+        
+        List<Element> currentInheritedParams = inheritResourceParams 
+            ? new LinkedList<Element>(info.getInheritedParams()) : Collections.<Element>emptyList();
         for (Element methodEl : methodEls) {
             writeResourceMethod(methodEl, classPackage, imports, sbCode, info, isRoot, currentPath);
   
         }
+        if (inheritResourceParams && methodEls.isEmpty()) {
+            info.getInheritedParams().addAll(getWadlElements(rElement, "param"));
+        }
         
         List<Element> childEls = getWadlElements(rElement, "resource");
         for (Element childEl : childEls) {
             String path = childEl.getAttribute("path");
-            String newPath = (currentPath + path).replace("//", "/");
+            if (!path.startsWith("/")) {
+                path = "/" + path;
+            }
+            String newPath = currentPath + path.replace("//", "/");
             String id = childEl.getAttribute("id");
             if (id.length() == 0) {
                 writeMethods(childEl, classPackage, imports, sbCode, info, id, false, newPath);
@@ -572,6 +581,8 @@ public class SourceGenerator {
                 writeResourceMethod(childEl, classPackage, imports, sbCode, info, false,
newPath);
             }
         }
+        info.getInheritedParams().clear();
+        info.getInheritedParams().addAll(currentInheritedParams);
     }
     
     private void writeAnnotation(StringBuilder sbCode, Set<String> imports,
@@ -702,7 +713,7 @@ public class SourceGenerator {
             
             sbCode.append("(");
             
-            List<Element> inParamElements = getParameters(resourceEl, 
+            List<Element> inParamElements = getParameters(resourceEl, info.getInheritedParams(),
                         !isRoot && !isResourceElement && resourceEl.getAttribute("id").length()
> 0);
             
             Element repElement = getActualRepElement(allRequestReps, inXmlRep); 
@@ -734,15 +745,24 @@ public class SourceGenerator {
         return xmlReps;
     }
     
-    private List<Element> getParameters(Element resourceEl, boolean isSubresourceMethod)
{
+    private List<Element> getParameters(Element resourceEl, List<Element> inheritedParams,

+                                        boolean isSubresourceMethod) {
         List<Element> inParamElements = new LinkedList<Element>();
         List<Element> allParamElements = getWadlElements(resourceEl, "param");
+        List<Element> newInheritedParams = inheritResourceParams ? new LinkedList<Element>()

+            : Collections.<Element>emptyList();
         for (Element el : allParamElements) {
-            if (isSubresourceMethod && RESOURCE_LEVEL_PARAMS.contains(el.getAttribute("style")))
{
+            boolean isResourceLevelParam = RESOURCE_LEVEL_PARAMS.contains(el.getAttribute("style"));

+            if (isSubresourceMethod && isResourceLevelParam) {
                 continue;
             }
+            if (inheritResourceParams && isResourceLevelParam) {
+                newInheritedParams.add(el);
+            }
             inParamElements.add(el);
         }
+        inParamElements.addAll(inheritedParams);
+        inheritedParams.addAll(newInheritedParams);
         return inParamElements;
     }
 
@@ -1433,6 +1453,10 @@ public class SourceGenerator {
         this.compilerArgs = args;
     }
 
+    public void setInheritResourceParams(boolean inherit) {
+        this.inheritResourceParams = inherit;
+    }
+    
     public void setSchemaPackageMap(Map<String, String> map) {
         this.schemaPackageMap = map;
     }
@@ -1544,6 +1568,7 @@ public class SourceGenerator {
         private Set<String> resourceClassNames = new HashSet<String>();
         private Application rootApp;
         private File srcDir;
+        private List<Element> inheritedParams = new LinkedList<Element>();
         
         public ContextInfo(Application rootApp,
                            File srcDir,
@@ -1556,6 +1581,9 @@ public class SourceGenerator {
             this.rootApp = rootApp;
             this.srcDir = srcDir;
         }
+        public List<Element> getInheritedParams() {
+            return inheritedParams;
+        }
         public Application getApp() {
             return rootApp;
         }

Modified: cxf/branches/2.6.x-fixes/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxrs/jaxrs-toolspec.xml
URL: http://svn.apache.org/viewvc/cxf/branches/2.6.x-fixes/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxrs/jaxrs-toolspec.xml?rev=1376880&r1=1376879&r2=1376880&view=diff
==============================================================================
--- cxf/branches/2.6.x-fixes/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxrs/jaxrs-toolspec.xml
(original)
+++ cxf/branches/2.6.x-fixes/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxrs/jaxrs-toolspec.xml
Fri Aug 24 10:00:18 2012
@@ -170,6 +170,14 @@ Examples:
                 <switch>generateEnums</switch>
             </option>
             
+            <option id="inheritResourceParams" maxOccurs="1">
+                <annotation>
+                    Specifies that resource-level (path or matrix) parameters
+                    can be inherited by child resources
+                </annotation>
+                <switch>inheritResourceParams</switch>
+            </option>
+            
             <option id="notypes" maxOccurs="1">
                 <annotation>Turns off generating types</annotation>
                 <switch>noTypes</switch>

Modified: cxf/branches/2.6.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.6.x-fixes/tools/wadlto/jaxrs/src/test/java/org/apache/cxf/tools/wadlto/jaxrs/JAXRSContainerTest.java?rev=1376880&r1=1376879&r2=1376880&view=diff
==============================================================================
--- cxf/branches/2.6.x-fixes/tools/wadlto/jaxrs/src/test/java/org/apache/cxf/tools/wadlto/jaxrs/JAXRSContainerTest.java
(original)
+++ cxf/branches/2.6.x-fixes/tools/wadlto/jaxrs/src/test/java/org/apache/cxf/tools/wadlto/jaxrs/JAXRSContainerTest.java
Fri Aug 24 10:00:18 2012
@@ -376,6 +376,7 @@ public class JAXRSContainerTest extends 
             context.put(WadlToolConstants.CFG_OUTPUTDIR, output.getCanonicalPath());
             context.put(WadlToolConstants.CFG_WADLURL, getLocation("/wadl/resourcesNoId.xml"));
             context.put(WadlToolConstants.CFG_COMPILE, "true");
+            context.put(WadlToolConstants.CFG_INHERIT_PARAMS, "true");
             
             container.setContext(context);
             container.execute();

Modified: cxf/branches/2.6.x-fixes/tools/wadlto/jaxrs/src/test/resources/wadl/resourcesNoId.xml
URL: http://svn.apache.org/viewvc/cxf/branches/2.6.x-fixes/tools/wadlto/jaxrs/src/test/resources/wadl/resourcesNoId.xml?rev=1376880&r1=1376879&r2=1376880&view=diff
==============================================================================
--- cxf/branches/2.6.x-fixes/tools/wadlto/jaxrs/src/test/resources/wadl/resourcesNoId.xml
(original)
+++ cxf/branches/2.6.x-fixes/tools/wadlto/jaxrs/src/test/resources/wadl/resourcesNoId.xml
Fri Aug 24 10:00:18 2012
@@ -4,13 +4,18 @@
   <resources base="http://localhost:8080/baz">
        <resource path="/TestRs">
           <param name="id" style="template" type="xs:int"/>
-          <resource path="/helloWorld/{id}">
+          <resource path="/helloWorld/{id}/{id2}">
+           <param name="id2" style="template" type="xs:int"/>
            <method name="GET">
            <response>
              <representation mediaType="application/octet-stream">
                <param name="result" style="plain" type="xs:string"/>
              </representation></response>
            </method>
+           
+           <resource path="sub">
+	           <method name="POST"/>
+	       </resource>
           </resource>
           <resource path="/helloWorld2">
            <method name="GET">

Modified: cxf/branches/2.6.x-fixes/tools/wadlto/jaxrs/src/test/resources/wadl/singleResourceWithRefs.xml
URL: http://svn.apache.org/viewvc/cxf/branches/2.6.x-fixes/tools/wadlto/jaxrs/src/test/resources/wadl/singleResourceWithRefs.xml?rev=1376880&r1=1376879&r2=1376880&view=diff
==============================================================================
--- cxf/branches/2.6.x-fixes/tools/wadlto/jaxrs/src/test/resources/wadl/singleResourceWithRefs.xml
(original)
+++ cxf/branches/2.6.x-fixes/tools/wadlto/jaxrs/src/test/resources/wadl/singleResourceWithRefs.xml
Fri Aug 24 10:00:18 2012
@@ -20,7 +20,7 @@
 <application xmlns="http://wadl.dev.java.net/2009/02" xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:prefix1="http://superbooks">
 
  <resource_type id="main-resource">
-     <param name="id" style="template" type="xs:long"/>
+     <param href="#id1"/>
      <method name="GET">
       <request/>
       <response>
@@ -43,4 +43,6 @@
  <resources base="http://localhost:8080/baz">
      <resource path="/bookstore/{id}" type="#main-resource"/>
   </resources>  
+  
+  <param id="id1" name="id" style="template" type="xs:long"/>
 </application>



Mime
View raw message