cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1328129 - in /cxf/branches/2.5.x-fixes: ./ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/codegen/SourceGenerator.java
Date Thu, 19 Apr 2012 21:59:29 GMT
Author: sergeyb
Date: Thu Apr 19 21:59:28 2012
New Revision: 1328129

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

........
  r1328123 | sergeyb | 2012-04-19 22:43:59 +0100 (Thu, 19 Apr 2012) | 1 line
  
  [CXF-4250] Handling root-level WADL method declarations properly
........

Modified:
    cxf/branches/2.5.x-fixes/   (props changed)
    cxf/branches/2.5.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/codegen/SourceGenerator.java

Propchange: cxf/branches/2.5.x-fixes/
------------------------------------------------------------------------------
  Merged /cxf/trunk:r1328123

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

Modified: cxf/branches/2.5.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.5.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/codegen/SourceGenerator.java?rev=1328129&r1=1328128&r2=1328129&view=diff
==============================================================================
--- cxf/branches/2.5.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/codegen/SourceGenerator.java
(original)
+++ cxf/branches/2.5.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/codegen/SourceGenerator.java
Thu Apr 19 21:59:28 2012
@@ -16,7 +16,7 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-package org.apache.cxf.jaxrs.ext.codegen;
+package org.apache.cxf.tools.wadlto.jaxrs;
 
 import java.io.File;
 import java.io.FileNotFoundException;
@@ -72,6 +72,10 @@ import org.xml.sax.SAXParseException;
 import org.apache.cxf.Bus;
 import org.apache.cxf.catalog.OASISCatalogManager;
 import org.apache.cxf.catalog.OASISCatalogManagerHelper;
+import org.apache.cxf.common.jaxb.JAXBUtils;
+import org.apache.cxf.common.jaxb.JAXBUtils.JCodeModel;
+import org.apache.cxf.common.jaxb.JAXBUtils.S2JJAXBModel;
+import org.apache.cxf.common.jaxb.JAXBUtils.SchemaCompiler;
 import org.apache.cxf.common.logging.LogUtils;
 import org.apache.cxf.common.util.PackageUtils;
 import org.apache.cxf.common.util.ReflectionInvokationHandler;
@@ -79,10 +83,6 @@ import org.apache.cxf.common.util.System
 import org.apache.cxf.common.xmlschema.XmlSchemaConstants;
 import org.apache.cxf.helpers.CastUtils;
 import org.apache.cxf.helpers.DOMUtils;
-import org.apache.cxf.jaxb.JAXBUtils;
-import org.apache.cxf.jaxb.JAXBUtils.JCodeModel;
-import org.apache.cxf.jaxb.JAXBUtils.S2JJAXBModel;
-import org.apache.cxf.jaxb.JAXBUtils.SchemaCompiler;
 import org.apache.cxf.jaxrs.model.wadl.WadlGenerator;
 import org.apache.cxf.jaxrs.utils.JAXRSUtils;
 import org.apache.cxf.jaxrs.utils.ResourceUtils;
@@ -241,7 +241,7 @@ public class SourceGenerator {
         Element appElement = app.getAppElement();
         List<Element> resourcesEls = getWadlElements(appElement, "resources");
         if (resourcesEls.size() != 1) {
-            throw new IllegalStateException("WADL resources element is missing");
+            throw new IllegalStateException("Single WADL resources element is expected");
         }
         
         List<Element> resourceEls = getWadlElements(resourcesEls.get(0), "resource");
@@ -475,9 +475,7 @@ public class SourceGenerator {
         } else {
             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();
+        name = firstCharToUpperCase(name);
         for (String typeName : typeClassNames) {
             String localName = typeName.contains(".") 
                 ? typeName.substring(typeName.lastIndexOf('.') + 1) : typeName;
@@ -488,6 +486,12 @@ public class SourceGenerator {
         return name;
     }
     
+    private String firstCharToUpperCase(String name) {
+        StringBuilder sb = new StringBuilder();
+        sb.append(Character.toUpperCase(name.charAt(0)));
+        return name.length() > 1 ? sb.append(name.substring(1)).toString() : sb.toString();
+    }
+    
     private boolean writeAnnotations(boolean interfaceIsGenerated) {
         if (interfaceIsGenerated) {
             return true;
@@ -633,8 +637,7 @@ public class SourceGenerator {
             }
             boolean responseTypeAvailable = true;
             if (methodNameLowerCase.length() > 0) {
-                responseTypeAvailable = writeResponseType(responseEls, sbCode, imports,
-                        info.getTypeClassNames(), info.getGrammarInfo());
+                responseTypeAvailable = writeResponseType(responseEls, sbCode, imports, info);
                 sbCode.append(id + suffixName);
             } else {
                 boolean expandedQName = id.startsWith("{");
@@ -648,7 +651,10 @@ public class SourceGenerator {
                     : clsSimpleName.substring(packageName.length() + 1);
                 String subResponseNs = clsSimpleName == null ? getClassPackageName(packageName)

                     : clsSimpleName.substring(0, packageName.length());
-                String parentId = ((Element)resourceEl.getParentNode()).getAttribute("id");
+                Object parentNode = resourceEl.getParentNode();
+                String parentId = parentNode instanceof Element 
+                    ? ((Element)parentNode).getAttribute("id")
+                    : ""; 
                 writeSubResponseType(id.equals(parentId), subResponseNs, localName, 
                         sbCode, imports);
                 
@@ -749,8 +755,8 @@ public class SourceGenerator {
     
     private boolean writeResponseType(List<Element> responseEls,
                                       StringBuilder sbCode,
-                                      Set<String> imports, Set<String> typeClassNames,

-                                      GrammarInfo gInfo) {
+                                      Set<String> imports,  
+                                      ContextInfo info) {
         
         Element okResponse = getOKResponse(responseEls);
         
@@ -766,8 +772,7 @@ public class SourceGenerator {
             return false;
         }
         String elementName = getElementRefName(
-                getActualRepElement(repElements, getXmlReps(repElements).get(0)),
-                typeClassNames, gInfo, imports);
+                getActualRepElement(repElements, getXmlReps(repElements).get(0)), info, imports);
         if (elementName != null) {
             sbCode.append(elementName + " ");
         } else {
@@ -846,7 +851,7 @@ public class SourceGenerator {
                 }
             }
             boolean isRepeating = Boolean.valueOf(paramEl.getAttribute("repeating"));
-            String type = getPrimitiveType(paramEl);
+            String type = getPrimitiveType(paramEl, info, imports);
             if (paramAnn == QueryParam.class
                 && (isRepeating || !Boolean.valueOf(paramEl.getAttribute("required")))
   
                 && AUTOBOXED_PRIMITIVES_MAP.containsKey(type)) {
@@ -870,8 +875,7 @@ public class SourceGenerator {
         String elementParamName = null;
         if (!form) {
             if (!jaxpRequired) {    
-                elementParamType = getElementRefName(repElement, 
-                        info.getTypeClassNames(), info.getGrammarInfo(), imports);
+                elementParamType = getElementRefName(repElement, info, imports);
                 if (elementParamType != null) {
                     elementParamName = elementParamType.toLowerCase();
                 }
@@ -940,7 +944,7 @@ public class SourceGenerator {
         return elements;
     }
     
-    private String getPrimitiveType(Element paramEl) {
+    private String getPrimitiveType(Element paramEl, ContextInfo info, Set<String>
imports) {
         String type = paramEl.getAttribute("type");
         if (type.length() == 0) {
             return "String";
@@ -950,13 +954,44 @@ public class SourceGenerator {
         if (XSD_SPECIFIC_TYPE_MAP.containsKey(value)) {
             return XSD_SPECIFIC_TYPE_MAP.get(value);
         } else {
-            return value;
+            String actualValue = value.replaceAll("[\\-\\_]", "");
+            if (!actualValue.equals(value) && pair.length > 1) {
+                actualValue = convertRefToClassName(pair[0], actualValue, actualValue, info,
imports);
+            }
+            return actualValue;
+        }
+    }
+    
+    private String convertRefToClassName(String prefix,
+                                         String actualValue,
+                                         String defaultValue,
+                                         ContextInfo info, 
+                                         Set<String> imports) {
+        GrammarInfo gInfo = info.getGrammarInfo();
+        if (gInfo != null) {
+            String namespace = gInfo.getNsMap().get(prefix);
+            if (namespace != null) {
+                String packageName = getPackageFromNamespace(namespace);
+                String clsName = getSchemaClassName(packageName, gInfo, actualValue, 
+                                                    info.getTypeClassNames());
+                if (clsName != null) {
+                    addImport(imports, clsName);
+                    int index = clsName.lastIndexOf(".");
+                    if (index != -1) {
+                        actualValue = clsName.substring(index + 1);
+                    } else {
+                        actualValue = clsName;
+                    }       
+                }
+            } else {
+                actualValue = defaultValue;
+            }
         }
+        return actualValue;
     }
     
     private String getElementRefName(Element repElement,
-                                     Set<String> typeClassNames,
-                                     GrammarInfo gInfo, 
+                                     ContextInfo info, 
                                      Set<String> imports) {
         if (repElement == null) {
             return null;
@@ -966,26 +1001,12 @@ public class SourceGenerator {
         if (elementRef.length() > 0) {
             String[] pair = elementRef.split(":");
             if (pair.length == 2) {
-                String namespace = gInfo != null ? gInfo.getNsMap().get(pair[0]) : null;
-                if (namespace == null) {
-                    return null;
-                }
-                String packageName = getPackageFromNamespace(namespace);
-                String clsName = getSchemaClassName(packageName, gInfo, pair[1], typeClassNames);
-                if (clsName != null) {
-                    addImport(imports, clsName);
-                    int index = clsName.lastIndexOf(".");
-                    if (index != -1) {
-                        return clsName.substring(index + 1);
-                    } else {
-                        return clsName;
-                    }
-                }
+                return convertRefToClassName(pair[0], pair[1], null, info, imports);
             }
         } else {
             Element param = DOMUtils.getFirstChildWithName(repElement, getWadlNamespace(),
"param");
             if (param != null) {
-                return getPrimitiveType(param);
+                return getPrimitiveType(param, info, imports);
             }
         }
         return null;
@@ -1125,7 +1146,16 @@ public class SourceGenerator {
             
             String schemaURI = resolveLocationWithCatalog(href);
             if (schemaURI == null) {
-                schemaURI = app.getWadlPath() != null ? getBaseWadlPath(app.getWadlPath())
+ href : href;
+                if (!URI.create(href).isAbsolute() && app.getWadlPath() != null)
{
+                    String baseWadlPath = getBaseWadlPath(app.getWadlPath());
+                    if  (!href.startsWith("/")) {
+                        schemaURI = baseWadlPath + href;
+                    } else {
+                        schemaURI = URI.create(baseWadlPath).resolve(href).toString();
+                    }
+                } else {
+                    schemaURI = href;
+                }
             }
             schemas.add(createSchemaInfo(readIncludedDocument(schemaURI),
                                             schemaURI));



Mime
View raw message