cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1328898 - in /cxf/branches/2.5.x-fixes: ./ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/codegen/SourceGenerator.java
Date Sun, 22 Apr 2012 16:50:03 GMT
Author: sergeyb
Date: Sun Apr 22 16:50:02 2012
New Revision: 1328898

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

........
  r1328322 | sergeyb | 2012-04-20 12:11:13 +0100 (Fri, 20 Apr 2012) | 1 line
  
  Minor update to WADL generator to get enum classes generated 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/
------------------------------------------------------------------------------
    svn:mergeinfo = /cxf/trunk:1328322

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=1328898&r1=1328897&r2=1328898&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
Sun Apr 22 16:50:02 2012
@@ -851,7 +851,8 @@ public class SourceGenerator {
                 }
             }
             boolean isRepeating = Boolean.valueOf(paramEl.getAttribute("repeating"));
-            String type = getPrimitiveType(paramEl, info, imports);
+            String type = enumCreated ? getTypicalClassName(name)
+                : getPrimitiveType(paramEl, info, imports);
             if (paramAnn == QueryParam.class
                 && (isRepeating || !Boolean.valueOf(paramEl.getAttribute("required")))
   
                 && AUTOBOXED_PRIMITIVES_MAP.containsKey(type)) {
@@ -861,8 +862,7 @@ public class SourceGenerator {
                 addImport(imports, List.class.getName());
                 type = "List<" + type + ">";
             }
-            String paramName = enumCreated ? getTypicalClassName(name) 
-                                           : name.replaceAll("[\\.\\-]", "_");
+            String paramName = name.replaceAll("[\\.\\-]", "_");
             sbCode.append(type).append(" ").append(paramName);
             if (i + 1 < inParamEls.size()) {
                 sbCode.append(", ");
@@ -905,26 +905,75 @@ public class SourceGenerator {
             .append(";").append(getLineSep()).append(getLineSep());
         
         sbCode.append("public enum " + clsName);
-        sbCode.append(" {" + getLineSep());
+        openBlock(sbCode);
         
         for (int i = 0; i < options.size(); i++) {
             String value = options.get(i).getAttribute("value");
-            sbCode.append(TAB).append(value.toUpperCase());
+            sbCode.append(TAB).append(value.toUpperCase().replaceAll("[\\,\\-]", "_"))
+                .append("(\"").append(value).append("\")");
             if (i + 1 < options.size()) {
                 sbCode.append(",");
+            } else {
+                sbCode.append(";");
             }
             sbCode.append(getLineSep());
         }
+        
+        sbCode.append(TAB).append("private String value;").append(getLineSep());
+        sbCode.append(TAB).append("private ").append(clsName).append("(String v)");
+        openBlock(sbCode);
+        tab(sbCode, 2).append("this.value = v;").append(getLineSep());
+        tabCloseBlock(sbCode, 1);
+        
+        sbCode.append(TAB).append("public static ")
+            .append(clsName).append(" fromString(String value)");
+        openBlock(sbCode);    
+        tab(sbCode, 2);
+        sbCode.append("if (").append("value").append(" != null)");
+        openBlock(sbCode);
+        tab(sbCode, 3);
+        sbCode.append("for (").append(clsName).append(" v : ")
+            .append(clsName).append(".values())");
+        openBlock(sbCode);    
+        tab(sbCode, 4);
+        sbCode.append("if (value.equalsIgnoreCase(v.value))");
+        openBlock(sbCode);
+        tab(sbCode, 5);
+        sbCode.append("return v;").append(getLineSep());
+        tabCloseBlock(sbCode, 4);
+        tabCloseBlock(sbCode, 3);
+        tabCloseBlock(sbCode, 2);
+        tab(sbCode, 2);
+        sbCode.append("throw new IllegalArgumentException();").append(getLineSep());
+        tabCloseBlock(sbCode, 1);
         sbCode.append("}");
         createJavaSourceFile(src, new QName(classPackage, clsName), sbCode, sbImports, false);
     }
     
+    private static StringBuilder tab(StringBuilder sb, int count) {
+        for (int i = 0; i < count; i++) {
+            sb.append(TAB);
+        }
+        return sb;
+    }
+    
+    private StringBuilder tabCloseBlock(StringBuilder sb, int count) {
+        tab(sb, count).append("}").append(getLineSep());
+        return sb;
+    }
+    
+    private StringBuilder openBlock(StringBuilder sb) {
+        sb.append(" {").append(getLineSep());
+        return sb;
+    }
+    
     private String getTypicalClassName(String name) { 
         String theName = name.toUpperCase();
         if (theName.length() == 1) {
             return theName;
         } else {
-            return theName.substring(0, 1) + theName.substring(1).toLowerCase();
+            theName = theName.substring(0, 1) + theName.substring(1).toLowerCase();
+            return theName.replaceAll("[\\.\\-]", "");
         }
     }
     



Mime
View raw message