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

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Fri Jun 4 06:48:28 EDT 2010


Author: jeff.zhang
Date: 2010-06-04 06:48:27 -0400 (Fri, 04 Jun 2010)
New Revision: 105714

Added:
   projects/jboss-jca/trunk/codegenerator/src/main/java/org/jboss/jca/codegenerator/JCA15Profile.java
   projects/jboss-jca/trunk/codegenerator/src/main/java/org/jboss/jca/codegenerator/xml/Ra15XmlGen.java
   projects/jboss-jca/trunk/codegenerator/src/main/java/org/jboss/jca/codegenerator/xml/Ra16XmlGen.java
Modified:
   projects/jboss-jca/trunk/codegenerator/src/main/java/org/jboss/jca/codegenerator/JCA16Profile.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/xml/RaXmlGen.java
   projects/jboss-jca/trunk/codegenerator/src/main/resources/codegenerator.properties
Log:
[JBJCA-309] add profile 1.5 support

Added: projects/jboss-jca/trunk/codegenerator/src/main/java/org/jboss/jca/codegenerator/JCA15Profile.java
===================================================================
--- projects/jboss-jca/trunk/codegenerator/src/main/java/org/jboss/jca/codegenerator/JCA15Profile.java	                        (rev 0)
+++ projects/jboss-jca/trunk/codegenerator/src/main/java/org/jboss/jca/codegenerator/JCA15Profile.java	2010-06-04 10:48:27 UTC (rev 105714)
@@ -0,0 +1,165 @@
+/*
+ * 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 org.jboss.jca.codegenerator.code.AbstractCodeGen;
+import org.jboss.jca.codegenerator.xml.BuildXmlGen;
+import org.jboss.jca.codegenerator.xml.Ra15XmlGen;
+
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+
+/**
+ * A JCA15Profile.
+ * 
+ * @author Jeff Zhang
+ * @version $Revision: $
+ */
+public class JCA15Profile implements Profile
+{
+
+   /**
+    * JCA15Profile
+    */
+   public JCA15Profile()
+   {
+   }
+   
+  
+   /**
+    * generate code
+    * @param def Definition 
+    * @param packageName the writer to output the text to.
+    */
+   @Override
+   public void generate(Definition def, String packageName)
+   {
+      generateClassCode(def, "Ra");
+      generateClassCode(def, "Mcf");
+      generateClassCode(def, "Mc");
+      generateClassCode(def, "McMeta");
+      generateClassCode(def, "Cm");
+
+      if (!def.isUseCciConnection())
+      {
+         generateClassCode(def, "CfInterface");
+         generateClassCode(def, "Cf");
+         generateClassCode(def, "ConnInterface");
+         generateClassCode(def, "ConnImpl");
+      }
+      else
+      {
+         generateClassCode(def, "CciConn");
+         generateClassCode(def, "CciConnFactory");
+         generateClassCode(def, "ConnMeta");
+         generateClassCode(def, "RaMeta");
+         generateClassCode(def, "ConnSpec");
+      }
+      
+      if (def.isSupportInbound())
+      {
+         generateClassCode(def, "Ml");
+         generateClassCode(def, "As");
+      }
+      
+      generateAntXml(def.getOutputDir());
+
+      generateRaXml(def, def.getOutputDir());
+   }
+
+   /**
+    * generate ResourceAdapater code
+    * @param def Definition 
+    * @param packageName the writer to output the text to.
+    */
+   private void generateClassCode(Definition def, String className)
+   {
+      if (className == null || className.equals(""))
+         return;
+      
+      try
+      {
+
+         String clazzName = this.getClass().getPackage().getName() + ".code." + className + "CodeGen";
+         String javaFile = (String)Definition.class.getMethod(
+            "get" + className + "Class").invoke(def, (Object[])null) + ".java";
+         FileWriter fw = Utils.createSrcFile(javaFile, def.getRaPackage(), def.getOutputDir());
+
+         Class<?> clazz = Class.forName(clazzName, true, Thread.currentThread().getContextClassLoader());
+         AbstractCodeGen codeGen = (AbstractCodeGen)clazz.newInstance();
+         
+         codeGen.generate(def, fw);
+         
+         fw.flush();
+         fw.close();
+      }
+      catch (IOException ioe)
+      {
+         ioe.printStackTrace();
+      }
+      catch (Exception e)
+      {
+         e.printStackTrace();
+      }
+   }
+   
+   /**
+    * generate ant build.xml
+    * @param outputDir output directory
+    */
+   private void generateAntXml(String outputDir)
+   {
+      try
+      {
+         //ant build.xml
+         FileWriter antfw = Utils.createFile("build.xml", outputDir);
+         BuildXmlGen bxGen = new BuildXmlGen();
+         bxGen.generate(null, antfw);
+         antfw.close();
+      }
+      catch (IOException ioe)
+      {
+         ioe.printStackTrace();
+      }
+   }
+
+   /**
+    * generate ra.xml
+    * @param def Definition
+    * @param outputDir output directory
+    */
+   private void generateRaXml(Definition def, String outputDir)
+   {
+      try
+      {
+         FileWriter rafw = Utils.createFile("ra.xml", outputDir + File.separatorChar + "META-INF");
+         Ra15XmlGen raGen = new Ra15XmlGen();
+         raGen.generate(def, rafw);
+         rafw.close();
+      }
+      catch (IOException ioe)
+      {
+         ioe.printStackTrace();
+      }
+   }
+}

Modified: projects/jboss-jca/trunk/codegenerator/src/main/java/org/jboss/jca/codegenerator/JCA16Profile.java
===================================================================
--- projects/jboss-jca/trunk/codegenerator/src/main/java/org/jboss/jca/codegenerator/JCA16Profile.java	2010-06-04 09:53:32 UTC (rev 105713)
+++ projects/jboss-jca/trunk/codegenerator/src/main/java/org/jboss/jca/codegenerator/JCA16Profile.java	2010-06-04 10:48:27 UTC (rev 105714)
@@ -23,7 +23,7 @@
 
 import org.jboss.jca.codegenerator.code.AbstractCodeGen;
 import org.jboss.jca.codegenerator.xml.BuildXmlGen;
-import org.jboss.jca.codegenerator.xml.RaXmlGen;
+import org.jboss.jca.codegenerator.xml.Ra16XmlGen;
 
 import java.io.File;
 import java.io.FileWriter;
@@ -154,7 +154,7 @@
       try
       {
          FileWriter rafw = Utils.createFile("ra.xml", outputDir + File.separatorChar + "META-INF");
-         RaXmlGen raGen = new RaXmlGen();
+         Ra16XmlGen raGen = new Ra16XmlGen();
          raGen.generate(def, rafw);
          rafw.close();
       }

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-04 09:53:32 UTC (rev 105713)
+++ projects/jboss-jca/trunk/codegenerator/src/main/java/org/jboss/jca/codegenerator/Main.java	2010-06-04 10:48:27 UTC (rev 105714)
@@ -92,26 +92,39 @@
 
          BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
          Definition def = new Definition();
-
-         System.out.print(dbconf.getString("use.annotation"));
-         String useAnnotation = in.readLine();
-         if (useAnnotation == null)
-            def.setUseAnnotation(false);
-         else
+         
+         String version = null;
+         do
          {
-            if (useAnnotation.equals("Y") || useAnnotation.equals("y") || useAnnotation.equals("Yes"))
-               def.setUseAnnotation(true);
+            System.out.print(dbconf.getString("profile.version"));
+            version = in.readLine();
+            if (version == null || version.equals(""))
+               version = "1.6";
+         }
+         while (!(version.equals("1.6") || version.equals("1.5")));
+         
+         if (version.equals("1.6"))
+         {
+            System.out.print(dbconf.getString("use.annotation"));
+            String useAnnotation = in.readLine();
+            if (useAnnotation == null)
+               def.setUseAnnotation(false);
             else
-               def.setUseAnnotation(false);
+            {
+               if (useAnnotation.equals("Y") || useAnnotation.equals("y") || useAnnotation.equals("Yes"))
+                  def.setUseAnnotation(true);
+               else
+                  def.setUseAnnotation(false);
+            }
          }
+         else
+            def.setUseAnnotation(false);
          
          System.out.print(dbconf.getString("package.name"));
          String packageName = in.readLine();
          System.out.print(dbconf.getString("ra.class.name"));
          String raClassName = in.readLine();
          
-
-         Profile profile = new JCA16Profile();
          def.setRaPackage(packageName);
          def.setRaClass(raClassName);
          
@@ -196,6 +209,17 @@
          
          def.setOutputDir(outputDir);
 
+         Profile profile;
+
+         if (version.equals("1.6"))
+         {
+            profile = new JCA16Profile();
+         }
+         else
+         {
+            profile = new JCA15Profile();
+         }
+
          profile.generate(def, packageName);
          
          System.out.println(dbconf.getString("code.wrote"));

Added: projects/jboss-jca/trunk/codegenerator/src/main/java/org/jboss/jca/codegenerator/xml/Ra15XmlGen.java
===================================================================
--- projects/jboss-jca/trunk/codegenerator/src/main/java/org/jboss/jca/codegenerator/xml/Ra15XmlGen.java	                        (rev 0)
+++ projects/jboss-jca/trunk/codegenerator/src/main/java/org/jboss/jca/codegenerator/xml/Ra15XmlGen.java	2010-06-04 10:48:27 UTC (rev 105714)
@@ -0,0 +1,59 @@
+/*
+ * 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.xml;
+
+import java.io.IOException;
+import java.io.Writer;
+
+/**
+ * A BuildXmlGen.
+ * 
+ * @author Jeff Zhang
+ * @version $Revision: $
+ */
+public class Ra15XmlGen extends RaXmlGen
+{
+   /**
+    * write Connector Version
+    * 
+    * @param out output writer
+    * @throws IOException io exception
+    */
+   @Override
+   void writeConnectorVersion(Writer out) throws IOException
+   {
+      out.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
+      writeEol(out);
+      writeEol(out);
+      out.write("<connector xmlns=\"http://java.sun.com/xml/ns/j2ee\"");
+      writeEol(out);
+      out.write("           xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"");
+      writeEol(out);
+      out.write("           xsi:schemaLocation=\"http://java.sun.com/xml/ns/j2ee");
+      writeEol(out);
+      out.write("           http://java.sun.com/xml/ns/j2ee/connector_1_5.xsd\"");
+      writeEol(out);
+      out.write("           version=\"1.5\">");
+      writeEol(out);
+      writeEol(out);
+   }
+}

Added: projects/jboss-jca/trunk/codegenerator/src/main/java/org/jboss/jca/codegenerator/xml/Ra16XmlGen.java
===================================================================
--- projects/jboss-jca/trunk/codegenerator/src/main/java/org/jboss/jca/codegenerator/xml/Ra16XmlGen.java	                        (rev 0)
+++ projects/jboss-jca/trunk/codegenerator/src/main/java/org/jboss/jca/codegenerator/xml/Ra16XmlGen.java	2010-06-04 10:48:27 UTC (rev 105714)
@@ -0,0 +1,59 @@
+/*
+ * 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.xml;
+
+import java.io.IOException;
+import java.io.Writer;
+
+/**
+ * A BuildXmlGen.
+ * 
+ * @author Jeff Zhang
+ * @version $Revision: $
+ */
+public class Ra16XmlGen extends RaXmlGen
+{
+   /**
+    * write Connector Version
+    * 
+    * @param out output writer
+    * @throws IOException io exception
+    */
+   @Override
+   void writeConnectorVersion(Writer out) throws IOException
+   {
+      out.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
+      writeEol(out);
+      writeEol(out);
+      out.write("<connector xmlns=\"http://java.sun.com/xml/ns/javaee\"");
+      writeEol(out);
+      out.write("           xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"");
+      writeEol(out);
+      out.write("           xsi:schemaLocation=\"http://java.sun.com/xml/ns/javaee");
+      writeEol(out);
+      out.write("           http://java.sun.com/xml/ns/j2ee/connector_1_6.xsd\"");
+      writeEol(out);
+      out.write("           version=\"1.6\" metadata-complete=\"true\">");
+      writeEol(out);
+      writeEol(out);
+   }
+}

Modified: projects/jboss-jca/trunk/codegenerator/src/main/java/org/jboss/jca/codegenerator/xml/RaXmlGen.java
===================================================================
--- projects/jboss-jca/trunk/codegenerator/src/main/java/org/jboss/jca/codegenerator/xml/RaXmlGen.java	2010-06-04 09:53:32 UTC (rev 105713)
+++ projects/jboss-jca/trunk/codegenerator/src/main/java/org/jboss/jca/codegenerator/xml/RaXmlGen.java	2010-06-04 10:48:27 UTC (rev 105714)
@@ -34,25 +34,13 @@
  * @author Jeff Zhang
  * @version $Revision: $
  */
-public class RaXmlGen extends AbstractXmlGen
+public abstract class RaXmlGen extends AbstractXmlGen
 {
    @Override
    public void writeXmlBody(Definition def, Writer out) throws IOException
    {
-      out.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
-      writeEol(out);
-      writeEol(out);
-      out.write("<connector xmlns=\"http://java.sun.com/xml/ns/javaee\"");
-      writeEol(out);
-      out.write("           xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"");
-      writeEol(out);
-      out.write("           xsi:schemaLocation=\"http://java.sun.com/xml/ns/javaee");
-      writeEol(out);
-      out.write("           http://java.sun.com/xml/ns/j2ee/connector_1_6.xsd\"");
-      writeEol(out);
-      out.write("           version=\"1.6\" metadata-complete=\"true\">");
-      writeEol(out);
-      writeEol(out);
+      writeConnectorVersion(out);
+      
       int indent = 1;
       writeIndent(out, indent);
       out.write("<vendor-name>Red Hat Middleware LLC</vendor-name>");
@@ -81,6 +69,14 @@
       out.write("</connector>");
       writeEol(out);
    }
+
+   /**
+    * write Connector Version
+    * 
+    * @param out output writer
+    * @throws IOException io exception
+    */
+   abstract void writeConnectorVersion(Writer out) throws IOException;
    
    /**
     * Output config props xml part

Modified: projects/jboss-jca/trunk/codegenerator/src/main/resources/codegenerator.properties
===================================================================
--- projects/jboss-jca/trunk/codegenerator/src/main/resources/codegenerator.properties	2010-06-04 09:53:32 UTC (rev 105713)
+++ projects/jboss-jca/trunk/codegenerator/src/main/resources/codegenerator.properties	2010-06-04 10:48:27 UTC (rev 105714)
@@ -1,3 +1,4 @@
+profile.version=Profile version: [1.6/1.5] 
 use.annotation=Use Annotation: [Y/N/Yes/No] 
 package.name=Package name: 
 ra.class.name=Resource adapter class name: 




More information about the jboss-cvs-commits mailing list