[jboss-cvs] JBossAS SVN: r103890 - in projects/jboss-jca/trunk: codegenerator and 15 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Tue Apr 13 05:32:12 EDT 2010


Author: jeff.zhang
Date: 2010-04-13 05:32:10 -0400 (Tue, 13 Apr 2010)
New Revision: 103890

Added:
   projects/jboss-jca/trunk/codegenerator/
   projects/jboss-jca/trunk/codegenerator/.classpath
   projects/jboss-jca/trunk/codegenerator/.project
   projects/jboss-jca/trunk/codegenerator/build.xml
   projects/jboss-jca/trunk/codegenerator/src/
   projects/jboss-jca/trunk/codegenerator/src/main/
   projects/jboss-jca/trunk/codegenerator/src/main/java/
   projects/jboss-jca/trunk/codegenerator/src/main/java/org/
   projects/jboss-jca/trunk/codegenerator/src/main/java/org/jboss/
   projects/jboss-jca/trunk/codegenerator/src/main/java/org/jboss/jca/
   projects/jboss-jca/trunk/codegenerator/src/main/java/org/jboss/jca/codegenerator/
   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/SimpleTemplate.java
   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/package.html
   projects/jboss-jca/trunk/codegenerator/src/main/resources/
   projects/jboss-jca/trunk/codegenerator/src/main/resources/ResourceAdapter.template
   projects/jboss-jca/trunk/codegenerator/src/main/resources/codegenerator-manifest.mf
   projects/jboss-jca/trunk/codegenerator/src/main/resources/codegenerator.bat
   projects/jboss-jca/trunk/codegenerator/src/main/resources/codegenerator.sh
   projects/jboss-jca/trunk/codegenerator/src/test/
   projects/jboss-jca/trunk/codegenerator/src/test/java/
   projects/jboss-jca/trunk/codegenerator/src/test/java/org/
   projects/jboss-jca/trunk/codegenerator/src/test/java/org/jboss/
   projects/jboss-jca/trunk/codegenerator/src/test/java/org/jboss/jca/
   projects/jboss-jca/trunk/codegenerator/src/test/java/org/jboss/jca/codegenerator/
   projects/jboss-jca/trunk/codegenerator/src/test/java/org/jboss/jca/codegenerator/SimpleTemplateTestCase.java
   projects/jboss-jca/trunk/codegenerator/src/test/java/org/jboss/jca/codegenerator/package.html
   projects/jboss-jca/trunk/codegenerator/src/test/resources/
   projects/jboss-jca/trunk/codegenerator/src/test/resources/test.template
Modified:
   projects/jboss-jca/trunk/build.xml
Log:
[JBJCA-306][JBJCA-307] code generator init commit

Modified: projects/jboss-jca/trunk/build.xml
===================================================================
--- projects/jboss-jca/trunk/build.xml	2010-04-13 07:57:11 UTC (rev 103889)
+++ projects/jboss-jca/trunk/build.xml	2010-04-13 09:32:10 UTC (rev 103890)
@@ -225,6 +225,7 @@
     <ant dir="web" inheritRefs="true" target="jars"/>
     <ant dir="sjc" inheritRefs="true" target="jars"/>
     <ant dir="standalone" inheritRefs="true" target="jars"/>
+    <ant dir="codegenerator" inheritRefs="true" target="jars"/>
   </target>
   
   <!-- ================================= 
@@ -241,6 +242,7 @@
     <ant dir="web" inheritRefs="true" target="docs"/>
     <ant dir="sjc" inheritRefs="true" target="docs"/>
     <ant dir="standalone" inheritRefs="true" target="docs"/>
+    <ant dir="codegenerator" inheritRefs="true" target="jars"/>
   </target>
   
   <!-- ================================= 
@@ -261,6 +263,8 @@
     <ant dir="embedded" inheritRefs="true" target="test"/>
     <ant dir="deployers" inheritRefs="true" target="test"/>
     <ant dir="validator" inheritRefs="true" target="test"/>
+    <ant dir="codegenerator" inheritRefs="true" target="jars"/>
+    <ant dir="codegenerator" inheritRefs="true" target="jars"/>
   </target>
   
   <!-- ================================= 

Added: projects/jboss-jca/trunk/codegenerator/.classpath
===================================================================
--- projects/jboss-jca/trunk/codegenerator/.classpath	                        (rev 0)
+++ projects/jboss-jca/trunk/codegenerator/.classpath	2010-04-13 09:32:10 UTC (rev 103890)
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+	<classpathentry kind="src" path="src/main/java"/>
+	<classpathentry excluding="**/*.java" kind="src" path="src/main/resources"/>
+	<classpathentry kind="src" output="eclipse-target/tests-classes" path="src/test/java"/>
+	<classpathentry excluding="**/*.java" kind="src" output="eclipse-target/tests-classes" path="src/test/resources"/>
+	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+	<classpathentry combineaccessrules="false" kind="src" path="/jboss-jca-api"/>
+	<classpathentry combineaccessrules="false" kind="src" path="/jboss-jca-common"/>
+	<classpathentry kind="var" path="JBJCA_LIB/standalone/jboss-metadata-rar.jar"/>
+	<classpathentry kind="var" path="JBJCA_LIB/standalone/ant.jar"/>
+	<classpathentry kind="output" path="eclipse-target/classes"/>
+</classpath>

Added: projects/jboss-jca/trunk/codegenerator/.project
===================================================================
--- projects/jboss-jca/trunk/codegenerator/.project	                        (rev 0)
+++ projects/jboss-jca/trunk/codegenerator/.project	2010-04-13 09:32:10 UTC (rev 103890)
@@ -0,0 +1,13 @@
+<projectDescription>
+  <name>jboss-jca-codegenerator</name>
+  <comment>JBoss JCA Codegenerator</comment>
+  <projects/>
+  <buildSpec>
+    <buildCommand>
+      <name>org.eclipse.jdt.core.javabuilder</name>
+    </buildCommand>
+  </buildSpec>
+  <natures>
+    <nature>org.eclipse.jdt.core.javanature</nature>
+  </natures>
+</projectDescription>

Added: projects/jboss-jca/trunk/codegenerator/build.xml
===================================================================
--- projects/jboss-jca/trunk/codegenerator/build.xml	                        (rev 0)
+++ projects/jboss-jca/trunk/codegenerator/build.xml	2010-04-13 09:32:10 UTC (rev 103890)
@@ -0,0 +1,218 @@
+<!--
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, 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.
+-->
+<project name="jboss-jca-codegenerator" 
+         default="compile" 
+         xmlns:ivy="antlib:org.apache.ivy.ant">
+
+  <!-- ================================= 
+       Properties              
+       ================================= -->
+  <property name="build.codegenerator.dir" value="${build.dir}/codegenerator" />
+
+  <!-- ================================= 
+       Target: compile
+       ================================= -->
+  <target name="compile">
+    <mkdir dir="${build.codegenerator.dir}" />
+    <mkdir dir="${build.codegenerator.dir}/impl" />
+
+    <javac srcdir="src/main"
+           destdir="${build.codegenerator.dir}/impl"
+           classpathref="standalone.lib.path.id"
+           debug="${javac.debug}"
+           deprecation="${javac.deprecation}"
+           optimize="${javac.optimize}">
+      <compilerarg value="-Xlint"/>
+    </javac> 
+  </target>
+
+  <!-- ================================= 
+       Target: jars 
+       ================================= -->
+  <target name="jars" depends="compile">
+    <mkdir dir="${build.codegenerator.dir}/jars" />
+
+    <!-- codegenerator -->
+    <mkdir dir="${build.codegenerator.dir}/jars/codegenerator" />
+
+    <copy todir="${build.codegenerator.dir}/jars/codegenerator">
+      <fileset dir="${build.codegenerator.dir}/impl"
+               includes="**"/>
+    </copy>
+
+    <copy todir="${build.codegenerator.dir}/jars/codegenerator">
+      <fileset dir="src/main/resources/"
+               includes="**/*.template"/>
+    </copy>
+
+    <jar destfile="${target.dir}/jboss-jca-codegenerator.jar"
+         manifest="src/main/resources/codegenerator-manifest.mf"
+         basedir="${build.codegenerator.dir}/jars/codegenerator"/>
+<!--
+    <jar destfile="${target.dir}/jboss-jca-codegenerator-cli.jar"
+         manifest="src/main/resources/codegenerator-cli-manifest.mf"
+         basedir="${build.codegenerator.dir}/jars/codegenerator"
+         includes="**/Main*.class"/>
+  	
+    <jar destfile="${target.dir}/jboss-jca-codegenerator-ant.jar"
+         manifest="src/main/resources/codegenerator-ant-manifest.mf"
+         basedir="${build.codegenerator.dir}/jars/codegenerator"
+   	   includes="**/ant/**"/>
+-->
+  </target>
+
+  <!-- ================================= 
+       Target: docs
+       ================================= -->
+  <target name="docs" depends="compile">
+    <mkdir dir="${target.dir}/docs/codegenerator"/>
+    <javadoc packagenames="org.*"
+             sourcepath="src/main/java"
+             destdir="${target.dir}/docs/codegenerator"
+             doclet="org.jboss.apiviz.APIviz"
+             docletpathref="standalone.lib.path.id"
+             author="true"
+             version="true"
+             windowtitle="JBoss JCA codegenerator"
+             doctitle="JBoss JCA codegenerator"
+             use="true"
+             additionalparam="-author -version"
+             classpath="${build.codegenerator.dir}/impl"
+             classpathref="standalone.lib.path.id"
+             bottom="Copyright &#169; 2008-2009 Red Hat Middleware LLC (http://www.jboss.com/)">
+      <link offline="true" href="http://java.sun.com/j2se/5/docs/api/" packagelistLoc="${java.home}/../docs/api"/>
+    </javadoc>
+    <copy todir="${target.dir}/docs/codegenerator" overwrite="true">
+      <fileset dir="${tools.dir}/api"/>
+    </copy>
+  </target>
+
+  <!-- ================================= 
+       Target: test
+       ================================= -->
+  <target name="test" depends="jars, prepare-test">
+    <mkdir dir="${reports.dir}"/>
+    <mkdir dir="${reports.dir}/codegenerator"/>
+
+    <junit dir="src/test"
+           printsummary="${junit.printsummary}"
+           haltonerror="${junit.haltonerror}"
+           haltonfailure="${junit.haltonfailure}"
+           fork="${junit.fork}"
+           timeout="${junit.timeout}">
+      
+      <jvmarg line="${junit.jvm.options}"/>
+      <sysproperty key="archives.dir" value="${build.codegenerator.dir}"/>
+      <sysproperty key="java.util.logging.manager" value="org.jboss.logmanager.LogManager"/>
+      <sysproperty key="log4j.defaultInitOverride" value="true"/>
+      <sysproperty key="org.jboss.logging.Logger.pluginClass" value="org.jboss.logging.logmanager.LoggerPluginImpl"/>
+      <sysproperty key="test.dir" value="${test.dir}"/>
+      <sysproperty key="xb.builder.useUnorderedSequence" value="true"/>
+      <sysproperty key="javax.xml.stream.XMLInputFactory" value="com.sun.xml.internal.stream.XMLInputFactoryImpl"/>
+      
+      <classpath>
+        <pathelement location="${build.codegenerator.dir}/test"/>
+        <fileset dir="${target.dir}" includes="*.jar"/>
+        <fileset dir="${lib.dir}/test" includes="*.jar" />
+      </classpath>
+      
+      <formatter type="plain"/>
+      <formatter type="xml"/>
+      
+      <batchtest todir="${reports.dir}/codegenerator"
+                 haltonerror="${junit.batchtest.haltonerror}"
+                 haltonfailure="${junit.batchtest.haltonfailure}"
+                 fork="${junit.batchtest.fork}">
+        
+        <fileset dir="${build.codegenerator.dir}/test">
+          <include name="**/*TestCase.class"/>
+        </fileset>
+      </batchtest>
+
+    </junit>
+    
+  </target>
+
+
+  <!-- ================================= 
+       Target: one-test
+       ================================= -->
+  <target name="one-test" depends="jars, prepare-test">
+    <mkdir dir="${reports.dir}"/>
+    <mkdir dir="${reports.dir}/codegenerator"/>
+
+    <junit dir="src/test"
+           printsummary="${junit.printsummary}"
+           haltonerror="${junit.haltonerror}"
+           haltonfailure="${junit.haltonfailure}"
+           fork="${junit.fork}"
+           timeout="${junit.timeout}">
+      
+      <jvmarg line="${junit.jvm.options}"/>
+      <sysproperty key="archives.dir" value="${build.codegenerator.dir}"/>
+      <sysproperty key="java.util.logging.manager" value="org.jboss.logmanager.LogManager"/>
+      <sysproperty key="log4j.defaultInitOverride" value="true"/>
+      <sysproperty key="org.jboss.logging.Logger.pluginClass" value="org.jboss.logging.logmanager.LoggerPluginImpl"/>
+      <sysproperty key="test.dir" value="${test.dir}"/>
+      <sysproperty key="xb.builder.useUnorderedSequence" value="true"/>
+      <sysproperty key="javax.xml.stream.XMLInputFactory" value="com.sun.xml.internal.stream.XMLInputFactoryImpl"/>
+      
+      <classpath>
+        <pathelement location="${build.codegenerator.dir}/test"/>
+        <fileset dir="${target.dir}" includes="*.jar"/>
+        <fileset dir="${lib.dir}/test" includes="*.jar" />
+      </classpath>
+      
+      <formatter type="plain"/>
+      <formatter type="xml"/>
+      
+      <test todir="${reports.dir}/codegenerator" name="${test}"
+                 haltonerror="${junit.batchtest.haltonerror}"
+                 haltonfailure="${junit.batchtest.haltonfailure}"
+                 fork="${junit.batchtest.fork}"/>
+    </junit>
+  </target>
+
+  <!-- ================================= 
+       Target: prepare-test
+       ================================= -->
+  <target name="prepare-test">
+    <mkdir dir="${build.codegenerator.dir}" />
+    <mkdir dir="${build.codegenerator.dir}/test" />
+
+    <javac srcdir="src/test"
+           destdir="${build.codegenerator.dir}/test"
+           classpathref="test.lib.path.id"
+           debug="${javac.debug}"
+           deprecation="${javac.deprecation}"
+           optimize="${javac.optimize}">
+      <compilerarg value="-Xlint"/>
+    </javac> 
+
+    <copy todir="${build.codegenerator.dir}/test">
+      <fileset dir="src/test/resources"/>
+    </copy>
+
+
+  </target>
+
+</project>

Added: 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	                        (rev 0)
+++ projects/jboss-jca/trunk/codegenerator/src/main/java/org/jboss/jca/codegenerator/Main.java	2010-04-13 09:32:10 UTC (rev 103890)
@@ -0,0 +1,72 @@
+/*
+ * 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.BufferedReader;
+import java.io.FileWriter;
+import java.io.InputStreamReader;
+import java.net.URL;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Code generator main class
+ * 
+ * @author Jeff Zhang
+ * @version $Revision: $
+ */
+public class Main
+{
+
+   /**
+    * Code generator standalone tool
+    * 
+    * @param args command line arguments
+    */
+   public static void main(String[] args)
+   {
+      try 
+      {
+         BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
+         System.out.println("Please input ResourceAdapter package name: ");
+         String packageName = in.readLine();
+         System.out.println("Please input ResourceAdapter class name: ");
+         String className = in.readLine();
+
+         URL file = Main.class.getResource("/ResourceAdapter.template");
+         Template template = new SimpleTemplate(file);
+         Map<String, String> varMap = new HashMap<String, String>();
+         varMap.put("package.name", packageName);
+         varMap.put("class.name", className);
+         
+         FileWriter fw = new FileWriter(className + ".java");
+         template.process(varMap, fw);
+         fw.close();
+         System.out.println("Java file wrote");
+      }
+      catch (Exception e)
+      {
+         e.printStackTrace();
+      }
+   }
+
+}

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-04-13 09:32:10 UTC (rev 103890)
@@ -0,0 +1,178 @@
+/*
+ * 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.InputStream;
+import java.io.InputStreamReader;
+import java.io.Reader;
+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 = readFileIntoString(input);
+         }
+         String replacedString = replace(varMap);
+         out.write(replacedString);
+         out.flush();
+      }
+      catch (IOException e)
+      {
+         e.printStackTrace();
+      }
+
+      //System.out.println(templateString);
+   }
+
+   /**
+    * 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();
+   }
+
+   /**
+    *  Reads the contents of a file into a string variable.
+    * 
+    * @param input
+    * @return
+    * @throws IOException
+    */
+   private String readFileIntoString(URL input) throws IOException
+   {
+      
+      InputStream stream = null;
+      InputStreamReader reader = null;
+      try
+      {
+         stream = input.openStream();
+         reader = new InputStreamReader(stream);
+         return readStreamIntoString(reader);
+      }
+      finally
+      {
+         if (reader != null)
+            reader.close();
+         if (stream != null)
+            stream.close();
+      }
+   }
+
+   /**
+    *  Reads the contents of a stream into a string variable.
+    * 
+    * @param reader
+    * @return
+    * @throws IOException
+    */
+   private String readStreamIntoString(Reader reader) throws IOException
+   {
+      StringBuilder s = new StringBuilder();
+      char a[] = new char[0x10000];
+      while (true)
+      {
+         int l = reader.read(a);
+         if (l == -1)
+            break;
+         if (l <= 0)
+            throw new IOException();
+         s.append(a, 0, l);
+      }
+      return s.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-04-13 09:32:10 UTC (rev 103890)
@@ -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);
+}

Added: projects/jboss-jca/trunk/codegenerator/src/main/java/org/jboss/jca/codegenerator/package.html
===================================================================
--- projects/jboss-jca/trunk/codegenerator/src/main/java/org/jboss/jca/codegenerator/package.html	                        (rev 0)
+++ projects/jboss-jca/trunk/codegenerator/src/main/java/org/jboss/jca/codegenerator/package.html	2010-04-13 09:32:10 UTC (rev 103890)
@@ -0,0 +1,3 @@
+<body>
+Code generator
+</body>

Added: projects/jboss-jca/trunk/codegenerator/src/main/resources/ResourceAdapter.template
===================================================================
--- projects/jboss-jca/trunk/codegenerator/src/main/resources/ResourceAdapter.template	                        (rev 0)
+++ projects/jboss-jca/trunk/codegenerator/src/main/resources/ResourceAdapter.template	2010-04-13 09:32:10 UTC (rev 103890)
@@ -0,0 +1,129 @@
+/*
+ * 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 ${package.name};
+
+import javax.resource.ResourceException;
+import javax.resource.spi.ActivationSpec;
+import javax.resource.spi.BootstrapContext;
+import javax.resource.spi.ResourceAdapter;
+import javax.resource.spi.ResourceAdapterInternalException;
+import javax.resource.spi.endpoint.MessageEndpointFactory;
+import javax.transaction.xa.XAResource;
+
+import org.jboss.logging.Logger;
+
+/**
+ * ${class.name}
+ *
+ * @version $Revision: $
+ */
+public class ${class.name} implements ResourceAdapter
+{
+   private static Logger log = Logger.getLogger(${class.name}.class);
+   
+   /**
+    * This is called during the activation of a message endpoint. 
+    *
+    * @param endpointFactory a message endpoint factory instance.
+    * @param spec an activation spec JavaBean instance.
+    * @throws ResourceException generic exception 
+    */
+   public void endpointActivation(MessageEndpointFactory endpointFactory,
+      ActivationSpec spec) throws ResourceException
+   {
+      log.debug("call endpointActivation");
+
+   }
+
+   /**
+    * This is called when a message endpoint is deactivated. 
+    * 
+    * @param endpointFactory a message endpoint factory instance.
+    * @param spec an activation spec JavaBean instance.
+    */
+   public void endpointDeactivation(MessageEndpointFactory endpointFactory,
+      ActivationSpec spec)
+   {
+      log.debug("call endpointDeactivation");
+
+   }
+
+   /**
+    * This method is called by the application server during crash recovery.
+    * 
+    * @param specs an array of ActivationSpec JavaBeans 
+    * @throws ResourceException generic exception 
+    * @return an array of XAResource objects
+    */
+   public XAResource[] getXAResources(ActivationSpec[] specs)
+      throws ResourceException
+   {
+      log.debug("call getXAResources");
+      return null;
+   }
+
+   /**
+    * This is called when a resource adapter instance is bootstrapped. 
+    *
+    * @param ctx a bootstrap context containing references 
+    * @throws ResourceAdapterInternalException indicates bootstrap failure.
+    */
+   public void start(BootstrapContext ctx)
+      throws ResourceAdapterInternalException
+   {
+      log.debug("call start");
+
+   }
+
+   /**
+    * This is called when a resource adapter instance is undeployed or
+    * during application server shutdown. 
+    */
+   public void stop()
+   {
+      log.debug("call stop");
+
+   }
+
+   /**
+    * Hash code
+    * @return The hash
+    */
+   @Override
+   public int hashCode()
+   {
+      return 42;
+   }
+
+   /**
+    * Equals
+    * @param other The other object
+    * @return True if equal; otherwise false
+    */
+   public boolean equals(Object other)
+   {
+      if (other == null)
+         return false;
+
+      return getClass().equals(other.getClass());
+   }
+}

Added: projects/jboss-jca/trunk/codegenerator/src/main/resources/codegenerator-manifest.mf
===================================================================
--- projects/jboss-jca/trunk/codegenerator/src/main/resources/codegenerator-manifest.mf	                        (rev 0)
+++ projects/jboss-jca/trunk/codegenerator/src/main/resources/codegenerator-manifest.mf	2010-04-13 09:32:10 UTC (rev 103890)
@@ -0,0 +1,5 @@
+Implementation-Title: JBoss JCA Codegenerator
+Implementation-Vendor: Red Hat Middleware LLC
+Implementation-Vendor-Id: org.jboss
+Implementation-Version: 0.1
+Main-Class: org.jboss.jca.codegenerator.Main
\ No newline at end of file

Added: projects/jboss-jca/trunk/codegenerator/src/main/resources/codegenerator.bat
===================================================================
--- projects/jboss-jca/trunk/codegenerator/src/main/resources/codegenerator.bat	                        (rev 0)
+++ projects/jboss-jca/trunk/codegenerator/src/main/resources/codegenerator.bat	2010-04-13 09:32:10 UTC (rev 103890)
@@ -0,0 +1 @@
+java -jar jboss-jca-codegenerator.jar %*
\ No newline at end of file

Added: projects/jboss-jca/trunk/codegenerator/src/main/resources/codegenerator.sh
===================================================================
--- projects/jboss-jca/trunk/codegenerator/src/main/resources/codegenerator.sh	                        (rev 0)
+++ projects/jboss-jca/trunk/codegenerator/src/main/resources/codegenerator.sh	2010-04-13 09:32:10 UTC (rev 103890)
@@ -0,0 +1,2 @@
+#!/bin/sh
+java -jar jboss-jca-codegenerator.jar $*
\ No newline at end of file


Property changes on: projects/jboss-jca/trunk/codegenerator/src/main/resources/codegenerator.sh
___________________________________________________________________
Name: svn:executable
   + *

Added: projects/jboss-jca/trunk/codegenerator/src/test/java/org/jboss/jca/codegenerator/SimpleTemplateTestCase.java
===================================================================
--- projects/jboss-jca/trunk/codegenerator/src/test/java/org/jboss/jca/codegenerator/SimpleTemplateTestCase.java	                        (rev 0)
+++ projects/jboss-jca/trunk/codegenerator/src/test/java/org/jboss/jca/codegenerator/SimpleTemplateTestCase.java	2010-04-13 09:32:10 UTC (rev 103890)
@@ -0,0 +1,136 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008-2009, 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.StringWriter;
+import java.net.URL;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.jboss.logging.Logger;
+
+import org.junit.Test;
+import static org.junit.Assert.*;
+
+/**
+ * A SimpleTemplate test case.
+ * 
+ * @author Jeff Zhang
+ * @version $Revision: $
+ */
+public class SimpleTemplateTestCase
+{
+   private static Logger log = Logger.getLogger(SimpleTemplateTestCase.class);
+   
+   /**
+    * test process
+    * @throws Throwable throwable exception 
+    */
+   @Test
+   public void testProcessString() throws Throwable
+   {
+      Template template = new SimpleTemplate("Hello ${name}");
+      Map<String, String> varMap = new HashMap<String, String>();
+      varMap.put("name", "Jeff");
+      StringWriter writer = new StringWriter();
+      template.process(varMap, writer);
+      assertEquals(writer.toString(), "Hello Jeff");
+   }
+   
+   /**
+    * test replace
+    * @throws Throwable throwable exception 
+    */
+   @Test
+   public void testReplaceOk() throws Throwable
+   {
+      SimpleTemplate template = new SimpleTemplate("Hello ${firstname} ${lastname}");
+      Map<String, String> varMap = new HashMap<String, String>();
+      varMap.put("firstname", "Jeff");
+      varMap.put("lastname", "Zhang");
+      String replacedString = template.replace(varMap);
+      assertEquals(replacedString, "Hello Jeff Zhang");
+   }
+   
+   /**
+    * test replace
+    * @throws Throwable throwable exception 
+    */
+   @Test
+   public void testReplaceDouble() throws Throwable
+   {
+      SimpleTemplate template = new SimpleTemplate("Hello ${firstname} ${firstname}");
+      Map<String, String> varMap = new HashMap<String, String>();
+      varMap.put("firstname", "Jeff");
+      varMap.put("lastname", "Zhang");
+      String replacedString = template.replace(varMap);
+      assertEquals(replacedString, "Hello Jeff Jeff");
+   }
+   
+   /**
+    * test replace
+    * @throws Throwable throwable exception 
+    */
+   @Test
+   public void testReplaceNothing() throws Throwable
+   {
+      SimpleTemplate template = new SimpleTemplate("Hello ${firstname} ${firstname}");
+      Map<String, String> varMap = new HashMap<String, String>();
+      //varMap.put("firstname", "Jeff");
+      varMap.put("lastname", "Zhang");
+      String replacedString = template.replace(varMap);
+      assertEquals(replacedString, "Hello ${firstname} ${firstname}");
+   }
+   
+   /**
+    * test replace
+    * @throws Throwable throwable exception 
+    */
+   @Test
+   public void testReplaceJustOne() throws Throwable
+   {
+      SimpleTemplate template = new SimpleTemplate("Hello ${firstname ${firstname} ${lastname}");
+      Map<String, String> varMap = new HashMap<String, String>();
+      //varMap.put("firstname", "Jeff");
+      varMap.put("lastname", "Zhang");
+      String replacedString = template.replace(varMap);
+      assertEquals(replacedString, "Hello ${firstname ${firstname} Zhang");
+   }
+   
+   /**
+    * test process
+    * @throws Throwable throwable exception 
+    */
+   @Test
+   public void testProcessFile() throws Throwable
+   {
+      URL file = SimpleTemplateTestCase.class.getResource("/test.template");
+      SimpleTemplate template = new SimpleTemplate(file);
+      Map<String, String> varMap = new HashMap<String, String>();
+      varMap.put("package.name", "org.jboss.jca.test");
+      varMap.put("class.name", "BaseResourceAdapter");
+      StringWriter writer = new StringWriter();
+      template.process(varMap, writer);
+      assertTrue(writer.toString().indexOf("org.jboss.jca.test") > 0);
+   }
+}

Added: projects/jboss-jca/trunk/codegenerator/src/test/java/org/jboss/jca/codegenerator/package.html
===================================================================
--- projects/jboss-jca/trunk/codegenerator/src/test/java/org/jboss/jca/codegenerator/package.html	                        (rev 0)
+++ projects/jboss-jca/trunk/codegenerator/src/test/java/org/jboss/jca/codegenerator/package.html	2010-04-13 09:32:10 UTC (rev 103890)
@@ -0,0 +1,3 @@
+<body>
+Code generator
+</body>

Added: projects/jboss-jca/trunk/codegenerator/src/test/resources/test.template
===================================================================
--- projects/jboss-jca/trunk/codegenerator/src/test/resources/test.template	                        (rev 0)
+++ projects/jboss-jca/trunk/codegenerator/src/test/resources/test.template	2010-04-13 09:32:10 UTC (rev 103890)
@@ -0,0 +1,10 @@
+package ${package.name};
+import javax.resource.spi.ResourceAdapter;
+import org.jboss.logging.Logger;
+/**
+ * ${class.name}
+ */
+public class ${class.name} implements ResourceAdapter
+{
+   private static Logger log = Logger.getLogger(${class.name}.class);
+}
\ No newline at end of file




More information about the jboss-cvs-commits mailing list