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

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Thu Jun 17 06:07:11 EDT 2010


Author: jeff.zhang
Date: 2010-06-17 06:07:10 -0400 (Thu, 17 Jun 2010)
New Revision: 106107

Added:
   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/MethodForConnection.java
Modified:
   projects/jboss-jca/trunk/codegenerator/src/main/java/org/jboss/jca/codegenerator/Definition.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/ConnImplCodeGen.java
   projects/jboss-jca/trunk/codegenerator/src/main/java/org/jboss/jca/codegenerator/code/ConnInterfaceCodeGen.java
   projects/jboss-jca/trunk/codegenerator/src/main/java/org/jboss/jca/codegenerator/code/TestCodeGen.java
   projects/jboss-jca/trunk/codegenerator/src/main/resources/codegenerator.properties
Log:
[JBJCA-361] define method in Connection Interface

Added: 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	                        (rev 0)
+++ projects/jboss-jca/trunk/codegenerator/src/main/java/org/jboss/jca/codegenerator/BasicType.java	2010-06-17 10:07:10 UTC (rev 106107)
@@ -0,0 +1,112 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.jca.codegenerator;
+
+/**
+ * A BasicType.
+ * 
+ * @author Jeff Zhang
+ * @version $Revision: $
+ */
+public enum BasicType
+{
+   /** string */
+   String,
+   /** boolean */
+   Boolean,
+   /** integer */
+   Integer,
+   /** double */
+   Double,
+   /** bye */
+   Byte,
+   /** short */
+   Short,
+   /** long */
+   Long,
+   /** float */
+   Float,
+   /** char */
+   Character;
+   
+   /**
+    * is basic type
+    * @param type type string
+    * @return boolean true if basic type
+    */
+   public static boolean isBasicType(String type)
+   {
+      for (BasicType pt : BasicType.values())
+      {
+         if (type.equals(pt.toString()))
+         {
+            return true;
+         }
+      }
+      return false;
+   }
+   
+   /**
+    * return string include all types
+    * @return String all types
+    */
+   public static String allType()
+   {
+      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 default value string
+    * @param type type string
+    * @return String all types
+    */
+   public static String defaultValue(String type)
+   {
+      if (type.equals("String"))
+         return "null";
+      else if (type.equals("Boolean"))
+         return "false";
+      else if (type.equals("Integer"))
+         return "0";
+      else if (type.equals("Double"))
+         return "0.0";
+      else if (type.equals("Long"))
+         return "0l";
+      else if (type.equals("Byte"))
+         return "0";
+      else if (type.equals("Short"))
+         return "0";
+      else if (type.equals("Float"))
+         return "0.0f";
+      else if (type.equals("Character"))
+         return "0";
+      return "";
+   }
+}

Modified: projects/jboss-jca/trunk/codegenerator/src/main/java/org/jboss/jca/codegenerator/Definition.java
===================================================================
--- projects/jboss-jca/trunk/codegenerator/src/main/java/org/jboss/jca/codegenerator/Definition.java	2010-06-17 10:06:54 UTC (rev 106106)
+++ projects/jboss-jca/trunk/codegenerator/src/main/java/org/jboss/jca/codegenerator/Definition.java	2010-06-17 10:07:10 UTC (rev 106107)
@@ -101,6 +101,11 @@
    /** Activation class name */
    private String activationClass;
    
+   /** support self deined method in connection interface  */
+   private boolean defineMethodInConnection;
+   /** connection metadata class name */
+   private List<MethodForConnection> methods;
+   
    /**
     * Set the version.
     * 
@@ -715,4 +720,44 @@
       return supportTransaction;
    }
 
+   /**
+    * Set the defineMethodInConnection.
+    * 
+    * @param defineMethodInConnection The defineMethodInConnection to set.
+    */
+   public void setDefineMethodInConnection(boolean defineMethodInConnection)
+   {
+      this.defineMethodInConnection = defineMethodInConnection;
+   }
+
+   /**
+    * Get the defineMethodInConnection.
+    * 
+    * @return the defineMethodInConnection.
+    */
+   public boolean isDefineMethodInConnection()
+   {
+      return defineMethodInConnection;
+   }
+
+   /**
+    * Set the methods.
+    * 
+    * @param methods The methods to set.
+    */
+   public void setMethods(List<MethodForConnection> methods)
+   {
+      this.methods = methods;
+   }
+
+   /**
+    * Get the methods.
+    * 
+    * @return the methods.
+    */
+   public List<MethodForConnection> getMethods()
+   {
+      return methods;
+   }
+
 }

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 10:06:54 UTC (rev 106106)
+++ projects/jboss-jca/trunk/codegenerator/src/main/java/org/jboss/jca/codegenerator/Main.java	2010-06-17 10:07:10 UTC (rev 106107)
@@ -39,19 +39,7 @@
 public class Main
 {
    private static final int OTHER = 2;
-   
-   private enum PropsType 
-   {
-      String,
-      Boolean,
-      Integer,
-      Double,
-      Byte,
-      Short,
-      Long,
-      Float,
-      Character
-   }
+
    /**
     * Code generator stand alone tool
     * 
@@ -271,6 +259,22 @@
                System.out.print(dbconf.getString("conn.class.name"));
                String connImplName = in.readLine();
                def.setConnImplClass(connImplName);
+               
+               System.out.print(dbconf.getString("connection.method.support"));
+               String supportMethod = in.readLine();
+               if (supportMethod == null)
+                  def.setDefineMethodInConnection(false);
+               else
+               {
+                  if (supportMethod.equals("Y") || supportMethod.equals("y") || supportMethod.equals("Yes"))
+                     def.setDefineMethodInConnection(true);
+                  else
+                     def.setDefineMethodInConnection(false);
+               }
+               if (def.isDefineMethodInConnection())
+               {
+                  def.setMethods(inputMethod(dbconf, in));
+               }
             }
          }
          
@@ -361,24 +365,11 @@
             break;
          System.out.print("    " + dbconf.getString("config.properties.type"));
          String type = in.readLine();
-         boolean correctType = false;
-         for (PropsType pt : PropsType.values())
+
+         if (!BasicType.isBasicType(type))
          {
-            if (type.equals(pt.toString()))
-            {
-               correctType = true;
-               break;
-            }
-         }
-         if (!correctType)
-         {
             System.out.print(dbconf.getString("config.properties.type.tip") + " [");
-            for (PropsType pt : PropsType.values())
-            {
-               System.out.print(pt.toString());
-               System.out.print(", ");
-            }
-            System.out.println("]");
+            System.out.println(BasicType.allType() + "]");
             continue;
          }
          System.out.print("    " + dbconf.getString("config.properties.value"));
@@ -405,6 +396,65 @@
       }
       return props;
    }
+   
+   /**
+    * Input Methods
+    * @param dbconf ResourceBundle
+    * @param in BufferedReader
+    * @return List<MethodForConnection> list of properties
+    * @throws IOException ioException
+    */
+   private static List<MethodForConnection> inputMethod(ResourceBundle dbconf, BufferedReader in) 
+      throws IOException
+   {
+      List<MethodForConnection> methods = new ArrayList<MethodForConnection>();
+      while (true)
+      {
+         System.out.print("    " + dbconf.getString("connection.method.name"));
+         String methodName = in.readLine();
+         if (methodName == null || methodName.equals(""))
+            break;
+         MethodForConnection method = new MethodForConnection();
+         method.setMethodName(methodName);
+         System.out.print("    " + dbconf.getString("connection.method.return"));
+         String methodReturn = in.readLine();
+         if (!(methodReturn == null || methodReturn.equals("")))
+            method.setReturnType(methodReturn);
+         while (true)
+         {
+            System.out.print("    " + dbconf.getString("connection.method.param.name"));
+            String paramName = in.readLine();
+            if (paramName == null || paramName.equals(""))
+               break;
+            String paramType = null;
+            while (true)
+            {
+               System.out.print("    " + dbconf.getString("connection.method.param.type"));
+               paramType = in.readLine();
+               if (BasicType.isBasicType(paramType))
+                  break;
+               System.out.print(dbconf.getString("config.properties.type.tip") + " [");
+               System.out.println(BasicType.allType() + "]");
+            }
+            
+            MethodForConnection.Param param = method.newParam(paramName, paramType);
+            method.getParams().add(param);
+         }
+         
+         while (true)
+         {
+            System.out.print("    " + dbconf.getString("connection.method.exception"));
+            String exceptions = in.readLine();
+            if (exceptions == null || exceptions.equals(""))
+               break;
+            method.getExceptionType().add(exceptions);
+         }
+         methods.add(method);
+      }
+      
+      return methods;
+   
+   }
 
    /**
     * Tool usage

Added: projects/jboss-jca/trunk/codegenerator/src/main/java/org/jboss/jca/codegenerator/MethodForConnection.java
===================================================================
--- projects/jboss-jca/trunk/codegenerator/src/main/java/org/jboss/jca/codegenerator/MethodForConnection.java	                        (rev 0)
+++ projects/jboss-jca/trunk/codegenerator/src/main/java/org/jboss/jca/codegenerator/MethodForConnection.java	2010-06-17 10:07:10 UTC (rev 106107)
@@ -0,0 +1,188 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.jca.codegenerator;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * A MethodForConnection.
+ * 
+ * @author Jeff Zhang</a>
+ * @version $Revision: $
+ */
+public class MethodForConnection
+{
+   /** name */
+   private String methodName;
+   /** type */
+   private String returnType = "void";
+   /** value */
+   private List<Param> params = new ArrayList<Param>();
+   /** required */
+   private List<String> exceptionType = new ArrayList<String>();
+   
+   /** param */
+   public class Param
+   {
+      /** name */
+      private String name;
+      /** type */
+      private String type;
+      
+      /**
+       * Set the name.
+       * 
+       * @param name The name to set.
+       */
+      public void setName(String name)
+      {
+         this.name = name;
+      }
+      
+      /**
+       * Get the name.
+       * 
+       * @return the name.
+       */
+      public String getName()
+      {
+         return name;
+      }
+      
+      /**
+       * Set the type.
+       * 
+       * @param type The type to set.
+       */
+      public void setType(String type)
+      {
+         this.type = type;
+      }
+      
+      /**
+       * Get the type.
+       * 
+       * @return the type.
+       */
+      public String getType()
+      {
+         return type;
+      }
+   }
+
+   /**
+    * new param
+    * 
+    * @param name param name
+    * @param type param type
+    * @return new param
+    */
+   public Param newParam(String name, String type)
+   {
+      Param p = new Param();
+      p.setName(name);
+      p.setType(type);
+      return p;
+   }
+   
+   /**
+    * Set the methodName.
+    * 
+    * @param methodName The methodName to set.
+    */
+   public void setMethodName(String methodName)
+   {
+      this.methodName = methodName;
+   }
+
+   /**
+    * Get the methodName.
+    * 
+    * @return the methodName.
+    */
+   public String getMethodName()
+   {
+      return methodName;
+   }
+
+   /**
+    * Set the returnType.
+    * 
+    * @param returnType The returnType to set.
+    */
+   public void setReturnType(String returnType)
+   {
+      this.returnType = returnType;
+   }
+
+   /**
+    * Get the returnType.
+    * 
+    * @return the returnType.
+    */
+   public String getReturnType()
+   {
+      return returnType;
+   }
+
+   /**
+    * Set the params.
+    * 
+    * @param params The params to set.
+    */
+   public void setParams(List<Param> params)
+   {
+      this.params = params;
+   }
+
+   /**
+    * Get the params.
+    * 
+    * @return the params.
+    */
+   public List<Param> getParams()
+   {
+      return params;
+   }
+
+   /**
+    * Set the exceptionType.
+    * 
+    * @param exceptionType The exceptionType to set.
+    */
+   public void setExceptionType(List<String> exceptionType)
+   {
+      this.exceptionType = exceptionType;
+   }
+
+   /**
+    * Get the exceptionType.
+    * 
+    * @return the exceptionType.
+    */
+   public List<String> getExceptionType()
+   {
+      return exceptionType;
+   }
+
+}

Modified: projects/jboss-jca/trunk/codegenerator/src/main/java/org/jboss/jca/codegenerator/code/ConnImplCodeGen.java
===================================================================
--- projects/jboss-jca/trunk/codegenerator/src/main/java/org/jboss/jca/codegenerator/code/ConnImplCodeGen.java	2010-06-17 10:06:54 UTC (rev 106106)
+++ projects/jboss-jca/trunk/codegenerator/src/main/java/org/jboss/jca/codegenerator/code/ConnImplCodeGen.java	2010-06-17 10:07:10 UTC (rev 106107)
@@ -22,6 +22,7 @@
 package org.jboss.jca.codegenerator.code;
 
 import org.jboss.jca.codegenerator.Definition;
+import org.jboss.jca.codegenerator.MethodForConnection;
 
 import java.io.IOException;
 import java.io.Writer;
@@ -58,23 +59,7 @@
       
       writeDefaultConstructor(def, out, indent);
       
-      writeIndent(out, indent);
-      out.write("/**");
-      writeEol(out);
-      writeIndent(out, indent);
-      out.write(" * call me");
-      writeEol(out);
-      writeIndent(out, indent);
-      out.write(" */");
-      writeEol(out);
-      
-      writeIndent(out, indent);
-      out.write("public void callMe()");
-      writeLeftCurlyBracket(out, indent);
-      writeIndent(out, indent + 1);
-      out.write("log.debug(\"call callMe\");");
-
-      writeRightCurlyBracket(out, indent);
+      writeMethod(def, out, indent);
       writeRightCurlyBracket(out, 0);
    }
    
@@ -105,4 +90,90 @@
    {
       return def.getConnImplClass();
    }
+   
+   /**
+    * Output methods
+    * @param def definition
+    * @param out Writer
+    * @param indent space number
+    * @throws IOException ioException
+    */
+   private void writeMethod(Definition def, Writer out, int indent) throws IOException
+   {
+      if (def.isDefineMethodInConnection())
+      {
+         if (def.getMethods().size() > 0)
+         {
+            for (MethodForConnection method : def.getMethods())
+            {
+               writeIndent(out, indent);
+               out.write("/**");
+               writeEol(out);
+               writeIndent(out, indent);
+               out.write(" * call " + method.getMethodName());
+               writeEol(out);
+               writeIndent(out, indent);
+               out.write(" */");
+               writeEol(out);
+               
+               writeIndent(out, indent);
+               out.write("public " + method.getReturnType() + " " +
+                  method.getMethodName() + "(");
+               int paramSize = method.getParams().size();
+               for (int i = 0; i < paramSize; i++)
+               {
+                  MethodForConnection.Param param = method.getParams().get(i);
+                  out.write(param.getType());
+                  out.write(" ");
+                  out.write(param.getName());
+                  if (i + 1 < paramSize)
+                     out.write(", ");
+               }
+               out.write(")");
+               int exceptionSize = method.getExceptionType().size();
+               for (int i = 0; i < exceptionSize; i++)
+               {
+                  if (i == 0)
+                     out.write(" throws ");
+                  String ex = method.getExceptionType().get(i);
+                  out.write(ex);
+                  if (i + 1 < exceptionSize)
+                     out.write(", ");
+               }
+               writeLeftCurlyBracket(out, indent);
+               writeIndent(out, indent + 1);
+               out.write("log.debug(\"call " + method.getMethodName() + "\");");
+               writeEol(out);
+               if (!method.getReturnType().equals("void"))
+               {
+                  writeIndent(out, indent + 1);
+                  out.write("return null;");
+                  writeEol(out);
+               }
+
+               writeRightCurlyBracket(out, indent);
+            }
+         }
+      }
+      else
+      {
+         writeIndent(out, indent);
+         out.write("/**");
+         writeEol(out);
+         writeIndent(out, indent);
+         out.write(" * call me");
+         writeEol(out);
+         writeIndent(out, indent);
+         out.write(" */");
+         writeEol(out);
+         
+         writeIndent(out, indent);
+         out.write("public void callMe()");
+         writeLeftCurlyBracket(out, indent);
+         writeIndent(out, indent + 1);
+         out.write("log.debug(\"call callMe\");");
+
+         writeRightCurlyBracket(out, indent);
+      }
+   }
 }

Modified: projects/jboss-jca/trunk/codegenerator/src/main/java/org/jboss/jca/codegenerator/code/ConnInterfaceCodeGen.java
===================================================================
--- projects/jboss-jca/trunk/codegenerator/src/main/java/org/jboss/jca/codegenerator/code/ConnInterfaceCodeGen.java	2010-06-17 10:06:54 UTC (rev 106106)
+++ projects/jboss-jca/trunk/codegenerator/src/main/java/org/jboss/jca/codegenerator/code/ConnInterfaceCodeGen.java	2010-06-17 10:07:10 UTC (rev 106107)
@@ -22,6 +22,7 @@
 package org.jboss.jca.codegenerator.code;
 
 import org.jboss.jca.codegenerator.Definition;
+import org.jboss.jca.codegenerator.MethodForConnection;
 
 import java.io.IOException;
 import java.io.Writer;
@@ -49,19 +50,87 @@
       out.write("public interface " + getClassName(def));
       writeLeftCurlyBracket(out, 0);
       
-      writeIndent(out, indent);
-      out.write("/**");
-      writeEol(out);
-      writeIndent(out, indent);
-      out.write(" * call me");
-      writeEol(out);
-      writeIndent(out, indent);
-      out.write(" */");
-      writeEol(out);
-      
-      writeIndent(out, indent);
-      out.write("public void callMe();");
+      if (def.isDefineMethodInConnection())
+      {
+         if (def.getMethods().size() > 0)
+         {
+            for (MethodForConnection method : def.getMethods())
+            {
+               writeIndent(out, indent);
+               out.write("/**");
+               writeEol(out);
+               writeIndent(out, indent);
+               out.write(" * " + method.getMethodName());
+               writeEol(out);
+               for (MethodForConnection.Param param : method.getParams())
+               {
+                  writeIndent(out, indent);
+                  out.write(" * @param " + param.getName() + " " + param.getName());
+                  writeEol(out);
+               }
+               if (!method.getReturnType().equals("void"))
+               {
+                  writeIndent(out, indent);
+                  out.write(" * @return " + method.getReturnType());
+                  writeEol(out);
+               }
+               for (String ex : method.getExceptionType())
+               {
+                  writeIndent(out, indent);
+                  out.write(" * @throws " + ex + " " + ex);
+                  writeEol(out);
+               }
+               
+               writeIndent(out, indent);
+               out.write(" */");
+               writeEol(out);
+               
+               writeIndent(out, indent);
+               out.write("public " + method.getReturnType() + " " +
+                  method.getMethodName() + "(");
+               int paramSize = method.getParams().size();
+               for (int i = 0; i < paramSize; i++)
+               {
+                  MethodForConnection.Param param = method.getParams().get(i);
+                  out.write(param.getType());
+                  out.write(" ");
+                  out.write(param.getName());
+                  if (i + 1 < paramSize)
+                     out.write(", ");
+               }
+               out.write(")");
+               int exceptionSize = method.getExceptionType().size();
+               for (int i = 0; i < exceptionSize; i++)
+               {
+                  if (i == 0)
+                     out.write(" throws ");
+                  String ex = method.getExceptionType().get(i);
+                  out.write(ex);
+                  if (i + 1 < exceptionSize)
+                     out.write(", ");
+               }
 
+               out.write(";");
+               writeEol(out);
+            }
+         }
+      }
+      else
+      {
+         writeIndent(out, indent);
+         out.write("/**");
+         writeEol(out);
+         writeIndent(out, indent);
+         out.write(" * call me");
+         writeEol(out);
+         writeIndent(out, indent);
+         out.write(" */");
+         writeEol(out);
+         
+         writeIndent(out, indent);
+         out.write("public void callMe();");
+      }
+
       writeRightCurlyBracket(out, 0);
    }
    

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 10:06:54 UTC (rev 106106)
+++ projects/jboss-jca/trunk/codegenerator/src/main/java/org/jboss/jca/codegenerator/code/TestCodeGen.java	2010-06-17 10:07:10 UTC (rev 106107)
@@ -21,7 +21,9 @@
  */
 package org.jboss.jca.codegenerator.code;
 
+import org.jboss.jca.codegenerator.BasicType;
 import org.jboss.jca.codegenerator.Definition;
+import org.jboss.jca.codegenerator.MethodForConnection;
 
 import java.io.IOException;
 import java.io.Writer;
@@ -60,7 +62,13 @@
       writeEol(out);
 
       writeDeployment(def, out, indent);
-      writeTestBasic(def, out, indent);
+      
+      if (def.isDefineMethodInConnection())
+      {
+         writeTestMethod(def, out, indent);
+      }
+      else
+         writeTestBasic(def, out, indent);
 
       writeRightCurlyBracket(out, 0);
    }
@@ -284,4 +292,108 @@
       writeRightCurlyBracket(out, indent + 1);
       writeRightCurlyBracket(out, indent);
    }
+   
+   /**
+    * Output test generated method
+    * @param def definition
+    * @param out Writer
+    * @param indent space number
+    * @throws IOException ioException
+    */
+   private void writeTestMethod(Definition def, Writer out, int indent) throws IOException
+   {
+      for (MethodForConnection method : def.getMethods())
+      {
+         writeIndent(out, indent);
+         out.write("/**");
+         writeEol(out);
+         writeIndent(out, indent);
+         out.write(" * Test " + method.getMethodName());
+         writeEol(out);
+         writeIndent(out, indent);
+         out.write(" *");
+         writeEol(out);
+         writeIndent(out, indent);
+         out.write(" * @exception Throwable Thrown if case of an error");
+         writeEol(out);
+         writeIndent(out, indent);
+         out.write(" */");
+         writeEol(out);
+   
+         writeIndent(out, indent);
+         out.write("@Test");
+         writeEol(out);
+         writeIndent(out, indent);
+         out.write("public void test" + upcaseFirst(method.getMethodName()) + "() throws Throwable");
+         writeLeftCurlyBracket(out, indent);
+         
+         writeIndent(out, indent + 1);
+         out.write("Context context = null;");
+         writeEol(out);
+         writeIndent(out, indent + 1);
+         out.write("try");
+         writeLeftCurlyBracket(out, indent + 1);
+         writeIndent(out, indent + 2);
+         out.write("context = new InitialContext();");
+         writeEol(out);
+         writeIndent(out, indent + 2);
+         out.write(def.getCfInterfaceClass() + " cf = (" + def.getCfInterfaceClass() + 
+            ")context.lookup(JNDI_PREFIX + deploymentName);");
+         writeEol(out);
+         writeIndent(out, indent + 2);
+         out.write("assertNotNull(cf);");
+         writeEol(out);
+         writeIndent(out, indent + 2);
+         out.write(def.getConnInterfaceClass() + " c = cf.getConnection();");
+         writeEol(out);
+         writeIndent(out, indent + 2);
+         out.write("assertNotNull(c);");
+         writeEol(out);
+         writeIndent(out, indent + 2);
+         out.write("c." + method.getMethodName() + "(");
+         int paramSize = method.getParams().size();
+         for (int i = 0; i < paramSize; i++)
+         {
+            MethodForConnection.Param param = method.getParams().get(i);
+            out.write(BasicType.defaultValue(param.getType()));
+            if (i + 1 < paramSize)
+               out.write(", ");
+         }
+         out.write(");");
+         writeEol(out);
+         
+         writeRightCurlyBracket(out, indent + 1);
+         writeIndent(out, indent + 1);
+         out.write("catch (Throwable t)");
+         writeLeftCurlyBracket(out, indent + 1);
+         writeIndent(out, indent + 2);
+         out.write("log.error(t.getMessage(), t);");
+         writeEol(out);
+         writeIndent(out, indent + 2);
+         out.write("fail(t.getMessage());");
+         writeRightCurlyBracket(out, indent + 1);
+         writeIndent(out, indent + 1);
+         out.write("finally");
+         writeLeftCurlyBracket(out, indent + 1);
+         writeIndent(out, indent + 2);
+         out.write("if (context != null)");
+         writeLeftCurlyBracket(out, indent + 2);
+         writeIndent(out, indent + 3);
+         out.write("try");
+         writeLeftCurlyBracket(out, indent + 3);
+         writeIndent(out, indent + 4);
+         out.write("context.close();");
+         writeRightCurlyBracket(out, indent + 3);
+         writeIndent(out, indent + 3);
+         out.write("catch (NamingException ne)");
+         writeLeftCurlyBracket(out, indent + 3);
+         writeIndent(out, indent + 4);
+         out.write("// Ignore");
+         writeRightCurlyBracket(out, indent + 3);
+         writeRightCurlyBracket(out, indent + 2);
+         writeRightCurlyBracket(out, indent + 1);
+         writeRightCurlyBracket(out, indent);
+         writeEol(out);
+      }
+   }
 }

Modified: projects/jboss-jca/trunk/codegenerator/src/main/resources/codegenerator.properties
===================================================================
--- projects/jboss-jca/trunk/codegenerator/src/main/resources/codegenerator.properties	2010-06-17 10:06:54 UTC (rev 106106)
+++ projects/jboss-jca/trunk/codegenerator/src/main/resources/codegenerator.properties	2010-06-17 10:07:10 UTC (rev 106107)
@@ -24,5 +24,11 @@
 as.config.properties=ActivationSpec config properties [enter to quit]:
 acti.class.name=Activation class name: 
 support.transaction=Transaction support [N/NoTransaction/L/LocalTransaction/X/XATransaction]: 
+connection.method.support=Add methods to connection interface [Y/Yes/N/No]: 
+connection.method.name=Method name [enter to quit]: 
+connection.method.return=Return type: 
+connection.method.param.name=Parameter name [enter to quit]: 
+connection.method.param.type=Parameter type: 
+connection.method.exception=Exception type [enter to quit]: 
 output.dir=Output directory: 
 code.wrote=Code generated 



More information about the jboss-cvs-commits mailing list