[jboss-cvs] JBossAS SVN: r105206 - in projects/jboss-jca/trunk/codegenerator/src/main: resources and 1 other directory.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Tue May 25 04:03:16 EDT 2010


Author: jeff.zhang
Date: 2010-05-25 04:03:15 -0400 (Tue, 25 May 2010)
New Revision: 105206

Added:
   projects/jboss-jca/trunk/codegenerator/src/main/java/org/jboss/jca/codegenerator/SimpleTemplate.java
   projects/jboss-jca/trunk/codegenerator/src/main/java/org/jboss/jca/codegenerator/Template.java
   projects/jboss-jca/trunk/codegenerator/src/main/resources/ra.xml.template
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/McfCodeGen.java
   projects/jboss-jca/trunk/codegenerator/src/main/java/org/jboss/jca/codegenerator/PropsCodeGen.java
   projects/jboss-jca/trunk/codegenerator/src/main/java/org/jboss/jca/codegenerator/RaCodeGen.java
   projects/jboss-jca/trunk/codegenerator/src/main/resources/build.xml.template
   projects/jboss-jca/trunk/codegenerator/src/main/resources/codegenerator.properties
Log:
[JBJCA-318] generate ra.xml if choose no annotation

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-05-25 07:00:34 UTC (rev 105205)
+++ projects/jboss-jca/trunk/codegenerator/src/main/java/org/jboss/jca/codegenerator/Definition.java	2010-05-25 08:03:15 UTC (rev 105206)
@@ -77,6 +77,9 @@
    /** resource adapater metadata class name */
    private String raMetaClass;
    
+   /** use annotation or ra.xml  */
+   private boolean useAnnotation;
+   
    /**
     * Set the outputDir.
     * 
@@ -491,4 +494,24 @@
       return raMetaClass;
    }
 
+   /**
+    * Set the useAnnotation.
+    * 
+    * @param useAnnotation The useAnnotation to set.
+    */
+   public void setUseAnnotation(boolean useAnnotation)
+   {
+      this.useAnnotation = useAnnotation;
+   }
+
+   /**
+    * Get the useAnnotation.
+    * 
+    * @return the useAnnotation.
+    */
+   public boolean isUseAnnotation()
+   {
+      return useAnnotation;
+   }
+
 }

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-05-25 07:00:34 UTC (rev 105205)
+++ projects/jboss-jca/trunk/codegenerator/src/main/java/org/jboss/jca/codegenerator/Main.java	2010-05-25 08:03:15 UTC (rev 105206)
@@ -22,13 +22,16 @@
 package org.jboss.jca.codegenerator;
 
 import java.io.BufferedReader;
+import java.io.File;
 import java.io.FileWriter;
 import java.io.IOException;
 import java.io.InputStreamReader;
 import java.net.URL;
 import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.List;
 import java.util.Locale;
+import java.util.Map;
 import java.util.ResourceBundle;
 
 /**
@@ -93,6 +96,20 @@
          ResourceBundle dbconf = ResourceBundle.getBundle("codegenerator", Locale.getDefault());
 
          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
+         {
+            if (useAnnotation.equals("Y") || useAnnotation.equals("y") || useAnnotation.equals("Yes"))
+               def.setUseAnnotation(true);
+            else
+               def.setUseAnnotation(false);
+         }
+         
          System.out.print(dbconf.getString("package.name"));
          String packageName = in.readLine();
          System.out.print(dbconf.getString("ra.class.name"));
@@ -100,7 +117,6 @@
          
 
          Profile profile = new JCA16AnnoProfile();
-         Definition def = new Definition();
          def.setRaPackage(packageName);
          def.setRaClass(raClassName);
          
@@ -165,6 +181,9 @@
          
          generateAntXml(outputDir);
          
+         if (!def.isUseAnnotation())
+            generateRaXml(def, outputDir);
+         
          System.out.println(dbconf.getString("code.wrote"));
       }
       catch (IOException e)
@@ -174,6 +193,76 @@
    }
 
    /**
+    * generate ra.xml
+    * @param def Definition
+    * @param outputDir output directory
+    * @throws IOException ioException
+    */
+   private static void generateRaXml(Definition def, String outputDir) throws IOException
+   {
+      FileWriter rafw = Utils.createFile("ra.xml", outputDir + File.separatorChar + "META-INF");
+      URL templateFile = Main.class.getResource("/ra.xml.template");
+      String raString = Utils.readFileIntoString(templateFile);
+      Template template = new SimpleTemplate(raString);
+      Map<String, String> varMap = new HashMap<String, String>();
+      varMap.put("package.name", def.getRaPackage());
+      varMap.put("ra.class", def.getRaPackage() + "." + def.getRaClass());
+      varMap.put("mcf.class", def.getRaPackage() + "." + def.getMcfClass());
+      if (!def.isUseCciConnection())
+      {
+         varMap.put("cf.interface", def.getRaPackage() + "." + def.getCfInterfaceClass());
+         varMap.put("cf.class", def.getRaPackage() + "." + def.getCfClass());
+         varMap.put("conn.interface", def.getRaPackage() + "." + def.getConnInterfaceClass());
+         varMap.put("conn.class", def.getRaPackage() + "." + def.getConnImplClass());
+      }
+      else
+      {
+         varMap.put("cf.interface", "javax.resource.cci.ConnectionFactory");
+         varMap.put("cf.class", def.getRaPackage() + "." + def.getCciConnFactoryClass());
+         varMap.put("conn.interface", "javax.resource.cci.Connection");
+         varMap.put("conn.class", def.getRaPackage() + "." + def.getCciConnClass());
+      }
+      List<ConfigPropType> listRaProps = def.getRaConfigProps();
+      if (listRaProps.size() > 0)
+      {
+         String raProps = extractPropString(listRaProps);
+         varMap.put("ra.config.props", raProps);
+      }
+      List<ConfigPropType> listMcfProps = def.getMcfConfigProps();
+      if (listMcfProps.size() > 0)
+      {
+         String raProps = extractPropString(listMcfProps);
+         varMap.put("mcf.config.props", raProps);
+      }
+      
+      template.process(varMap, rafw);
+      rafw.close();
+   }
+
+   /**
+    * extract properties string
+    * 
+    * @param listPropType
+    * @return String properties string
+    */
+   private static String extractPropString(List<ConfigPropType> listPropType)
+   {
+      StringBuilder props = new StringBuilder();
+      if (listPropType.size() > 0)
+      {
+         props.append("<config-property>\n");
+         for (ConfigPropType prop : listPropType)
+         {
+            props.append("         <config-property-name>" + prop.getName() + "</config-property-name>\n");
+            props.append("         <config-property-type>java.lang." + prop.getType() + "</config-property-type>\n");
+            props.append("         <config-property-value>" + prop.getValue() + "</config-property-value>\n");
+         }
+         props.append("      </config-property>\n");
+      }
+      return props.toString();
+   }
+
+   /**
     * Input Properties
     * @param classname belong to which java class
     * @param dbconf ResourceBundle
@@ -225,16 +314,17 @@
    }
 
    /**
-    * generateAnt build.xml
+    * generate ant build.xml
     * @param outputDir output directory
+    * @throws IOException ioException
     */
    private static void generateAntXml(String outputDir) throws IOException
    {
       //ant build.xml
       FileWriter antfw = Utils.createFile("build.xml", outputDir);
-      URL headerFile = Main.class.getResource("/build.xml.template");
-      String headerString = Utils.readFileIntoString(headerFile);
-      antfw.write(headerString);
+      URL buildFile = Main.class.getResource("/build.xml.template");
+      String buildString = Utils.readFileIntoString(buildFile);
+      antfw.write(buildString);
       antfw.close();
    }
 

Modified: projects/jboss-jca/trunk/codegenerator/src/main/java/org/jboss/jca/codegenerator/McfCodeGen.java
===================================================================
--- projects/jboss-jca/trunk/codegenerator/src/main/java/org/jboss/jca/codegenerator/McfCodeGen.java	2010-05-25 07:00:34 UTC (rev 105205)
+++ projects/jboss-jca/trunk/codegenerator/src/main/java/org/jboss/jca/codegenerator/McfCodeGen.java	2010-05-25 08:03:15 UTC (rev 105206)
@@ -44,35 +44,38 @@
    public void writeClassBody(Definition def, Writer out) throws IOException
    {
       int indent = 1;
-      if (!def.isUseCciConnection())
+      if (def.isUseAnnotation())
       {
-         out.write("@ConnectionDefinition(connectionFactory = " + def.getCfInterfaceClass() + ".class,");
-         writeEol(out);
-         writeIndent(out, indent);
-         out.write("connectionFactoryImpl = " + def.getCfClass() + ".class,");
-         writeEol(out);
-         writeIndent(out, indent);
-         out.write("connection = " + def.getConnInterfaceClass() + ".class,");
-         writeEol(out);
-         writeIndent(out, indent);
-         out.write("connectionImpl = " + def.getConnImplClass() + ".class)");
-         writeEol(out);
+         if (!def.isUseCciConnection())
+         {
+            out.write("@ConnectionDefinition(connectionFactory = " + def.getCfInterfaceClass() + ".class,");
+            writeEol(out);
+            writeIndent(out, indent);
+            out.write("connectionFactoryImpl = " + def.getCfClass() + ".class,");
+            writeEol(out);
+            writeIndent(out, indent);
+            out.write("connection = " + def.getConnInterfaceClass() + ".class,");
+            writeEol(out);
+            writeIndent(out, indent);
+            out.write("connectionImpl = " + def.getConnImplClass() + ".class)");
+            writeEol(out);
+         }
+         else
+         {
+            out.write("@ConnectionDefinition(connectionFactory = ConnectionFactory.class,");
+            writeEol(out);
+            writeIndent(out, indent);
+            out.write("connectionFactoryImpl = " + def.getCciConnFactoryClass() + ".class,");
+            writeEol(out);
+            
+            writeIndent(out, indent);
+            out.write("connection = Connection.class,");
+            writeEol(out);
+            writeIndent(out, indent);
+            out.write("connectionImpl = " + def.getCciConnClass() + ".class)");
+            writeEol(out);
+         }
       }
-      else
-      {
-         out.write("@ConnectionDefinition(connectionFactory = ConnectionFactory.class,");
-         writeEol(out);
-         writeIndent(out, indent);
-         out.write("connectionFactoryImpl = " + def.getCciConnFactoryClass() + ".class,");
-         writeEol(out);
-         
-         writeIndent(out, indent);
-         out.write("connection = Connection.class,");
-         writeEol(out);
-         writeIndent(out, indent);
-         out.write("connectionImpl = " + def.getCciConnClass() + ".class)");
-         writeEol(out);
-      }
 
       out.write("public class " + getClassName(def) + " implements ManagedConnectionFactory");
       if (def.isImplRaAssociation())
@@ -154,10 +157,13 @@
          writeEol(out);
       }
       
-      out.write("import javax.resource.spi.ConfigProperty;");
-      writeEol(out);
-      out.write("import javax.resource.spi.ConnectionDefinition;");
-      writeEol(out);
+      if (def.isUseAnnotation())
+      {
+         out.write("import javax.resource.spi.ConfigProperty;");
+         writeEol(out);
+         out.write("import javax.resource.spi.ConnectionDefinition;");
+         writeEol(out);
+      }
       out.write("import javax.resource.spi.ConnectionManager;");
       writeEol(out);
       out.write("import javax.resource.spi.ConnectionRequestInfo;");

Modified: projects/jboss-jca/trunk/codegenerator/src/main/java/org/jboss/jca/codegenerator/PropsCodeGen.java
===================================================================
--- projects/jboss-jca/trunk/codegenerator/src/main/java/org/jboss/jca/codegenerator/PropsCodeGen.java	2010-05-25 07:00:34 UTC (rev 105205)
+++ projects/jboss-jca/trunk/codegenerator/src/main/java/org/jboss/jca/codegenerator/PropsCodeGen.java	2010-05-25 08:03:15 UTC (rev 105206)
@@ -51,10 +51,13 @@
          out.write("/** " + getConfigProps(def).get(i).getName() + " */");
          writeEol(out);
          
+         if (def.isUseAnnotation())
+         {
+            writeIndent(out, indent);
+            out.write("@ConfigProperty(defaultValue=\"" + getConfigProps(def).get(i).getValue() + "\")");
+            writeEol(out);
+         }
          writeIndent(out, indent);
-         out.write("@ConfigProperty(defaultValue=\"" + getConfigProps(def).get(i).getValue() + "\")");
-         writeEol(out);
-         writeIndent(out, indent);
          out.write("private " + 
                    getConfigProps(def).get(i).getType() +
                    " " +

Modified: projects/jboss-jca/trunk/codegenerator/src/main/java/org/jboss/jca/codegenerator/RaCodeGen.java
===================================================================
--- projects/jboss-jca/trunk/codegenerator/src/main/java/org/jboss/jca/codegenerator/RaCodeGen.java	2010-05-25 07:00:34 UTC (rev 105205)
+++ projects/jboss-jca/trunk/codegenerator/src/main/java/org/jboss/jca/codegenerator/RaCodeGen.java	2010-05-25 08:03:15 UTC (rev 105206)
@@ -42,8 +42,11 @@
    @Override
    public void writeClassBody(Definition def, Writer out) throws IOException
    {
-      out.write("@Connector");
-      writeEol(out);
+      if (def.isUseAnnotation())
+      {
+         out.write("@Connector");
+         writeEol(out);
+      }
       out.write("public class " + getClassName(def) + " implements ResourceAdapter");
       writeLeftCurlyBracket(out, 0);
       writeEol(out);
@@ -88,10 +91,13 @@
       writeEol(out);
       out.write("import javax.resource.spi.BootstrapContext;");
       writeEol(out);
-      out.write("import javax.resource.spi.ConfigProperty;");
-      writeEol(out);
-      out.write("import javax.resource.spi.Connector;");
-      writeEol(out);
+      if (def.isUseAnnotation())
+      {
+         out.write("import javax.resource.spi.ConfigProperty;");
+         writeEol(out);
+         out.write("import javax.resource.spi.Connector;");
+         writeEol(out);
+      }
       out.write("import javax.resource.spi.ResourceAdapter;");
       writeEol(out);
       out.write("import javax.resource.spi.ResourceAdapterInternalException;");

Added: projects/jboss-jca/trunk/codegenerator/src/main/java/org/jboss/jca/codegenerator/SimpleTemplate.java
===================================================================
--- projects/jboss-jca/trunk/codegenerator/src/main/java/org/jboss/jca/codegenerator/SimpleTemplate.java	                        (rev 0)
+++ projects/jboss-jca/trunk/codegenerator/src/main/java/org/jboss/jca/codegenerator/SimpleTemplate.java	2010-05-25 08:03:15 UTC (rev 105206)
@@ -0,0 +1,124 @@
+/*
+ * 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.io.IOException;
+import java.io.Writer;
+import java.net.URL;
+import java.util.Map;
+
+/**
+ * A SimpleTemplate.
+ * 
+ * @author Jeff Zhang
+ * @version $Revision: $
+ */
+public class SimpleTemplate implements Template
+{
+   /** template file */
+   
+   private URL input;
+   
+   /** template string */
+   String templateText = null;
+   
+   /**
+    * SimpleTemplate
+    * @param input template string
+    */
+   public SimpleTemplate(String input)
+   {
+      this.templateText = input;
+   }
+   
+   /**
+    * SimpleTemplate
+    * @param input template string
+    */
+   public SimpleTemplate(URL input)
+   {
+      this.input = input;
+   }
+   
+   /**
+    * Processes the template
+    * @param varMap variable map
+    * @param out the writer to output the text to.
+    */
+   @Override
+   public void process(Map<String, String> varMap, Writer out)
+   {
+      try
+      {
+         if (templateText == null)
+         {
+            templateText = Utils.readFileIntoString(input);
+         }
+         String replacedString = replace(varMap);
+         out.write(replacedString);
+         out.flush();
+      }
+      catch (IOException e)
+      {
+         e.printStackTrace();
+      }
+   }
+
+   /**
+    * Replace string in the template text
+    * @param varMap variable map
+    * @return replaced string
+    */
+   public String replace(Map<String, String> varMap)
+   {
+      StringBuilder newString = new StringBuilder();
+
+      int p = 0;
+      int p0 = 0;
+      while (true)
+      {
+         p = templateText.indexOf("${", p);
+         if (p == -1)
+         {
+            newString.append(templateText.substring(p0, templateText.length()));
+            break;
+         }
+         else
+         {
+            newString.append(templateText.substring(p0, p));
+         }
+         p0 = p;
+         p = templateText.indexOf("}", p);
+         if (p != -1)
+         {
+            String varName = templateText.substring(p0 + 2, p).trim();
+            if (varMap.containsKey(varName))
+            {
+               newString.append(varMap.get(varName));
+            }
+            p0 = p + 1;
+         }
+      }
+      return newString.toString();
+   }
+
+}

Added: projects/jboss-jca/trunk/codegenerator/src/main/java/org/jboss/jca/codegenerator/Template.java
===================================================================
--- projects/jboss-jca/trunk/codegenerator/src/main/java/org/jboss/jca/codegenerator/Template.java	                        (rev 0)
+++ projects/jboss-jca/trunk/codegenerator/src/main/java/org/jboss/jca/codegenerator/Template.java	2010-05-25 08:03:15 UTC (rev 105206)
@@ -0,0 +1,41 @@
+/*
+ * 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.io.Writer;
+import java.util.Map;
+
+/**
+ * Template interface.
+ * 
+ * @author Jeff Zhang
+ * @version $Revision: $
+ */
+public interface Template
+{
+   /**
+    * Processes the template
+    * @param varMap variable map
+    * @param out the writer to output the text to.
+    */
+   public void process(Map<String, String> varMap, Writer out);
+}

Modified: projects/jboss-jca/trunk/codegenerator/src/main/resources/build.xml.template
===================================================================
--- projects/jboss-jca/trunk/codegenerator/src/main/resources/build.xml.template	2010-05-25 07:00:34 UTC (rev 105205)
+++ projects/jboss-jca/trunk/codegenerator/src/main/resources/build.xml.template	2010-05-25 08:03:15 UTC (rev 105206)
@@ -33,9 +33,10 @@
     <jar destfile="${build.dir}/jca-ra.jar"
          basedir="${build.dir}"
          includes="**/*.class"/>
-    <jar destfile="${target.dir}/jca-test.rar"
-         basedir="${build.dir}"
-         includes="**/*.jar"/>
+    <jar destfile="${target.dir}/jca-test.rar">
+      <fileset dir="${basedir}" includes="META-INF/*"/>
+      <fileset dir="${build.dir}" includes="**/*.jar"/>
+    </jar>
   </target>
   
   <!-- ================================= 

Modified: projects/jboss-jca/trunk/codegenerator/src/main/resources/codegenerator.properties
===================================================================
--- projects/jboss-jca/trunk/codegenerator/src/main/resources/codegenerator.properties	2010-05-25 07:00:34 UTC (rev 105205)
+++ projects/jboss-jca/trunk/codegenerator/src/main/resources/codegenerator.properties	2010-05-25 08:03:15 UTC (rev 105206)
@@ -1,3 +1,4 @@
+use.annotation=Use Annotation: [Y/N/Yes/No] 
 package.name=Package name: 
 ra.class.name=Resource adapter class name: 
 mcf.class.name=Managed connection factory class name: 

Added: projects/jboss-jca/trunk/codegenerator/src/main/resources/ra.xml.template
===================================================================
--- projects/jboss-jca/trunk/codegenerator/src/main/resources/ra.xml.template	                        (rev 0)
+++ projects/jboss-jca/trunk/codegenerator/src/main/resources/ra.xml.template	2010-05-25 08:03:15 UTC (rev 105206)
@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!-- $Id $ -->
+
+<connector xmlns="http://java.sun.com/xml/ns/javaee"
+           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+           xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
+           http://java.sun.com/xml/ns/j2ee/connector_1_6.xsd"
+           version="1.6" metadata-complete="true">
+
+   <vendor-name>Red Hat Middleware LLC</vendor-name>
+   <eis-type>Test RA</eis-type>
+   <resourceadapter-version>0.1</resourceadapter-version>
+
+   <resourceadapter>
+      <resourceadapter-class>${ra.class}</resourceadapter-class>
+
+      ${ra.config.props}
+      <outbound-resourceadapter>
+         <connection-definition>
+            <managedconnectionfactory-class>${mcf.class}</managedconnectionfactory-class>
+         ${mcf.config.props}
+            
+            <connectionfactory-interface>${cf.interface}</connectionfactory-interface>
+            <connectionfactory-impl-class>${cf.class}</connectionfactory-impl-class>
+            <connection-interface>${conn.interface}</connection-interface>
+            <connection-impl-class>${conn.class}</connection-impl-class>
+         </connection-definition>
+         <transaction-support>NoTransaction</transaction-support>
+         <reauthentication-support>false</reauthentication-support>
+      </outbound-resourceadapter>
+   </resourceadapter>
+</connector>
\ No newline at end of file




More information about the jboss-cvs-commits mailing list