cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1179271 - in /cxf/trunk: rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/codegen/ 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...
Date Wed, 05 Oct 2011 15:39:35 GMT
Author: sergeyb
Date: Wed Oct  5 15:39:34 2011
New Revision: 1179271

URL: http://svn.apache.org/viewvc?rev=1179271&view=rev
Log:
[CXF-3797] Optional support for multiple in xml representations

Modified:
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/codegen/SourceGenerator.java
    cxf/trunk/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/WadlToolConstants.java
    cxf/trunk/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxrs/JAXRSContainer.java
    cxf/trunk/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxrs/jaxrs-toolspec.xml
    cxf/trunk/tools/wadlto/jaxrs/src/test/java/org/apache/cxf/tools/wadlto/jaxrs/JAXRSContainerTest.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=1179271&r1=1179270&r2=1179271&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
Wed Oct  5 15:39:34 2011
@@ -59,6 +59,7 @@ import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.MultivaluedMap;
 import javax.ws.rs.core.Response;
 import javax.xml.namespace.QName;
+import javax.xml.transform.Source;
 
 import org.w3c.dom.Element;
 import org.w3c.dom.NamedNodeMap;
@@ -103,6 +104,9 @@ public class SourceGenerator {
     private static final String DEFAULT_RESOURCE_NAME = "Resource";
     private static final String TAB = "    "; 
     
+    private static final List<String> HTTP_OK_STATUSES =
+        Arrays.asList(new String[] {"200", "201", "202", "203", "204"});
+    
     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;
@@ -154,6 +158,7 @@ public class SourceGenerator {
     private Map<String, String> schemaPackageMap = Collections.emptyMap();
     private Map<String, String> schemaTypesMap = Collections.emptyMap();
     private Bus bus;
+    private boolean supportMultipleXmlReps;
     
     public SourceGenerator() {
         this(Collections.<String, String>emptyMap());
@@ -163,6 +168,10 @@ public class SourceGenerator {
         this.properties = properties;
     }
     
+    public void setSupportMultipleXmlReps(boolean support) {
+        supportMultipleXmlReps = support;
+    }
+    
     private String getClassPackageName(String wadlPackageName) {
         if (resourcePackageName != null) {
             return resourcePackageName;
@@ -209,14 +218,12 @@ public class SourceGenerator {
     private void generateResourceClasses(Application app, GrammarInfo gInfo, 
                                          Set<String> typeClassNames, File src) {
         Element appElement = app.getAppElement();
-        List<Element> resourcesEls = DOMUtils.getChildrenWithName(appElement, 
-            WadlGenerator.WADL_NS, "resources");
+        List<Element> resourcesEls = getWadlElements(appElement, "resources");
         if (resourcesEls.size() != 1) {
             throw new IllegalStateException("WADL resources element is missing");
         }
         
-        List<Element> resourceEls = DOMUtils.getChildrenWithName(resourcesEls.get(0),

-            WadlGenerator.WADL_NS, "resource");
+        List<Element> resourceEls = getWadlElements(resourcesEls.get(0), "resource");
         if (resourceEls.size() == 0) {
             throw new IllegalStateException("WADL has no resource elements");
         }
@@ -250,9 +257,7 @@ public class SourceGenerator {
         if (type.length() > 0) {
             if (type.startsWith("#")) {
                 String refId = type.substring(1);
-                List<Element> resourceTypes = 
-                    DOMUtils.getChildrenWithName(app.getAppElement(), WadlGenerator.WADL_NS,

-                                                 "resource_type");
+                List<Element> resourceTypes = getWadlElements(app.getAppElement(),
"resource_type");
                 for (Element resourceType : resourceTypes) {
                     if (refId.equals(resourceType.getAttribute("id"))) {
                         Element realElement = (Element)resourceType.cloneNode(true);
@@ -386,8 +391,7 @@ public class SourceGenerator {
     private void writeSubresourceClasses(Application app, Element rElement, ContextInfo info,

             File src, boolean isRoot, String resourceId) {
 
-        List<Element> childEls = DOMUtils.getChildrenWithName(rElement, 
-            WadlGenerator.WADL_NS, "resource");
+        List<Element> childEls = getWadlElements(rElement, "resource");
         for (Element subEl : childEls) {
             String id = subEl.getAttribute("id");
             if (id.length() > 0 && !resourceId.equals(id) && !id.startsWith("{java")
@@ -464,15 +468,13 @@ public class SourceGenerator {
                               String resourceId,
                               boolean isRoot,
                               String currentPath) {
-        List<Element> methodEls = DOMUtils.getChildrenWithName(rElement, 
-            WadlGenerator.WADL_NS, "method");
+        List<Element> methodEls = getWadlElements(rElement, "method");
        
         for (Element methodEl : methodEls) {
             writeResourceMethod(methodEl, imports, sbCode, info, isRoot, currentPath);  
 
         }
         
-        List<Element> childEls = DOMUtils.getChildrenWithName(rElement, 
-                WadlGenerator.WADL_NS, "resource");
+        List<Element> childEls = getWadlElements(rElement, "resource");
         for (Element childEl : childEls) {
             String path = childEl.getAttribute("path");
             String newPath = (currentPath + path).replace("//", "/");
@@ -531,85 +533,112 @@ public class SourceGenerator {
         boolean isResourceElement = "resource".equals(methodEl.getLocalName());
         Element resourceEl = isResourceElement ? methodEl : (Element)methodEl.getParentNode();
         
-        String methodName = methodEl.getAttribute("name");
-        String methodNameLowerCase = methodName.toLowerCase();
-        String id = methodEl.getAttribute("id");
-        if (id.length() == 0) {
-            id = methodNameLowerCase;
-        }
-        
-        List<Element> responseEls = DOMUtils.getChildrenWithName(methodEl, 
-                                                                 WadlGenerator.WADL_NS, "response");
-        List<Element> requestEls = DOMUtils.getChildrenWithName(methodEl, 
-                                                                WadlGenerator.WADL_NS, "request");
+        List<Element> responseEls = getWadlElements(methodEl, "response");
+        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);
         
-        if (writeAnnotations(info.isInterfaceGenerated())) {
-            sbCode.append(TAB);
+        boolean jaxpSourceRequired = xmlRequestReps.size() > 1 && !supportMultipleXmlReps;
+        int numOfMethods = jaxpSourceRequired ? 1 : xmlRequestReps.size(); 
+        for (int i = 0; i < numOfMethods; i++) {
             
-            if (methodNameLowerCase.length() > 0) {
-                if (HTTP_METHOD_ANNOTATIONS.containsKey(methodNameLowerCase)) {
-                    writeAnnotation(sbCode, imports, 
-                                    HTTP_METHOD_ANNOTATIONS.get(methodNameLowerCase), null,
true, true);
-                } else {
-                    // TODO : write a custom annotation class name based on HttpMethod  
 
+            Element inXmlRep = xmlRequestReps.get(i);
+                        
+            String methodNameLowerCase = methodEl.getAttribute("name").toLowerCase();
+            String id = methodEl.getAttribute("id");
+            if (id.length() == 0) {
+                id = methodNameLowerCase;
+            }
+            String suffixName = "";
+            if (!jaxpSourceRequired && inXmlRep != null && xmlRequestReps.size()
> 1) {
+                String value = inXmlRep.getAttribute("element");
+                int index = value.indexOf(":");
+                suffixName = value.substring(index + 1);
+            }
+            if (writeAnnotations(info.isInterfaceGenerated())) {
+                sbCode.append(TAB);
+                
+                if (methodNameLowerCase.length() > 0) {
+                    if (HTTP_METHOD_ANNOTATIONS.containsKey(methodNameLowerCase)) {
+                        writeAnnotation(sbCode, imports, 
+                                        HTTP_METHOD_ANNOTATIONS.get(methodNameLowerCase),
null, true, true);
+                    } else {
+                        // TODO : write a custom annotation class name based on HttpMethod
   
+                    }
+                    writeFormatAnnotations(allRequestReps, sbCode, imports, true);
+                    writeFormatAnnotations(getWadlElements(getOKResponse(responseEls), "representation"),
+                            sbCode, imports, false);
+                }
+                if (!isRoot && !"/".equals(currentPath)) {
+                    writeAnnotation(sbCode, imports, Path.class, currentPath, true, true);
                 }
-                writeFormatAnnotations(firstRequestEl, 
-                        sbCode, imports, true);
-                writeFormatAnnotations(getOKResponse(responseEls), sbCode, imports, false);
+            } else {
+                sbCode.append(getLineSep()).append(TAB);
+            }
+            
+            if (!info.isInterfaceGenerated()) {
+                sbCode.append("public ");
             }
-            if (!isRoot && !"/".equals(currentPath)) {
-                writeAnnotation(sbCode, imports, Path.class, currentPath, true, true);
+            boolean responseTypeAvailable = true;
+            if (methodNameLowerCase.length() > 0) {
+                responseTypeAvailable = writeResponseType(responseEls, sbCode, imports,
+                        info.getTypeClassNames(), info.getGrammarInfo());
+                sbCode.append(id + suffixName);
+            } else {
+                boolean expandedQName = id.startsWith("{");
+                QName qname = convertToQName(id, expandedQName);
+                String packageName = possiblyConvertNamespaceURI(qname.getNamespaceURI(),
expandedQName);
+                
+                String clsSimpleName = getSchemaClassName(packageName, info.getGrammarInfo(),

+                        qname.getLocalPart(), info.getTypeClassNames());
+                String localName = clsSimpleName == null 
+                    ? getClassName(qname.getLocalPart(), true, info.getTypeClassNames())

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

+                    : clsSimpleName.substring(0, packageName.length());
+                String parentId = ((Element)resourceEl.getParentNode()).getAttribute("id");
+                writeSubResponseType(id.equals(parentId), subResponseNs, localName, 
+                        sbCode, imports);
+                
+                sbCode.append("get" + localName + suffixName);
             }
-        } else {
-            sbCode.append(getLineSep()).append(TAB);
-        }
-        
-        if (!info.isInterfaceGenerated()) {
-            sbCode.append("public ");
-        }
-        boolean responseTypeAvailable = true;
-        if (methodNameLowerCase.length() > 0) {
-            responseTypeAvailable = writeResponseType(responseEls, sbCode, imports,
-                    info.getTypeClassNames(), info.getGrammarInfo());
-            sbCode.append(id);
-        } else {
-            boolean expandedQName = id.startsWith("{");
-            QName qname = convertToQName(id, expandedQName);
-            String packageName = possiblyConvertNamespaceURI(qname.getNamespaceURI(), expandedQName);
             
-            String clsSimpleName = getSchemaClassName(packageName, info.getGrammarInfo(),

-                    qname.getLocalPart(), info.getTypeClassNames());
-            String localName = clsSimpleName == null 
-                ? getClassName(qname.getLocalPart(), true, info.getTypeClassNames()) 
-                : clsSimpleName.substring(packageName.length() + 1);
-            String subResponseNs = clsSimpleName == null ? getClassPackageName(packageName)

-                : clsSimpleName.substring(0, packageName.length());
-            String parentId = ((Element)resourceEl.getParentNode()).getAttribute("id");
-            writeSubResponseType(id.equals(parentId), subResponseNs, localName, sbCode, imports);
+            sbCode.append("(");
             
-            sbCode.append("get" + localName);
-        }
-        
-        sbCode.append("(");
-        
-        List<Element> inParamElements = getParameters(resourceEl, 
-                    !isRoot && !isResourceElement && resourceEl.getAttribute("id").length()
> 0);
-        
-        writeRequestTypes(firstRequestEl, inParamElements, sbCode, imports, info);
-        sbCode.append(")");
-        if (info.isInterfaceGenerated()) {
-            sbCode.append(";");
-        } else {
-            generateEmptyMethodBody(sbCode, responseTypeAvailable);
+            List<Element> inParamElements = getParameters(resourceEl, 
+                        !isRoot && !isResourceElement && resourceEl.getAttribute("id").length()
> 0);
+            
+            Element repElement = getActualRepElement(allRequestReps, inXmlRep); 
+            writeRequestTypes(firstRequestEl, repElement, inParamElements, 
+                    jaxpSourceRequired, sbCode, imports, info);
+            sbCode.append(")");
+            if (info.isInterfaceGenerated()) {
+                sbCode.append(";");
+            } else {
+                generateEmptyMethodBody(sbCode, responseTypeAvailable);
+            }
+            sbCode.append(getLineSep()).append(getLineSep());
         }
-        sbCode.append(getLineSep()).append(getLineSep());
     }
 
+    private List<Element> getXmlReps(List<Element> repElements) {
+        List<Element> xmlReps = new ArrayList<Element>();
+        for (Element el : repElements) {
+            String value = el.getAttribute("element");
+            if (value.length() > 0 && value.contains(":")) {
+                xmlReps.add(el);
+            }
+        }
+        if (xmlReps.isEmpty()) {
+            xmlReps.add(null);
+        }
+        return xmlReps;
+    }
+    
     private List<Element> getParameters(Element resourceEl, boolean isSubresourceMethod)
{
         List<Element> inParamElements = new LinkedList<Element>();
-        List<Element> allParamElements = DOMUtils.getChildrenWithName(resourceEl, 
-                                              WadlGenerator.WADL_NS, "param");
+        List<Element> allParamElements = getWadlElements(resourceEl, "param");
         for (Element el : allParamElements) {
             if (isSubresourceMethod && RESOURCE_LEVEL_PARAMS.contains(el.getAttribute("style")))
{
                 continue;
@@ -640,30 +669,41 @@ public class SourceGenerator {
     }
     
     private boolean addFormParameters(List<Element> inParamElements, Element requestEl)
{
-        List<Element> repElements = 
-            DOMUtils.getChildrenWithName(requestEl, WadlGenerator.WADL_NS, "representation");
+        List<Element> repElements = getWadlElements(requestEl, "representation");
  
         if (repElements.size() == 1) {
             String mediaType = repElements.get(0).getAttribute("mediaType");
             if (MediaType.APPLICATION_FORM_URLENCODED.equals(mediaType)) { 
-                inParamElements.addAll(DOMUtils.getChildrenWithName(repElements.get(0), 
-                                                                WadlGenerator.WADL_NS, "param"));
+                inParamElements.addAll(getWadlElements(repElements.get(0), "param"));
                 return true;
             }
         }
         return false;
     }
     
-    private boolean writeResponseType(List<Element> responseEls, StringBuilder sbCode,
-                                   Set<String> imports, Set<String> typeClassNames,

-                                   GrammarInfo gInfo) {
+    private Element getActualRepElement(List<Element> repElements, Element xmlElement)
{
+        if (xmlElement != null) {
+            return xmlElement;
+        }
+        for (Element el : repElements) {
+            Element param = DOMUtils.getFirstChildWithName(el, WadlGenerator.WADL_NS, "param");
+            if (param != null) {
+                return el;
+            }
+        }
+        return null;
+    }
+    
+    private boolean writeResponseType(List<Element> responseEls,
+                                      StringBuilder sbCode,
+                                      Set<String> imports, Set<String> typeClassNames,

+                                      GrammarInfo gInfo) {
         
         Element okResponse = getOKResponse(responseEls);
         
         List<Element> repElements = null;
         if (okResponse != null) {
-            repElements = 
-                DOMUtils.getChildrenWithName(okResponse, WadlGenerator.WADL_NS, "representation");
   
+            repElements = getWadlElements(okResponse, "representation");    
         } else {
             repElements = CastUtils.cast(Collections.emptyList(), Element.class);
         }
@@ -672,7 +712,9 @@ public class SourceGenerator {
             sbCode.append("void ");
             return false;
         }
-        String elementName = getElementRefName(repElements, typeClassNames, gInfo, imports);
+        String elementName = getElementRefName(
+                getActualRepElement(repElements, getXmlReps(repElements).get(0)),
+                typeClassNames, gInfo, imports);
         if (elementName != null) {
             sbCode.append(elementName + " ");
         } else {
@@ -685,10 +727,15 @@ public class SourceGenerator {
     private Element getOKResponse(List<Element> responseEls) {
         for (int i = 0; i < responseEls.size(); i++) {
             String statusValue = responseEls.get(i).getAttribute("status");
-            if (statusValue.length() == 0 
-                || Arrays.asList(statusValue.split("\\s")).contains("200")) {
+            if (statusValue.length() == 0) {
                 return responseEls.get(i);
             }
+            String[] statuses = statusValue.split("\\s");
+            for (String status : statuses) {
+                if (HTTP_OK_STATUSES.contains(status)) {
+                    return responseEls.get(i);
+                }
+            }
         }
         return null;
     }
@@ -700,9 +747,11 @@ public class SourceGenerator {
         }
         sbCode.append(localName).append(" ");
     }
-    
+        
     private void writeRequestTypes(Element requestEl,
+                                   Element repElement,
                                    List<Element> inParamEls, 
+                                   boolean jaxpRequired,
                                    StringBuilder sbCode, 
                                    Set<String> imports, 
                                    ContextInfo info) {
@@ -710,8 +759,7 @@ public class SourceGenerator {
         boolean form = false;
         boolean formParamsAvailable = false;
         if (requestEl != null) {
-            inParamEls.addAll(DOMUtils.getChildrenWithName(requestEl, 
-                 WadlGenerator.WADL_NS, "param"));
+            inParamEls.addAll(getWadlElements(requestEl, "param"));
             int currentSize = inParamEls.size();
             form = addFormParameters(inParamEls, requestEl);
             formParamsAvailable = currentSize < inParamEls.size(); 
@@ -751,15 +799,16 @@ public class SourceGenerator {
         String elementParamType = null;
         String elementParamName = null;
         if (!form) {
-            List<Element> repElements = requestEl != null 
-                ? DOMUtils.getChildrenWithName(requestEl, WadlGenerator.WADL_NS, "representation")
-                : CastUtils.cast(Collections.emptyList(), Element.class);
-            if (repElements.size() > 0) {    
-                elementParamType = getElementRefName(repElements, info.getTypeClassNames(),

-                        info.getGrammarInfo(), imports);
+            if (!jaxpRequired) {    
+                elementParamType = getElementRefName(repElement, 
+                        info.getTypeClassNames(), info.getGrammarInfo(), imports);
                 if (elementParamType != null) {
                     elementParamName = elementParamType.toLowerCase();
                 }
+            } else {
+                addImport(imports, Source.class.getName());
+                elementParamType = Source.class.getSimpleName();
+                elementParamName = "source";
             }
         } else if (!formParamsAvailable) {
             addImport(imports, MultivaluedMap.class.getName());
@@ -774,6 +823,12 @@ public class SourceGenerator {
         }
     }
     
+    private List<Element> getWadlElements(Element parent, String name) {
+        return parent != null 
+            ? DOMUtils.getChildrenWithName(parent, WadlGenerator.WADL_NS, name)
+            : CastUtils.cast(Collections.emptyList(), Element.class);
+    }
+    
     private String getPrimitiveType(Element paramEl) {
         String type = paramEl.getAttribute("type");
         if (type == null) {
@@ -784,17 +839,16 @@ public class SourceGenerator {
         return "string".equals(value) ? "String" : value;
     }
     
-    private String getElementRefName(List<Element> repElements, Set<String> typeClassNames,
-                                     GrammarInfo gInfo, Set<String> imports) {
-        String elementRef = null;
-        for (Element el : repElements) {
-            String value = el.getAttribute("element");
-            if (value.length() > 0) {
-                elementRef = value;
-                break;
-            }
+    private String getElementRefName(Element repElement,
+                                     Set<String> typeClassNames,
+                                     GrammarInfo gInfo, 
+                                     Set<String> imports) {
+        if (repElement == null) {
+            return null;
         }
-        if (elementRef != null) {
+        String elementRef = repElement.getAttribute("element");
+        
+        if (elementRef.length() > 0) {
             String[] pair = elementRef.split(":");
             if (pair.length == 2) {
                 String namespace = gInfo != null ? gInfo.getNsMap().get(pair[0]) : null;
@@ -814,12 +868,10 @@ public class SourceGenerator {
                 }
             }
         } else {
-            for (Element el : repElements) {
-                Element param = DOMUtils.getFirstChildWithName(el, WadlGenerator.WADL_NS,
"param");
-                if (param != null) {
-                    return getPrimitiveType(param);
-                }
-            }    
+            Element param = DOMUtils.getFirstChildWithName(repElement, WadlGenerator.WADL_NS,
"param");
+            if (param != null) {
+                return getPrimitiveType(param);
+            }
         }
         return null;
     }
@@ -852,11 +904,8 @@ public class SourceGenerator {
     
     
     
-    private void writeFormatAnnotations(Element parentEl, StringBuilder sbCode, 
+    private void writeFormatAnnotations(List<Element> repElements, StringBuilder sbCode,

                                         Set<String> imports, boolean inRep) {
-        List<Element> repElements = parentEl != null 
-            ? DOMUtils.getChildrenWithName(parentEl, WadlGenerator.WADL_NS, "representation")
-            : CastUtils.cast(Collections.emptyList(), Element.class);
         if (repElements.size() == 0) {    
             return;
         }
@@ -866,15 +915,19 @@ public class SourceGenerator {
         if (repElements.size() > 1) {
             sbCode.append("{");
         }
+        String mediaTypes = "";
+        boolean first = true;
         for (int i = 0; i < repElements.size(); i++) {
             String mediaType = repElements.get(i).getAttribute("mediaType");
-            if (mediaType != null) {
-                sbCode.append("\"" + mediaType + "\"");
-                if (i + 1 < repElements.size()) { 
-                    sbCode.append(", ");
+            if (mediaType != null && !mediaTypes.contains(mediaType)) {
+                if (!first) { 
+                    mediaTypes += ", ";
                 }
+                first = false;
+                mediaTypes += "\"" + mediaType + "\"";
             }
         }
+        sbCode.append(mediaTypes);
         if (repElements.size() > 1) {
             sbCode.append(" }");
         }
@@ -930,8 +983,7 @@ public class SourceGenerator {
     }
 
     private List<SchemaInfo> getSchemaElements(Application app) {
-        List<Element> grammarEls = DOMUtils.getChildrenWithName(app.getAppElement(),

-                                                                WadlGenerator.WADL_NS, "grammars");
+        List<Element> grammarEls = getWadlElements(app.getAppElement(), "grammars");
         if (grammarEls.size() != 1) {
             return null;
         }
@@ -946,8 +998,7 @@ public class SourceGenerator {
             }
             schemas.add(createSchemaInfo(schemasEls.get(i), systemId));
         }
-        List<Element> includeEls = DOMUtils.getChildrenWithName(grammarEls.get(0),

-             WadlGenerator.WADL_NS, "include");
+        List<Element> includeEls = getWadlElements(grammarEls.get(0), "include");
         for (Element includeEl : includeEls) {
             String href = includeEl.getAttribute("href");
             

Modified: cxf/trunk/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/WadlToolConstants.java
URL: http://svn.apache.org/viewvc/cxf/trunk/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/WadlToolConstants.java?rev=1179271&r1=1179270&r2=1179271&view=diff
==============================================================================
--- cxf/trunk/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/WadlToolConstants.java
(original)
+++ cxf/trunk/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/WadlToolConstants.java
Wed Oct  5 15:39:34 2011
@@ -37,6 +37,8 @@ public final class WadlToolConstants {
     public static final String CFG_SCHEMA_PACKAGENAME = "schemaPackagename";
     public static final String CFG_RESOURCENAME = "resourcename";
     
+    public static final String CFG_MULTIPLE_XML_REPS = "supportMultipleXmlReps";
+    
     public static final String CFG_CATALOG = ToolConstants.CFG_CATALOG;
     public static final String CFG_BINDING = ToolConstants.CFG_BINDING;
     

Modified: cxf/trunk/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxrs/JAXRSContainer.java
URL: http://svn.apache.org/viewvc/cxf/trunk/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxrs/JAXRSContainer.java?rev=1179271&r1=1179270&r2=1179271&view=diff
==============================================================================
--- cxf/trunk/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxrs/JAXRSContainer.java
(original)
+++ cxf/trunk/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxrs/JAXRSContainer.java
Wed Oct  5 15:39:34 2011
@@ -117,6 +117,7 @@ public class JAXRSContainer extends Abst
         sg.setPackageName((String)context.get(WadlToolConstants.CFG_PACKAGENAME));
         sg.setResourceName((String)context.get(WadlToolConstants.CFG_RESOURCENAME));
 
+        sg.setSupportMultipleXmlReps(context.optionSet(WadlToolConstants.CFG_MULTIPLE_XML_REPS));
         // set the base path
         sg.setWadlPath(wadlURL);
                 

Modified: cxf/trunk/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxrs/jaxrs-toolspec.xml
URL: http://svn.apache.org/viewvc/cxf/trunk/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxrs/jaxrs-toolspec.xml?rev=1179271&r1=1179270&r2=1179271&view=diff
==============================================================================
--- cxf/trunk/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxrs/jaxrs-toolspec.xml
(original)
+++ cxf/trunk/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxrs/jaxrs-toolspec.xml
Wed Oct  5 15:39:34 2011
@@ -137,6 +137,18 @@ Examples:
                 <switch>noAddressBinding</switch>
             </option>
             
+            <option id="supportMultipleXmlReps" maxOccurs="1">
+                <annotation>
+                    Specifies that if a method contains multiple request XML representations
+                    then a separate method per every such representation will be generated.
+                    Note, enabling this option is not recommended when a server-side JAX-RS
+                    code is generated.
+                    A single method containing a javax.xml.transform.Source input parameter
+                    will be generated by default such cases.   
+                </annotation>
+                <switch>supportMultipleXmlReps</switch>
+            </option>
+            
 <!-- 
 
 TODO: consider implementing most of the following options

Modified: cxf/trunk/tools/wadlto/jaxrs/src/test/java/org/apache/cxf/tools/wadlto/jaxrs/JAXRSContainerTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/tools/wadlto/jaxrs/src/test/java/org/apache/cxf/tools/wadlto/jaxrs/JAXRSContainerTest.java?rev=1179271&r1=1179270&r2=1179271&view=diff
==============================================================================
--- cxf/trunk/tools/wadlto/jaxrs/src/test/java/org/apache/cxf/tools/wadlto/jaxrs/JAXRSContainerTest.java
(original)
+++ cxf/trunk/tools/wadlto/jaxrs/src/test/java/org/apache/cxf/tools/wadlto/jaxrs/JAXRSContainerTest.java
Wed Oct  5 15:39:34 2011
@@ -55,6 +55,31 @@ public class JAXRSContainerTest extends 
             fail();
         }
     }
+    
+    @Test    
+    public void testCodeGenInterfacesMultipleInXmlReps() {
+        try {
+            JAXRSContainer container = new JAXRSContainer(null);
+
+            ToolContext context = new ToolContext();
+            context.put(WadlToolConstants.CFG_OUTPUTDIR, output.getCanonicalPath());
+            context.put(WadlToolConstants.CFG_WADLURL, getLocation("/wadl/bookstore.xml"));
+            context.put(WadlToolConstants.CFG_COMPILE, "true");
+            context.put(WadlToolConstants.CFG_MULTIPLE_XML_REPS, "true");
+
+            container.setContext(context);
+            container.execute();
+
+            assertNotNull(output.list());
+            
+            verifyFiles("java", true, false, "superbooks", "org.apache.cxf.jaxrs.model.wadl",
10);
+            verifyFiles("class", true, false, "superbooks", "org.apache.cxf.jaxrs.model.wadl",
10);
+            
+        } catch (Exception e) {
+            e.printStackTrace();
+            fail();
+        }
+    }
         
     @Test    
     public void testCodeGenInterfacesWithBinding() {

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=1179271&r1=1179270&r2=1179271&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 Wed Oct  5 15:39:34
2011
@@ -118,6 +118,15 @@
       </response>
      </method>
 
+     <method name="POST" id="addBookOrBook2">
+      <request>
+       <representation mediaType="application/xml" element="prefix1:thebook"/>
+       <representation mediaType="application/xml" element="prefix1:theBook2"/>
+       <representation mediaType="application/json"/>
+      </request>
+      <response status="201"/>
+     </method>
+
      <method name="PUT" id="addBook">
       <doc>Update the book</doc>
       <request>



Mime
View raw message