cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1177618 - in /cxf/trunk: rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/codegen/SourceGenerator.java tools/wadlto/jaxrs/src/test/resources/wadl/bookstore.xml
Date Fri, 30 Sep 2011 11:57:31 GMT
Author: sergeyb
Date: Fri Sep 30 11:57:31 2011
New Revision: 1177618

URL: http://svn.apache.org/viewvc?rev=1177618&view=rev
Log:
[CXF-3797] Fixing a bug to do with subresource locator parameter generation plus few more
improvements, thanks to Christos Fragoulides

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

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=1177618&r1=1177617&r2=1177618&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
Fri Sep 30 11:57:31 2011
@@ -105,6 +105,7 @@ public class SourceGenerator {
     
     private static final Map<String, Class<?>> HTTP_METHOD_ANNOTATIONS;
     private static final Map<String, Class<?>> PARAM_ANNOTATIONS;
+    private static final Set<String> RESOURCE_LEVEL_PARAMS;
     
     static {
         HTTP_METHOD_ANNOTATIONS = new HashMap<String, Class<?>>();
@@ -120,6 +121,10 @@ public class SourceGenerator {
         PARAM_ANNOTATIONS.put("header", HeaderParam.class);
         PARAM_ANNOTATIONS.put("query", QueryParam.class);
         PARAM_ANNOTATIONS.put("matrix", MatrixParam.class);
+        
+        RESOURCE_LEVEL_PARAMS = new HashSet<String>();
+        RESOURCE_LEVEL_PARAMS.add("template");
+        RESOURCE_LEVEL_PARAMS.add("matrix");
     }
 
     private Comparator<String> importsComparator;
@@ -255,7 +260,7 @@ public class SourceGenerator {
                 GrammarInfo gInfoBase = generateSchemaCodeAndInfo(refApp, typeClassNames,
srcDir);
                 if (gInfoBase != null) {
                     gInfo.getElementTypeMap().putAll(gInfoBase.getElementTypeMap());
-                    gInfo.getNsMap().putAll(gInfo.getNsMap());
+                    gInfo.getNsMap().putAll(gInfoBase.getNsMap());
                 }
                 return getResourceElement(refApp, resElement, gInfo, typeClassNames, 
                                           "#" + wadlRef.getFragment(), srcDir);
@@ -513,8 +518,8 @@ public class SourceGenerator {
                                      ContextInfo info,
                                      boolean isRoot,
                                      String currentPath) {
-        Element resourceEl = "resource".equals(methodEl.getLocalName()) 
-            ? methodEl : (Element)methodEl.getParentNode();
+        boolean isResourceElement = "resource".equals(methodEl.getLocalName());
+        Element resourceEl = isResourceElement ? methodEl : (Element)methodEl.getParentNode();
         
         String methodName = methodEl.getAttribute("name");
         String methodNameLowerCase = methodName.toLowerCase();
@@ -577,9 +582,10 @@ public class SourceGenerator {
         }
         
         sbCode.append("(");
-        List<Element> inParamElements = new LinkedList<Element>();
-        inParamElements.addAll(DOMUtils.getChildrenWithName(resourceEl, 
-                                                            WadlGenerator.WADL_NS, "param"));
+        
+        List<Element> inParamElements = getParameters(resourceEl, 
+                    !isRoot && !isResourceElement && resourceEl.getAttribute("id").length()
> 0);
+        
         writeRequestTypes(firstRequestEl, inParamElements, sbCode, imports, info);
         sbCode.append(")");
         if (info.isInterfaceGenerated()) {
@@ -590,6 +596,20 @@ public class SourceGenerator {
         sbCode.append(getLineSep()).append(getLineSep());
     }
 
+    private List<Element> getParameters(Element resourceEl, boolean isSubresourceMethod)
{
+        List<Element> inParamElements = new LinkedList<Element>();
+        List<Element> allParamElements = DOMUtils.getChildrenWithName(resourceEl, 
+                                              WadlGenerator.WADL_NS, "param");
+        for (Element el : allParamElements) {
+            if (isSubresourceMethod && RESOURCE_LEVEL_PARAMS.contains(el.getAttribute("style")))
{
+                continue;
+            }
+            inParamElements.add(el);
+        }
+        return inParamElements;
+    }
+
+    
     private String possiblyConvertNamespaceURI(String nsURI, boolean expandedQName) {
         return expandedQName ? getPackageFromNamespace(nsURI) : nsURI;
     }
@@ -687,19 +707,16 @@ public class SourceGenerator {
             formParamsAvailable = currentSize < inParamEls.size(); 
         }
                   
-        if (form && !formParamsAvailable) {
-            addImport(imports, MultivaluedMap.class.getName());
-            sbCode.append("MultivaluedMap map");
-        } 
         for (int i = 0; i < inParamEls.size(); i++) {
     
             Element paramEl = inParamEls.get(i);
-
+            Class<?> paramAnn = PARAM_ANNOTATIONS.get(paramEl.getAttribute("style"));
+            if (paramAnn == QueryParam.class && form) {
+                paramAnn = FormParam.class; 
+            } 
             String name = paramEl.getAttribute("name");
             if (writeAnnotations(info.isInterfaceGenerated())) {
-                Class<?> paramAnnotation = form ? FormParam.class 
-                    : PARAM_ANNOTATIONS.get(paramEl.getAttribute("style"));
-                writeAnnotation(sbCode, imports, paramAnnotation, name, false, false);
+                writeAnnotation(sbCode, imports, paramAnn, name, false, false);
                 sbCode.append(" ");
             }
             String type = getPrimitiveType(paramEl);
@@ -715,24 +732,30 @@ public class SourceGenerator {
                 }
             }
         }
+        String elementParamType = null;
+        String elementParamName = null;
         if (!form) {
-            String elementName = null;
-            
             List<Element> repElements = requestEl != null 
                 ? DOMUtils.getChildrenWithName(requestEl, WadlGenerator.WADL_NS, "representation")
                 : CastUtils.cast(Collections.emptyList(), Element.class);
             if (repElements.size() > 0) {    
-                elementName = getElementRefName(repElements, info.getTypeClassNames(), 
+                elementParamType = getElementRefName(repElements, info.getTypeClassNames(),

                         info.getGrammarInfo(), imports);
-            }
-            if (elementName != null) {
-                if (inParamEls.size() > 0) {
-                    sbCode.append(", ");
+                if (elementParamType != null) {
+                    elementParamName = elementParamType.toLowerCase();
                 }
-                sbCode.append(elementName).append(" ").append(elementName.toLowerCase());
             }
+        } else if (!formParamsAvailable) {
+            addImport(imports, MultivaluedMap.class.getName());
+            elementParamType = MultivaluedMap.class.getSimpleName();
+            elementParamName = "map";
+        }
+        if (elementParamType != null) {
+            if (inParamEls.size() > 0) {
+                sbCode.append(", ");
+            }
+            sbCode.append(elementParamType).append(" ").append(elementParamName);
         }
-        
     }
     
     private String getPrimitiveType(Element paramEl) {

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=1177618&r1=1177617&r2=1177618&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 Fri Sep 30 11:57:31
2011
@@ -219,6 +219,13 @@
     <resource path="/recursive" id="org.apache.cxf.jaxrs.model.wadl.FormInterface"/>
     <resource path="/c">
       <resource path="/formSub" id="org.apache.cxf.jaxrs.model.wadl.FormInterface2">
+        <param name="formid" style="template" type="xs:int"/>
+        <method name="POST" id="formSub">
+	        <request>
+	           <representation mediaType="application/x-www-form-urlencoded"/>
+	        </request>
+	        <response status="204"></response>
+	      </method>
         <resource path="/recursive" id="org.apache.cxf.jaxrs.model.wadl.FormInterface"/>
         <resource path="/subform1">
 	      <method name="POST" id="form1">
@@ -231,6 +238,7 @@
 	  </resource> 
    </resource>
   <resource path="/form1">
+   <param name="formid" style="template" type="xs:int"/>
    <method name="POST" id="form1">
     <request>
      <representation mediaType="application/x-www-form-urlencoded"/>



Mime
View raw message