[jboss-cvs] JBossAS SVN: r106144 - in projects/jboss-jca/trunk/codegenerator/src/main/java/org/jboss/jca/codegenerator: code and 1 other directory.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Thu Jun 17 23:21:46 EDT 2010


Author: jeff.zhang
Date: 2010-06-17 23:21:46 -0400 (Thu, 17 Jun 2010)
New Revision: 106144

Modified:
   projects/jboss-jca/trunk/codegenerator/src/main/java/org/jboss/jca/codegenerator/BasicType.java
   projects/jboss-jca/trunk/codegenerator/src/main/java/org/jboss/jca/codegenerator/Main.java
   projects/jboss-jca/trunk/codegenerator/src/main/java/org/jboss/jca/codegenerator/code/TestCodeGen.java
Log:
[JBJCA-361] support primitive type and result

Modified: projects/jboss-jca/trunk/codegenerator/src/main/java/org/jboss/jca/codegenerator/BasicType.java
===================================================================
--- projects/jboss-jca/trunk/codegenerator/src/main/java/org/jboss/jca/codegenerator/BasicType.java	2010-06-17 22:51:00 UTC (rev 106143)
+++ projects/jboss-jca/trunk/codegenerator/src/main/java/org/jboss/jca/codegenerator/BasicType.java	2010-06-18 03:21:46 UTC (rev 106144)
@@ -48,6 +48,16 @@
    /** char */
    Character;
    
+   private static String[] primitive = {
+      "int",
+      "boolean",
+      "double",
+      "byte",
+      "short",
+      "long",
+      "float",
+      "char"
+   };
    /**
     * is basic type
     * @param type type string
@@ -66,12 +76,49 @@
    }
    
    /**
-    * return string include all types
+    * is primitive type
+    * @param type type string
+    * @return boolean true if basic type
+    */
+   public static boolean isPrimitiveType(String type)
+   {
+      for (String ptype : primitive)
+      {
+         if (type.equals(ptype))
+            return true;
+      }
+      return false;
+   }
+   
+   /**
+    * return string include all basic types
     * @return String all types
     */
+   public static String allBasicType()
+   {
+      StringBuilder sb = new StringBuilder();
+      BasicType[] types = BasicType.values();
+      for (int i = 0; i < types.length; i++)
+      {
+         sb.append(types[i].toString());
+         if (i + 1 < types.length)
+            sb.append(", ");
+      }
+      return sb.toString();
+   }
+   
+   /**
+    * return string include all basic and primitive types
+    * @return String all types
+    */
    public static String allType()
    {
       StringBuilder sb = new StringBuilder();
+      for (String ptype : primitive)
+      {
+         sb.append(ptype);
+         sb.append(", ");
+      }
       BasicType[] types = BasicType.values();
       for (int i = 0; i < types.length; i++)
       {
@@ -91,22 +138,22 @@
    {
       if (type.equals("String"))
          return "null";
-      else if (type.equals("Boolean"))
+      else if (type.equals("boolean") || type.equals("Boolean"))
          return "false";
-      else if (type.equals("Integer"))
+      else if (type.equals("int") || type.equals("Integer"))
          return "0";
-      else if (type.equals("Double"))
+      else if (type.equals("double") || type.equals("Double"))
          return "0.0";
-      else if (type.equals("Long"))
+      else if (type.equals("long") || type.equals("Long"))
          return "0l";
-      else if (type.equals("Byte"))
+      else if (type.equals("byte") || type.equals("Byte"))
          return "0";
-      else if (type.equals("Short"))
+      else if (type.equals("short") || type.equals("Short"))
          return "0";
-      else if (type.equals("Float"))
+      else if (type.equals("float") || type.equals("Float"))
          return "0.0f";
-      else if (type.equals("Character"))
-         return "0";
-      return "";
+      else if (type.equals("char") || type.equals("Character"))
+         return "''";
+      return null;
    }
 }

Modified: projects/jboss-jca/trunk/codegenerator/src/main/java/org/jboss/jca/codegenerator/Main.java
===================================================================
--- projects/jboss-jca/trunk/codegenerator/src/main/java/org/jboss/jca/codegenerator/Main.java	2010-06-17 22:51:00 UTC (rev 106143)
+++ projects/jboss-jca/trunk/codegenerator/src/main/java/org/jboss/jca/codegenerator/Main.java	2010-06-18 03:21:46 UTC (rev 106144)
@@ -369,7 +369,7 @@
          if (!BasicType.isBasicType(type))
          {
             System.out.print(dbconf.getString("config.properties.type.tip") + " [");
-            System.out.println(BasicType.allType() + "]");
+            System.out.println(BasicType.allBasicType() + "]");
             continue;
          }
          System.out.print("    " + dbconf.getString("config.properties.value"));
@@ -431,7 +431,7 @@
             {
                System.out.print("    " + dbconf.getString("connection.method.param.type"));
                paramType = in.readLine();
-               if (BasicType.isBasicType(paramType))
+               if (BasicType.isBasicType(paramType) || BasicType.isPrimitiveType(paramType))
                   break;
                System.out.print(dbconf.getString("config.properties.type.tip") + " [");
                System.out.println(BasicType.allType() + "]");

Modified: projects/jboss-jca/trunk/codegenerator/src/main/java/org/jboss/jca/codegenerator/code/TestCodeGen.java
===================================================================
--- projects/jboss-jca/trunk/codegenerator/src/main/java/org/jboss/jca/codegenerator/code/TestCodeGen.java	2010-06-17 22:51:00 UTC (rev 106143)
+++ projects/jboss-jca/trunk/codegenerator/src/main/java/org/jboss/jca/codegenerator/code/TestCodeGen.java	2010-06-18 03:21:46 UTC (rev 106144)
@@ -349,7 +349,12 @@
          writeIndent(out, indent + 2);
          out.write("assertNotNull(c);");
          writeEol(out);
+         
          writeIndent(out, indent + 2);
+         if (!method.getReturnType().equals("void"))
+         {
+            out.write(method.getReturnType() + " result = ");
+         }
          out.write("c." + method.getMethodName() + "(");
          int paramSize = method.getParams().size();
          for (int i = 0; i < paramSize; i++)



More information about the jboss-cvs-commits mailing list