cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject git commit: [CXF-5956, CXF-5961] Support for repeating response parameters and optional multipart parameters, patches to both issues provided by Alexei Markevich
Date Tue, 19 Aug 2014 16:18:48 GMT
Repository: cxf
Updated Branches:
  refs/heads/master 43c8d500b -> 819054563


[CXF-5956, CXF-5961] Support for repeating response parameters and optional multipart parameters,
patches to both issues provided by Alexei Markevich


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

Branch: refs/heads/master
Commit: 81905456385a4431d58805f3ba580b2e4ad45c26
Parents: 43c8d50
Author: Sergey Beryozkin <sberyozkin@talend.com>
Authored: Tue Aug 19 17:18:27 2014 +0100
Committer: Sergey Beryozkin <sberyozkin@talend.com>
Committed: Tue Aug 19 17:18:27 2014 +0100

----------------------------------------------------------------------
 .../cxf/tools/wadlto/jaxrs/SourceGenerator.java | 57 ++++++++++++++------
 .../tools/wadlto/jaxrs/JAXRSContainerTest.java  |  3 ++
 .../jaxrs/src/test/resources/wadl/test.xml      |  2 +-
 3 files changed, 45 insertions(+), 17 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/81905456/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 f5e9ff7..0e927a3 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
@@ -751,13 +751,14 @@ public class SourceGenerator {
                 QName qname = convertToQName(id, expandedQName);
                 String packageName = possiblyConvertNamespaceURI(qname.getNamespaceURI(),
expandedQName);
                 
-                String clsSimpleName = getSchemaClassName(packageName, info.getGrammarInfo(),

+                String clsFullName = getSchemaClassName(packageName, info.getGrammarInfo(),

                         qname.getLocalPart(), info.getTypeClassNames());
-                String localName = clsSimpleName == null 
+                int lastDotIndex = clsFullName == null ? -1 : clsFullName.lastIndexOf(".");
+                String localName = clsFullName == null 
                     ? getClassName(qname.getLocalPart(), true, info.getTypeClassNames())

-                    : clsSimpleName.substring(packageName.length() + 1);
-                String subResponseNs = clsSimpleName == null ? getClassPackageName(packageName)

-                    : clsSimpleName.substring(0, packageName.length());
+                    : clsFullName.substring(lastDotIndex + 1);
+                String subResponseNs = clsFullName == null ? getClassPackageName(packageName)

+                    : clsFullName.substring(0, lastDotIndex);
                 Object parentNode = resourceEl.getParentNode();
                 String parentId = parentNode instanceof Element 
                     ? ((Element)parentNode).getAttribute("id")
@@ -1011,7 +1012,13 @@ public class SourceGenerator {
                 }
             }
             if (writeAnnotations(info.isInterfaceGenerated())) {
-                writeAnnotation(sbCode, imports, paramAnn, name, false, false);
+                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(')');
+                } else {
+                    writeAnnotation(sbCode, imports, paramAnn, name, false, false);
+                }
                 sbCode.append(" ");
                 String defaultVal = paramEl.getAttribute("default");
                 if (defaultVal.length() > 0) {
@@ -1019,7 +1026,7 @@ public class SourceGenerator {
                     sbCode.append(" ");    
                 }
             }
-            boolean isRepeating = Boolean.valueOf(paramEl.getAttribute("repeating"));
+            boolean isRepeating = isRepeatingParam(paramEl);
             String type = enumCreated ? getTypicalClassName(name)
                 : getPrimitiveType(paramEl, info, imports);
             if (OPTIONAL_PARAMS.contains(paramAnn)
@@ -1027,10 +1034,7 @@ public class SourceGenerator {
                 && AUTOBOXED_PRIMITIVES_MAP.containsKey(type)) {
                 type = AUTOBOXED_PRIMITIVES_MAP.get(type);
             }
-            if (isRepeating) {
-                addImport(imports, List.class.getName());
-                type = "List<" + type + ">";
-            }
+            type = addListIfRepeating(type, isRepeating, imports);
             String paramName;
             if (JavaUtils.isJavaKeyword(name)) {
                 paramName = name.concat("_arg");
@@ -1094,6 +1098,18 @@ public class SourceGenerator {
         }
     }
     
+    private boolean isRepeatingParam(Element paramEl) {
+        return Boolean.valueOf(paramEl.getAttribute("repeating"));
+    }
+    
+    private String addListIfRepeating(String type, boolean isRepeating, Set<String>
imports) {
+        if (isRepeating) {
+            addImport(imports, List.class.getName());
+            type = "List<" + type + ">";
+        }
+        return type;
+    }
+    
     private Class<?> getParamAnnotation(String paramStyle) {
         Class<?> paramAnn = PARAM_ANNOTATIONS.get(paramStyle);
         if (paramAnn == null) {
@@ -1214,7 +1230,7 @@ public class SourceGenerator {
             if (XSD_SPECIFIC_TYPE_MAP.containsKey(pair[1])) {
                 String expandedName = "{" + Constants.URI_2001_SCHEMA_XSD + "}" + pair[1];
                 if (schemaTypeMap.containsKey(expandedName)) {
-                    return checkGenericType(schemaTypeMap.get(expandedName));
+                    return addImportsAndGetSimpleName(imports, schemaTypeMap.get(expandedName));
                 }
                 
                 String xsdType = XSD_SPECIFIC_TYPE_MAP.get(pair[1]);
@@ -1256,13 +1272,21 @@ public class SourceGenerator {
     }
     
     private String addImportsAndGetSimpleName(Set<String> imports, String clsName)
{
+        String originalName = clsName;
+        int typeIndex = clsName.lastIndexOf("..");
+        if (typeIndex != -1) {
+            clsName = clsName.substring(0, typeIndex);
+        }
         addImport(imports, clsName);
         int index = clsName.lastIndexOf(".");
         
         if (index != -1) {
             clsName = clsName.substring(index + 1);
         }
-        return checkGenericType(clsName);
+        if (typeIndex != -1) {
+            clsName = clsName + "<" + originalName.substring(typeIndex + 2) + ">";
 
+        }
+        return clsName;
     }
     
     private String checkGenericType(String clsName) {
@@ -1302,9 +1326,10 @@ public class SourceGenerator {
                 return addImportsAndGetSimpleName(imports, mediaTypesMap.get(mediaType));
             }
             if (checkPrimitive) {
-                Element param = DOMUtils.getFirstChildWithName(repElement, getWadlNamespace(),
"param");
-                if (param != null) {
-                    return getPrimitiveType(param, info, imports);
+                Element paramEl = DOMUtils.getFirstChildWithName(repElement, getWadlNamespace(),
"param");
+                if (paramEl != null) {
+                    String type = getPrimitiveType(paramEl, info, imports);
+                    type = addListIfRepeating(type, isRepeatingParam(paramEl), imports);
                 }
             }
         }

http://git-wip-us.apache.org/repos/asf/cxf/blob/81905456/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 61ee5cd..a0416b8 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
@@ -98,6 +98,9 @@ public class JAXRSContainerTest extends ProcessorTestBase {
             context.put(WadlToolConstants.CFG_OUTPUTDIR, output.getCanonicalPath());
             context.put(WadlToolConstants.CFG_WADLURL, getLocation("/wadl/test.xml"));
             context.put(WadlToolConstants.CFG_COMPILE, "true");
+            context.put(WadlToolConstants.CFG_SCHEMA_TYPE_MAP, 
+                        "{http://www.w3.org/2001/XMLSchema}anyType=" 
+                        + "java.io.InputStream");
             context.put(WadlToolConstants.CFG_INHERIT_PARAMS, "true");
             
             container.setContext(context);

http://git-wip-us.apache.org/repos/asf/cxf/blob/81905456/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 6ee4988..b70b9ef 100644
--- a/tools/wadlto/jaxrs/src/test/resources/wadl/test.xml
+++ b/tools/wadlto/jaxrs/src/test/resources/wadl/test.xml
@@ -24,7 +24,7 @@
                 <method name="POST">
 	                <request>
 	                    <representation mediaType="text/plain">
-	                        <param name="id" style="plain" type="java.util.Date"/>
+	                        <param name="id" style="plain" type="xsd:anyType"/>
 	                    </representation>
 	                </request>
 	                <response>


Mime
View raw message