cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1174385 - in /cxf/branches/2.4.x-fixes: ./ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/codegen/ tools/wadlto/jaxrs/src/test/java/org/apache/cxf/tools/wadlto/jaxrs/ tools/wadlto/jaxrs/src/test/resources/wadl/
Date Thu, 22 Sep 2011 20:53:36 GMT
Author: sergeyb
Date: Thu Sep 22 20:53:36 2011
New Revision: 1174385

URL: http://svn.apache.org/viewvc?rev=1174385&view=rev
Log:
Merged revisions 1173863,1173868,1173871,1174109,1174210 via svnmerge from 
https://svn.apache.org/repos/asf/cxf/trunk

........
  r1173863 | sergeyb | 2011-09-21 22:14:33 +0100 (Wed, 21 Sep 2011) | 1 line
  
  [CXF-3797] Applying most of the patch from Christos Fragoulides with some modifications
........
  r1173868 | sergeyb | 2011-09-21 22:18:33 +0100 (Wed, 21 Sep 2011) | 1 line
  
  [CXF-3797] Removing a ref to rackspace.wadl
........
  r1173871 | sergeyb | 2011-09-21 22:20:15 +0100 (Wed, 21 Sep 2011) | 1 line
  
  [CXF-3797] Really removing a ref to rackspace.wadl
........
  r1174109 | sergeyb | 2011-09-22 14:04:47 +0100 (Thu, 22 Sep 2011) | 1 line
  
  [CXF-3797] More fixes from Christos Fragoulides with updates
........
  r1174210 | sergeyb | 2011-09-22 16:34:55 +0100 (Thu, 22 Sep 2011) | 1 line
  
  [CXF-3797] Referencing element declarations found in xs:include schemas
........

Modified:
    cxf/branches/2.4.x-fixes/   (props changed)
    cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/codegen/SourceGenerator.java
    cxf/branches/2.4.x-fixes/tools/wadlto/jaxrs/src/test/java/org/apache/cxf/tools/wadlto/jaxrs/JAXRSContainerTest.java
    cxf/branches/2.4.x-fixes/tools/wadlto/jaxrs/src/test/java/org/apache/cxf/tools/wadlto/jaxrs/WADLToJavaTest.java
    cxf/branches/2.4.x-fixes/tools/wadlto/jaxrs/src/test/resources/wadl/bookstore.xml
    cxf/branches/2.4.x-fixes/tools/wadlto/jaxrs/src/test/resources/wadl/bookstoreImport.xml
    cxf/branches/2.4.x-fixes/tools/wadlto/jaxrs/src/test/resources/wadl/singleResource.xml

Propchange: cxf/branches/2.4.x-fixes/
------------------------------------------------------------------------------
    svn:mergeinfo = /cxf/trunk:1173863-1173871,1174109,1174210

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

Modified: cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/codegen/SourceGenerator.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/codegen/SourceGenerator.java?rev=1174385&r1=1174384&r2=1174385&view=diff
==============================================================================
--- cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/codegen/SourceGenerator.java
(original)
+++ cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/codegen/SourceGenerator.java
Thu Sep 22 20:53:36 2011
@@ -29,6 +29,7 @@ import java.io.StringReader;
 import java.net.URI;
 import java.net.URL;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.Collections;
 import java.util.Comparator;
 import java.util.HashMap;
@@ -62,10 +63,10 @@ import javax.xml.namespace.QName;
 import org.w3c.dom.Element;
 import org.w3c.dom.NamedNodeMap;
 import org.w3c.dom.Node;
+
 import org.xml.sax.InputSource;
 import org.xml.sax.SAXParseException;
 
-
 import org.apache.cxf.Bus;
 import org.apache.cxf.catalog.OASISCatalogManager;
 import org.apache.cxf.catalog.OASISCatalogManagerHelper;
@@ -186,7 +187,7 @@ public class SourceGenerator {
                 generateClassesFromSchema(codeModel, srcDir);
             }
         }
-        return getGrammarInfo(app.getAppElement(), schemaElements);
+        return getGrammarInfo(app, schemaElements);
     }
     
     private void generateResourceClasses(Application app, GrammarInfo gInfo, 
@@ -207,9 +208,13 @@ public class SourceGenerator {
         for (int i = 0; i < resourceEls.size(); i++) {
             Element resource = getResourceElement(app, resourceEls.get(i), gInfo, typeClassNames,

                                                   resourceEls.get(i).getAttribute("type"),
src);
-            writeResourceClass(app, resource, typeClassNames, gInfo, src, true, generateInterfaces);
+            writeResourceClass(app, resource, 
+                               new ContextInfo(typeClassNames, gInfo, generateInterfaces),

+                               src, true);
             if (generateInterfaces && generateImpl) {
-                writeResourceClass(app, resource, typeClassNames, gInfo, src, true, false);
+                writeResourceClass(app, resource, 
+                                   new ContextInfo(typeClassNames, gInfo, false), 
+                                   src, true);
             }
             if (resourceName != null) {
                 break;
@@ -259,14 +264,14 @@ public class SourceGenerator {
         
     }
     
-    private GrammarInfo getGrammarInfo(Element appElement, List<SchemaInfo> schemaElements)
{
+    private GrammarInfo getGrammarInfo(Application app, List<SchemaInfo> schemaElements)
{
         
         if (schemaElements == null || schemaElements.isEmpty()) {
             return new GrammarInfo();
         }
         
         Map<String, String> nsMap = new HashMap<String, String>();
-        NamedNodeMap attrMap = appElement.getAttributes();
+        NamedNodeMap attrMap = app.getAppElement().getAttributes();
         for (int i = 0; i < attrMap.getLength(); i++) {
             Node node = attrMap.item(i);
             String nodeName = node.getNodeName();
@@ -277,26 +282,40 @@ public class SourceGenerator {
         }
         Map<String, String> elementTypeMap = new HashMap<String, String>();
         for (SchemaInfo schemaEl : schemaElements) {
-            List<Element> elementEls = DOMUtils.getChildrenWithName(schemaEl.getElement(),

-                 XmlSchemaConstants.XSD_NAMESPACE_URI, "element");
-            for (Element el : elementEls) {
-                String type = el.getAttribute("type");
-                if (type.length() > 0) {
-                    String[] pair = type.split(":");
-                    elementTypeMap.put(el.getAttribute("name"), pair.length == 1 ? pair[0]
: pair[1]);
-                }
-            }
+            populateElementTypeMap(app, schemaEl.getElement(), schemaEl.getSystemId(), elementTypeMap);
         }
         return new GrammarInfo(nsMap, elementTypeMap);
     }
     
+    private void populateElementTypeMap(Application app, Element schemaEl, 
+            String systemId, Map<String, String> elementTypeMap) {
+        List<Element> elementEls = DOMUtils.getChildrenWithName(schemaEl, 
+                XmlSchemaConstants.XSD_NAMESPACE_URI, "element");
+        for (Element el : elementEls) {
+            String type = el.getAttribute("type");
+            if (type.length() > 0) {
+                String[] pair = type.split(":");
+                elementTypeMap.put(el.getAttribute("name"), pair.length == 1 ? pair[0] :
pair[1]);
+            }
+        }
+        Element includeEl = DOMUtils.getFirstChildWithName(schemaEl, 
+                XmlSchemaConstants.XSD_NAMESPACE_URI, "include");
+        if (includeEl != null) {
+            int ind = systemId.lastIndexOf("/");
+            if (ind != -1) {
+                String schemaURI = systemId.substring(0, ind + 1) + includeEl.getAttribute("schemaLocation");
+                populateElementTypeMap(app, readIncludedDocument(schemaURI), schemaURI, elementTypeMap);
+            }
+        }
+    }
+    
     public void generateMainClass(Element resourcesEl, File src) {
         
     }
     
-    private void writeResourceClass(Application app, Element rElement, Set<String>
typeClassNames, 
-                                    GrammarInfo gInfo, File src, boolean isRoot,
-                                    boolean interfaceIsGenerated) {
+    private void writeResourceClass(Application app, Element rElement,
+                                    ContextInfo info, 
+                                    File src, boolean isRoot) {
         String resourceId = resourceName != null 
             ? resourceName : rElement.getAttribute("id");
         if (resourceId.length() == 0) {
@@ -306,56 +325,62 @@ public class SourceGenerator {
         QName qname = convertToQName(resourceId, expandedQName);
         String namespaceURI = possiblyConvertNamespaceURI(qname.getNamespaceURI(), expandedQName);
         
-        if (getSchemaClassName(namespaceURI, gInfo, qname.getLocalPart(), typeClassNames)
!= null) {
+        if (getSchemaClassName(namespaceURI, info.getGrammarInfo(), qname.getLocalPart(),

+                              info.getTypeClassNames()) != null) {
             return; 
         }
         
+        
+        final String className = getClassName(qname.getLocalPart(), 
+                info.isInterfaceGenerated(), info.getTypeClassNames());
+        if (info.getResourceClassNames().contains(className)) {
+            return;
+        }
+        info.getResourceClassNames().add(className);
+        final String classPackage = getClassPackageName(namespaceURI);
+        
         StringBuilder sbImports = new StringBuilder();
         StringBuilder sbCode = new StringBuilder();
         Set<String> imports = createImports();
         
-        final String classPackage = getClassPackageName(namespaceURI);
-        final String className = getClassName(qname.getLocalPart(), interfaceIsGenerated);
         
         sbImports.append(getClassComment()).append(getLineSep());
         sbImports.append("package " + classPackage)
             .append(";").append(getLineSep()).append(getLineSep());
         
-        if (isRoot && writeAnnotations(interfaceIsGenerated)) {
+        if (isRoot && writeAnnotations(info.isInterfaceGenerated())) {
             String path = rElement.getAttribute("path");
             writeAnnotation(sbCode, imports, Path.class, path, true, false);
         }
                 
-        sbCode.append("public " + getClassType(interfaceIsGenerated) + " " + className);
-        writeImplementsInterface(sbCode, qname.getLocalPart(), interfaceIsGenerated);   
          
+        sbCode.append("public " + getClassType(info.interfaceIsGenerated) + " " + className);
+        writeImplementsInterface(sbCode, qname.getLocalPart(), info.isInterfaceGenerated());
             
         sbCode.append(" {" + getLineSep() + getLineSep());
         
-        writeMethods(rElement, imports, sbCode, typeClassNames, gInfo, isRoot, interfaceIsGenerated);
+        writeMethods(rElement, imports, sbCode, info, resourceId, isRoot, "");
         
-        List<Element> childEls = DOMUtils.getChildrenWithName(rElement, 
-            WadlGenerator.WADL_NS, "resource");
-        for (Element childEl : childEls) {
-            if (childEl.getAttribute("id").length() == 0) {
-                writeMethods(childEl, imports, sbCode, typeClassNames, gInfo, false, interfaceIsGenerated);
-            } else {
-                writeResourceMethod(childEl, imports, sbCode, typeClassNames, gInfo, 
-                                    false, interfaceIsGenerated);
-            }
-        }
         sbCode.append("}");
         writeImports(sbImports, imports, classPackage);
         
         createJavaSourceFile(src, new QName(classPackage, className), sbCode, sbImports);
         
+        writeSubresourceClasses(app, rElement, info, src, isRoot, resourceId);
+    }
+    
+    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");
         for (Element subEl : childEls) {
             String id = subEl.getAttribute("id");
             if (id.length() > 0 && !resourceId.equals(id) && !id.startsWith("{java")
                 && !id.startsWith("java")) {
-                writeResourceClass(app, 
-                                   getResourceElement(app, subEl, gInfo, typeClassNames,

-                                                      subEl.getAttribute("type"), src), 
-                                   typeClassNames, gInfo, src, false, interfaceIsGenerated);
+                Element subElement = getResourceElement(app, subEl, info.getGrammarInfo(),

+                    info.getTypeClassNames(), subEl.getAttribute("type"), src);
+                writeResourceClass(app, subElement, info, src, false);
             }
+            writeSubresourceClasses(app, subEl, info, src, false, id);
         }
     }
     
@@ -376,13 +401,24 @@ public class SourceGenerator {
         return interfaceIsGenerated ? "interface" : "class";
     }
     
-    private String getClassName(String clsName, boolean interfaceIsGenerated) {
+    private String getClassName(String clsName, boolean interfaceIsGenerated, Set<String>
typeClassNames) {
+        String name = null;
         if (interfaceIsGenerated) {
-            return clsName;
+            name = clsName;
         } else {
-            return generateInterfaces ? clsName + "Impl" : clsName;
+            name = generateInterfaces ? clsName + "Impl" : clsName;
         }
-        
+        StringBuilder sb = new StringBuilder();
+        sb.append(Character.toUpperCase(name.charAt(0)));
+        name = name.length() > 1 ? sb.append(name.substring(1)).toString() : sb.toString();
+        for (String typeName : typeClassNames) {
+            String localName = typeName.contains(".") 
+                ? typeName.substring(typeName.lastIndexOf('.') + 1) : typeName;
+            if (name.equalsIgnoreCase(localName)) {
+                name += "Resource";
+            }
+        }
+        return name;
     }
     
     private boolean writeAnnotations(boolean interfaceIsGenerated) {
@@ -408,15 +444,28 @@ public class SourceGenerator {
     
     private void writeMethods(Element rElement,  
                               Set<String> imports, StringBuilder sbCode, 
-                              Set<String> typeClassNames, GrammarInfo gInfo,
+                              ContextInfo info,
+                              String resourceId,
                               boolean isRoot,
-                              boolean interfaceIsGenerated) {
+                              String currentPath) {
         List<Element> methodEls = DOMUtils.getChildrenWithName(rElement, 
             WadlGenerator.WADL_NS, "method");
        
         for (Element methodEl : methodEls) {
-            writeResourceMethod(methodEl, imports, sbCode, typeClassNames, gInfo, 
-                                isRoot, interfaceIsGenerated);    
+            writeResourceMethod(methodEl, imports, sbCode, info, isRoot, currentPath);  
 
+        }
+        
+        List<Element> childEls = DOMUtils.getChildrenWithName(rElement, 
+                WadlGenerator.WADL_NS, "resource");
+        for (Element childEl : childEls) {
+            String path = childEl.getAttribute("path");
+            String newPath = (currentPath + path).replace("//", "/");
+            String id = childEl.getAttribute("id");
+            if (id.length() == 0) {
+                writeMethods(childEl, imports, sbCode, info, id, false, newPath);
+            } else {
+                writeResourceMethod(childEl, imports, sbCode, info, false, newPath);
+            }
         }
     }
     
@@ -458,10 +507,11 @@ public class SourceGenerator {
     }
     
     private void writeResourceMethod(Element methodEl, 
-                                     Set<String> imports, StringBuilder sbCode, 
-                                     Set<String> typeClassNames, GrammarInfo gInfo,
+                                     Set<String> imports,
+                                     StringBuilder sbCode,
+                                     ContextInfo info,
                                      boolean isRoot,
-                                     boolean interfaceIsGenerated) {
+                                     String currentPath) {
         Element resourceEl = "resource".equals(methodEl.getLocalName()) 
             ? methodEl : (Element)methodEl.getParentNode();
         
@@ -476,9 +526,9 @@ public class SourceGenerator {
                                                                  WadlGenerator.WADL_NS, "response");
         List<Element> requestEls = DOMUtils.getChildrenWithName(methodEl, 
                                                                 WadlGenerator.WADL_NS, "request");
+        Element firstRequestEl = requestEls.size() >= 1 ? requestEls.get(0) : null;
         
-        
-        if (writeAnnotations(interfaceIsGenerated)) {
+        if (writeAnnotations(info.isInterfaceGenerated())) {
             sbCode.append(TAB);
             
             if (methodNameLowerCase.length() > 0) {
@@ -488,41 +538,40 @@ public class SourceGenerator {
                 } else {
                     // TODO : write a custom annotation class name based on HttpMethod  
 
                 }
-                writeFormatAnnotations(requestEls, sbCode, imports, true);
-                writeFormatAnnotations(responseEls, sbCode, imports, false);
+                writeFormatAnnotations(firstRequestEl, 
+                        sbCode, imports, true);
+                writeFormatAnnotations(getOKResponse(responseEls), sbCode, imports, false);
             }
-            if (!isRoot) {
-                String path = resourceEl.getAttribute("path");
-                writeAnnotation(sbCode, imports, Path.class, path, true, true);
+            if (!isRoot && !"/".equals(currentPath)) {
+                writeAnnotation(sbCode, imports, Path.class, currentPath, true, true);
             }
         } else {
             sbCode.append(getLineSep()).append(TAB);
         }
         
-        if (!interfaceIsGenerated) {
+        if (!info.isInterfaceGenerated()) {
             sbCode.append("public ");
         }
         boolean responseTypeAvailable = true;
         if (methodNameLowerCase.length() > 0) {
-            responseTypeAvailable = writeResponseType(responseEls, sbCode, imports, typeClassNames,
gInfo);
+            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, gInfo, qname.getLocalPart(),

-                                                      typeClassNames);
-            String localName = clsSimpleName == null ? qname.getLocalPart() 
+            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);
             
-            // TODO : we need to take care of multiple subresource locators with diff @Path
-            // returning the same type; also we might have ids like "{org.apache.cxf}Book#getName"

-            
             sbCode.append("get" + localName);
         }
         
@@ -530,10 +579,9 @@ public class SourceGenerator {
         List<Element> inParamElements = new LinkedList<Element>();
         inParamElements.addAll(DOMUtils.getChildrenWithName(resourceEl, 
                                                             WadlGenerator.WADL_NS, "param"));
-        writeRequestTypes(requestEls, inParamElements, sbCode, imports, typeClassNames, gInfo,
-                          interfaceIsGenerated);
+        writeRequestTypes(firstRequestEl, inParamElements, sbCode, imports, info);
         sbCode.append(")");
-        if (interfaceIsGenerated) {
+        if (info.isInterfaceGenerated()) {
             sbCode.append(";");
         } else {
             generateEmptyMethodBody(sbCode, responseTypeAvailable);
@@ -578,29 +626,17 @@ public class SourceGenerator {
     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 (responseEls.size() >= 1) {
-            Element okResponse = null;
-            if (responseEls.size() > 1) {
-                for (int i = 0; i < responseEls.size(); i++) {
-                    String statusValue = responseEls.get(i).getAttribute("status");
-                    try {
-                        int status = statusValue.length() == 0 ? 200 : Integer.valueOf(statusValue);
-                        if (status == 200) {
-                            okResponse = responseEls.get(i);
-                            break;
-                        }
-                    } catch (NumberFormatException ex) {
-                        // ignore
-                    }
-                }
-            } else {
-                okResponse = responseEls.get(0);
-            }
-            repElements = DOMUtils.getChildrenWithName(okResponse, WadlGenerator.WADL_NS,
"representation");
+        if (okResponse != null) {
+            repElements = 
+                DOMUtils.getChildrenWithName(okResponse, WadlGenerator.WADL_NS, "representation");
   
         } else {
             repElements = CastUtils.cast(Collections.emptyList(), Element.class);
         }
+        
         if (repElements.size() == 0) {    
             sbCode.append("void ");
             return false;
@@ -615,6 +651,17 @@ public class SourceGenerator {
         return true;
     }
     
+    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")) {
+                return responseEls.get(i);
+            }
+        }
+        return null;
+    }
+    
     private void writeSubResponseType(boolean recursive, String ns, String localName,
                                       StringBuilder sbCode, Set<String> imports) {
         if (!recursive && ns.length() > 0) {
@@ -623,25 +670,23 @@ public class SourceGenerator {
         sbCode.append(localName).append(" ");
     }
     
-    private void writeRequestTypes(List<Element> requestEls,
+    private void writeRequestTypes(Element requestEl,
                                    List<Element> inParamEls, 
                                    StringBuilder sbCode, 
                                    Set<String> imports, 
-                                   Set<String> typeClassNames, 
-                                   GrammarInfo gInfo,
-                                   boolean interfaceIsGenerated) {
+                                   ContextInfo info) {
         
         boolean form = false;
-        boolean formParamsAvailbale = false;
-        if (requestEls.size() == 1 && inParamEls.size() == 0) {
-            inParamEls.addAll(DOMUtils.getChildrenWithName(requestEls.get(0), 
+        boolean formParamsAvailable = false;
+        if (requestEl != null) {
+            inParamEls.addAll(DOMUtils.getChildrenWithName(requestEl, 
                  WadlGenerator.WADL_NS, "param"));
             int currentSize = inParamEls.size();
-            form = addFormParameters(inParamEls, requestEls.get(0));
-            formParamsAvailbale = currentSize < inParamEls.size(); 
+            form = addFormParameters(inParamEls, requestEl);
+            formParamsAvailable = currentSize < inParamEls.size(); 
         }
                   
-        if (form && !formParamsAvailbale) {
+        if (form && !formParamsAvailable) {
             addImport(imports, MultivaluedMap.class.getName());
             sbCode.append("MultivaluedMap map");
         } 
@@ -650,7 +695,7 @@ public class SourceGenerator {
             Element paramEl = inParamEls.get(i);
 
             String name = paramEl.getAttribute("name");
-            if (writeAnnotations(interfaceIsGenerated)) {
+            if (writeAnnotations(info.isInterfaceGenerated())) {
                 Class<?> paramAnnotation = form ? FormParam.class 
                     : PARAM_ANNOTATIONS.get(paramEl.getAttribute("style"));
                 writeAnnotation(sbCode, imports, paramAnnotation, name, false, false);
@@ -661,7 +706,7 @@ public class SourceGenerator {
                 addImport(imports, List.class.getName());
                 type = "List<" + type + ">";
             }
-            sbCode.append(type).append(" ").append(name.replace('.', '_'));
+            sbCode.append(type).append(" ").append(name.replaceAll("[\\.\\-]", "_"));
             if (i + 1 < inParamEls.size()) {
                 sbCode.append(", ");
                 if (i + 1 >= 4 && ((i + 1) % 4) == 0) {
@@ -672,11 +717,12 @@ public class SourceGenerator {
         if (!form) {
             String elementName = null;
             
-            List<Element> repElements = requestEls.size() == 1 
-                ? DOMUtils.getChildrenWithName(requestEls.get(0), WadlGenerator.WADL_NS,
"representation")
+            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, typeClassNames, gInfo, imports);
+                elementName = getElementRefName(repElements, info.getTypeClassNames(), 
+                        info.getGrammarInfo(), imports);
             }
             if (elementName != null) {
                 if (inParamEls.size() > 0) {
@@ -727,6 +773,13 @@ public class SourceGenerator {
                     }
                 }
             }
+        } else {
+            for (Element el : repElements) {
+                Element param = DOMUtils.getFirstChildWithName(el, WadlGenerator.WADL_NS,
"param");
+                if (param != null) {
+                    return getPrimitiveType(param);
+                }
+            }    
         }
         return null;
     }
@@ -759,10 +812,10 @@ public class SourceGenerator {
     
     
     
-    private void writeFormatAnnotations(List<Element> parentEls, StringBuilder sbCode,

+    private void writeFormatAnnotations(Element parentEl, StringBuilder sbCode, 
                                         Set<String> imports, boolean inRep) {
-        List<Element> repElements = parentEls.size() == 1 
-            ? DOMUtils.getChildrenWithName(parentEls.get(0), WadlGenerator.WADL_NS, "representation")
+        List<Element> repElements = parentEl != null 
+            ? DOMUtils.getChildrenWithName(parentEl, WadlGenerator.WADL_NS, "representation")
             : CastUtils.cast(Collections.emptyList(), Element.class);
         if (repElements.size() == 0) {    
             return;
@@ -1109,4 +1162,31 @@ public class SourceGenerator {
             return wadlPath;
         }
     }
+    
+    private static class ContextInfo {
+        private boolean interfaceIsGenerated;
+        private Set<String> typeClassNames;
+        private GrammarInfo gInfo;
+        private Set<String> resourceClassNames = new HashSet<String>();
+        
+        public ContextInfo(Set<String> typeClassNames, GrammarInfo gInfo, boolean interfaceIsGenerated)
{
+            this.interfaceIsGenerated = interfaceIsGenerated;
+            this.typeClassNames = typeClassNames;
+            this.gInfo = gInfo;
+        }
+        public boolean isInterfaceGenerated() {
+            return interfaceIsGenerated;
+        }
+        public Set<String> getTypeClassNames() {
+            return typeClassNames;
+        }
+        public GrammarInfo getGrammarInfo() {
+            return gInfo;
+        }
+        public Set<String> getResourceClassNames() {
+            return resourceClassNames;
+        }
+        
+        
+    }
 }

Modified: cxf/branches/2.4.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.4.x-fixes/tools/wadlto/jaxrs/src/test/java/org/apache/cxf/tools/wadlto/jaxrs/JAXRSContainerTest.java?rev=1174385&r1=1174384&r2=1174385&view=diff
==============================================================================
--- cxf/branches/2.4.x-fixes/tools/wadlto/jaxrs/src/test/java/org/apache/cxf/tools/wadlto/jaxrs/JAXRSContainerTest.java
(original)
+++ cxf/branches/2.4.x-fixes/tools/wadlto/jaxrs/src/test/java/org/apache/cxf/tools/wadlto/jaxrs/JAXRSContainerTest.java
Thu Sep 22 20:53:36 2011
@@ -47,15 +47,15 @@ public class JAXRSContainerTest extends 
 
             assertNotNull(output.list());
             
-            verifyFiles("java", true, false, "superbooks", "org.apache.cxf.jaxrs.model.wadl");
-            verifyFiles("class", true, false, "superbooks", "org.apache.cxf.jaxrs.model.wadl");
+            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() {
         try {
@@ -72,8 +72,8 @@ public class JAXRSContainerTest extends 
 
             assertNotNull(output.list());
             
-            verifyFiles("java", true, false, "superbooks", "org.apache.cxf.jaxrs.model.wadl");
-            verifyFiles("class", true, false, "superbooks", "org.apache.cxf.jaxrs.model.wadl");
+            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();
@@ -96,8 +96,8 @@ public class JAXRSContainerTest extends 
 
             assertNotNull(output.list());
             
-            verifyFiles("java", false, false, "superbooks", "org.apache.cxf.jaxrs.model.wadl");
-            verifyFiles("class", false, false, "superbooks", "org.apache.cxf.jaxrs.model.wadl");
+            verifyFiles("java", false, false, "superbooks", "org.apache.cxf.jaxrs.model.wadl",
9);
+            verifyFiles("class", false, false, "superbooks", "org.apache.cxf.jaxrs.model.wadl",
9);
             
         } catch (Exception e) {
             e.printStackTrace();
@@ -186,8 +186,8 @@ public class JAXRSContainerTest extends 
 
             assertNotNull(output.list());
             
-            verifyFiles("java", false, false, "superbooks", "org.apache.cxf.jaxrs.model.wadl");
-            verifyFiles("class", false, false, "superbooks", "org.apache.cxf.jaxrs.model.wadl");
+            verifyFiles("java", false, false, "superbooks", "org.apache.cxf.jaxrs.model.wadl",
9);
+            verifyFiles("class", false, false, "superbooks", "org.apache.cxf.jaxrs.model.wadl",
9);
             
         } catch (Exception e) {
             e.printStackTrace();
@@ -211,8 +211,8 @@ public class JAXRSContainerTest extends 
 
             assertNotNull(output.list());
             
-            verifyFiles("java", false, false, "superbooks", "org.apache.cxf.jaxrs.model.wadl");
-            verifyFiles("class", false, false, "superbooks", "org.apache.cxf.jaxrs.model.wadl");
+            verifyFiles("java", false, false, "superbooks", "org.apache.cxf.jaxrs.model.wadl",
9);
+            verifyFiles("class", false, false, "superbooks", "org.apache.cxf.jaxrs.model.wadl",
9);
             
         } catch (Exception e) {
             e.printStackTrace();
@@ -236,8 +236,8 @@ public class JAXRSContainerTest extends 
 
             assertNotNull(output.list());
             
-            verifyFiles("java", false, false, "superbooks", "org.apache.cxf.jaxrs.model.wadl");
-            verifyFiles("class", false, false, "superbooks", "org.apache.cxf.jaxrs.model.wadl");
+            verifyFiles("java", false, false, "superbooks", "org.apache.cxf.jaxrs.model.wadl",
9);
+            verifyFiles("class", false, false, "superbooks", "org.apache.cxf.jaxrs.model.wadl",
9);
             
         } catch (Exception e) {
             e.printStackTrace();
@@ -319,8 +319,8 @@ public class JAXRSContainerTest extends 
 
             assertNotNull(output.list());
             
-            verifyFiles("java", true, false, "superbooks", "custom.books");
-            verifyFiles("class", true, false, "superbooks", "custom.books");
+            verifyFiles("java", true, false, "superbooks", "custom.books", 10);
+            verifyFiles("class", true, false, "superbooks", "custom.books", 10);
             
         } catch (Exception e) {
             e.printStackTrace();
@@ -345,8 +345,8 @@ public class JAXRSContainerTest extends 
 
             assertNotNull(output.list());
             
-            verifyFiles("java", true, false, "custom.books.schema", "custom.books.service");
-            verifyFiles("class", true, false, "custom.books.schema", "custom.books.service");
+            verifyFiles("java", true, false, "custom.books.schema", "custom.books.service",
10);
+            verifyFiles("class", true, false, "custom.books.schema", "custom.books.service",
10);
             
         } catch (Exception e) {
             e.printStackTrace();
@@ -370,8 +370,8 @@ public class JAXRSContainerTest extends 
 
             assertNotNull(output.list());
             
-            verifyFiles("java", true, false, "superbooks", "org.apache.cxf.jaxrs.model.wadl");
-            verifyFiles("class", true, false, "superbooks", "org.apache.cxf.jaxrs.model.wadl");
+            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) {
             fail();
             e.printStackTrace();
@@ -395,8 +395,8 @@ public class JAXRSContainerTest extends 
 
             assertNotNull(output.list());
             
-            verifyFiles("java", true, true, "superbooks", "org.apache.cxf.jaxrs.model.wadl");
-            verifyFiles("class", true, true, "superbooks", "org.apache.cxf.jaxrs.model.wadl");
+            verifyFiles("java", true, true, "superbooks", "org.apache.cxf.jaxrs.model.wadl",
11);
+            verifyFiles("class", true, true, "superbooks", "org.apache.cxf.jaxrs.model.wadl",
11);
         } catch (Exception e) {
             fail();
             e.printStackTrace();
@@ -427,9 +427,9 @@ public class JAXRSContainerTest extends 
     }
     
     private void verifyFiles(String ext, boolean subresourceExpected, boolean interfacesAndImpl,

-                             String schemaPackage, String resourcePackage) {    
+                             String schemaPackage, String resourcePackage, int expectedCount)
{    
         List<File> files = FileUtils.getFilesRecurse(output, ".+\\." + ext + "$");
-        int size = interfacesAndImpl ? 9 : 7;
+        int size = interfacesAndImpl ? expectedCount : expectedCount - 2;
         if (!subresourceExpected) {
             size--;
         }
@@ -437,11 +437,13 @@ public class JAXRSContainerTest extends 
         doVerifyTypes(files, schemaPackage, ext);
         if (subresourceExpected) {
             assertTrue(checkContains(files, resourcePackage + ".FormInterface." + ext));
+            assertTrue(checkContains(files, resourcePackage + ".FormInterface2." + ext));
         }
         assertTrue(checkContains(files, resourcePackage + ".BookStore." + ext));
         if (interfacesAndImpl) {
             if (subresourceExpected) {
                 assertTrue(checkContains(files, resourcePackage + ".FormInterfaceImpl." +
ext));
+                assertTrue(checkContains(files, resourcePackage + ".FormInterface2Impl."
+ ext));
             }
             assertTrue(checkContains(files, resourcePackage + ".BookStoreImpl." + ext));
         }

Modified: cxf/branches/2.4.x-fixes/tools/wadlto/jaxrs/src/test/java/org/apache/cxf/tools/wadlto/jaxrs/WADLToJavaTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.4.x-fixes/tools/wadlto/jaxrs/src/test/java/org/apache/cxf/tools/wadlto/jaxrs/WADLToJavaTest.java?rev=1174385&r1=1174384&r2=1174385&view=diff
==============================================================================
--- cxf/branches/2.4.x-fixes/tools/wadlto/jaxrs/src/test/java/org/apache/cxf/tools/wadlto/jaxrs/WADLToJavaTest.java
(original)
+++ cxf/branches/2.4.x-fixes/tools/wadlto/jaxrs/src/test/java/org/apache/cxf/tools/wadlto/jaxrs/WADLToJavaTest.java
Thu Sep 22 20:53:36 2011
@@ -59,7 +59,7 @@ public class WADLToJavaTest extends Proc
     private void verifyFiles(String ext, boolean subresourceExpected, boolean interfacesAndImpl,

                              String schemaPackage, String resourcePackage) {    
         List<File> files = FileUtils.getFilesRecurse(output, ".+\\." + ext + "$");
-        int size = interfacesAndImpl ? 9 : 7;
+        int size = interfacesAndImpl ? 10 : 8;
         if (!subresourceExpected) {
             size--;
         }

Modified: cxf/branches/2.4.x-fixes/tools/wadlto/jaxrs/src/test/resources/wadl/bookstore.xml
URL: http://svn.apache.org/viewvc/cxf/branches/2.4.x-fixes/tools/wadlto/jaxrs/src/test/resources/wadl/bookstore.xml?rev=1174385&r1=1174384&r2=1174385&view=diff
==============================================================================
--- cxf/branches/2.4.x-fixes/tools/wadlto/jaxrs/src/test/resources/wadl/bookstore.xml (original)
+++ cxf/branches/2.4.x-fixes/tools/wadlto/jaxrs/src/test/resources/wadl/bookstore.xml Thu
Sep 22 20:53:36 2011
@@ -151,64 +151,85 @@
     <param name="mid" style="matrix" type="xs:int"/>
    </resource>
 
-   <resource path="/booksubresource" id="{http://superbooks}thebook">
-    <doc>Book subresource</doc>
-    <param name="id" style="template" type="xs:int"/>
-    <param name="mid" style="matrix" type="xs:int"/>
-    
-    <resource path="/book">
-     <method name="GET" id="getIt">
-      <doc>Get the book</doc>
+   
+  <resource path="/booksubresource" id="{http://superbooks}thebook">
+	    <doc>Book subresource</doc>
+	    <param name="id" style="template" type="xs:int"/>
+	    <param name="mid" style="matrix" type="xs:int"/>
+	    
+	    <resource path="/book">
+	     <method name="GET" id="getIt">
+	      <doc>Get the book</doc>
+	      <response>
+	       <representation mediaType="application/xml" element="prefix1:thebook"></representation>
+	       <representation mediaType="application/json"></representation>
+	      </response>
+	     </method>
+	    </resource>
+	   
+	    <resource path="/form1">
+	     <method name="POST" id="form1">
+	     <request>
+	      <representation mediaType="application/x-www-form-urlencoded"/>
+	     </request>
+	     <response status="204"></response>
+	    </method>
+	   </resource>
+	   
+	   <resource path="/form2">
+	    <method name="POST" id="form2">
+	     <request>
+	      <representation mediaType="application/x-www-form-urlencoded">
+	       <param name="field1" style="query" type="xs:string"/>
+	       <param name="field2" style="query" type="xs:string"/>
+	      </representation>
+	     </request>
+	     <response>
+	      <representation mediaType="text/plain">
+	       <param name="result" style="plain" type="xs:string"/>
+	      </representation>
+	     </response>
+	    </method>
+	   </resource>
+	
+	   <resource path="/chapter/{cid}" id="{http://superbooks}thechapter">
+	    <doc>Chapter subresource</doc>
+	    <param name="cid" style="template" type="xs:int"/>
+	    
+	    <resource path="/id">
+	     <method name="GET" id="getIt">
+	      <doc>Get the chapter</doc>
+	      <response>
+	       <representation mediaType="application/xml" element="prefix1:thechapter"></representation>
+	       <representation mediaType="application/json"></representation>
+	      </response>
+	     </method>
+	    </resource>
+	   </resource>
+ </resource>
+ <resource path="/a">
+   <resource path="/b">
+    <method name="GET" id="getChapter3">
       <response>
-       <representation mediaType="application/xml" element="prefix1:thebook"></representation>
-       <representation mediaType="application/json"></representation>
+         <representation mediaType="application/xml" element="prefix1:thechapter"/>
       </response>
-     </method>
-    </resource>
-   
-    <resource path="/form1">
-     <method name="POST" id="form1">
-     <request>
-      <representation mediaType="application/x-www-form-urlencoded"/>
-     </request>
-     <response status="204"></response>
     </method>
-   </resource>
    
-   <resource path="/form2">
-    <method name="POST" id="form2">
-     <request>
-      <representation mediaType="application/x-www-form-urlencoded">
-       <param name="field1" style="query" type="xs:string"/>
-       <param name="field2" style="query" type="xs:string"/>
-      </representation>
-     </request>
-     <response>
-      <representation mediaType="text/plain">
-       <param name="result" style="plain" type="xs:string"/>
-      </representation>
-     </response>
-    </method>
+  <resource path="/form" id="org.apache.cxf.jaxrs.model.wadl.FormInterface">
+    <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">
+        <resource path="/recursive" id="org.apache.cxf.jaxrs.model.wadl.FormInterface"/>
+        <resource path="/subform1">
+	      <method name="POST" id="form1">
+	        <request>
+	           <representation mediaType="application/x-www-form-urlencoded"/>
+	        </request>
+	        <response status="204"></response>
+	      </method>
+	    </resource>
+	  </resource> 
    </resource>
-
-   <resource path="/chapter/{cid}" id="{http://superbooks}thechapter">
-    <doc>Chapter subresource</doc>
-    <param name="cid" style="template" type="xs:int"/>
-    
-    <resource path="/id">
-     <method name="GET" id="getIt">
-      <doc>Get the chapter</doc>
-      <response>
-       <representation mediaType="application/xml" element="prefix1:thechapter"></representation>
-       <representation mediaType="application/json"></representation>
-      </response>
-     </method>
-    </resource>
-   </resource>
- </resource>
- 
- <resource path="/form" id="org.apache.cxf.jaxrs.model.wadl.FormInterface">
-  
   <resource path="/form1">
    <method name="POST" id="form1">
     <request>
@@ -230,8 +251,12 @@
       <representation mediaType="text/plain">
        <param name="result" style="plain" type="xs:string"/>
       </representation>
-    </response></method>
+    </response>
+   </method>
   </resource>
+  
+ </resource>
+ </resource>
  </resource>
 
  <!-- Recursive subresource -->

Modified: cxf/branches/2.4.x-fixes/tools/wadlto/jaxrs/src/test/resources/wadl/bookstoreImport.xml
URL: http://svn.apache.org/viewvc/cxf/branches/2.4.x-fixes/tools/wadlto/jaxrs/src/test/resources/wadl/bookstoreImport.xml?rev=1174385&r1=1174384&r2=1174385&view=diff
==============================================================================
--- cxf/branches/2.4.x-fixes/tools/wadlto/jaxrs/src/test/resources/wadl/bookstoreImport.xml
(original)
+++ cxf/branches/2.4.x-fixes/tools/wadlto/jaxrs/src/test/resources/wadl/bookstoreImport.xml
Thu Sep 22 20:53:36 2011
@@ -17,7 +17,8 @@
   specific language governing permissions and limitations
   under the License.
 -->
-<application xmlns="http://wadl.dev.java.net/2009/02" xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:prefix1="http://superbooks">
+<application xmlns="http://wadl.dev.java.net/2009/02" xmlns:xs="http://www.w3.org/2001/XMLSchema"

+   xmlns:ns1="http://superbooks">
 
  <grammars>
     <include href="schemas/book.xsd"/>
@@ -30,7 +31,13 @@
      
      <method name="POST" id="addBook">
       <request>
-       <representation mediaType="application/xml" element="prefix1:thebook"/>
+       <representation mediaType="application/xml" element="ns1:thebook"/>
+      </request>
+     </method>
+     
+     <method name="POST" id="addChapter">
+      <request>
+       <representation mediaType="application/xml" element="ns1:thechapter"/>
       </request>
      </method>
     </resource>

Modified: cxf/branches/2.4.x-fixes/tools/wadlto/jaxrs/src/test/resources/wadl/singleResource.xml
URL: http://svn.apache.org/viewvc/cxf/branches/2.4.x-fixes/tools/wadlto/jaxrs/src/test/resources/wadl/singleResource.xml?rev=1174385&r1=1174384&r2=1174385&view=diff
==============================================================================
--- cxf/branches/2.4.x-fixes/tools/wadlto/jaxrs/src/test/resources/wadl/singleResource.xml
(original)
+++ cxf/branches/2.4.x-fixes/tools/wadlto/jaxrs/src/test/resources/wadl/singleResource.xml
Thu Sep 22 20:53:36 2011
@@ -31,17 +31,17 @@
       </response>
     </method>
     <resource path="/books">
-     <method name="GET">
-      <response status="200">
-       <representation mediaType="text/plain">
-        <param name="result" style="plain" type="xs:string"/>
-       </representation>
-      </response>
-      <response status="400">
-        <representation mediaType="application/json"/>
-      </response>
-    </method>
-   </resource>
+       <method name="GET">
+	      <response status="200 201">
+	       <representation mediaType="text/plain">
+	        <param name="result" style="plain" type="xs:string"/>
+	       </representation>
+	      </response>
+	      <response status="400">
+	        <representation mediaType="application/json"/>
+	      </response>
+	   </method>
+     </resource>
     
    </resource>
  </resources>  



Mime
View raw message