cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1328436 - /cxf/trunk/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxrs/SourceGenerator.java
Date Fri, 20 Apr 2012 16:27:28 GMT
Author: sergeyb
Date: Fri Apr 20 16:27:28 2012
New Revision: 1328436

URL: http://svn.apache.org/viewvc?rev=1328436&view=rev
Log:
[CXF-4256] Updating WADL generator to create better enum classes

Modified:
    cxf/trunk/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxrs/SourceGenerator.java

Modified: cxf/trunk/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxrs/SourceGenerator.java
URL: http://svn.apache.org/viewvc/cxf/trunk/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxrs/SourceGenerator.java?rev=1328436&r1=1328435&r2=1328436&view=diff
==============================================================================
--- cxf/trunk/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxrs/SourceGenerator.java
(original)
+++ cxf/trunk/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxrs/SourceGenerator.java
Fri Apr 20 16:27:28 2012
@@ -909,12 +909,38 @@ public class SourceGenerator {
         
         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) ").append("{")
+            .append(getLineSep());
+        sbCode.append(TAB).append(TAB).append("this.value = v;").append(getLineSep());
+        sbCode.append(TAB).append("}").append(getLineSep());
+        
+        sbCode.append(TAB).append("public static ").append(clsName).append(" fromString(String
value) ")
+            .append("{").append(getLineSep());
+        sbCode.append(TAB).append(TAB);
+        sbCode.append("if (").append("value").append(" != null) {").append(getLineSep());
+        sbCode.append(TAB).append(TAB).append(TAB);
+        sbCode.append("for (").append(clsName).append(" v : ").append(clsName).append(".values())
{")
+            .append(getLineSep());
+        sbCode.append(TAB).append(TAB).append(TAB).append(TAB);
+        sbCode.append("if (value.equalsIgnoreCase(v.value)) {").append(getLineSep());
+        sbCode.append(TAB).append(TAB).append(TAB).append(TAB).append(TAB).append("return
v;")
+            .append(getLineSep());
+        sbCode.append(TAB).append(TAB).append(TAB).append(TAB).append("}").append(getLineSep());
+        sbCode.append(TAB).append(TAB).append(TAB).append("}").append(getLineSep());
+        sbCode.append(TAB).append(TAB).append("}").append(getLineSep());
+        sbCode.append(TAB).append(TAB).append("return null;").append(getLineSep());
+        sbCode.append(TAB).append("}").append(getLineSep());
         sbCode.append("}");
         createJavaSourceFile(src, new QName(classPackage, clsName), sbCode, sbImports, false);
     }
@@ -925,7 +951,7 @@ public class SourceGenerator {
             return theName;
         } else {
             theName = theName.substring(0, 1) + theName.substring(1).toLowerCase();
-            return theName.replaceAll("[\\.\\-]", "_");
+            return theName.replaceAll("[\\.\\-]", "");
         }
     }
     



Mime
View raw message