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

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Thu Apr 22 04:20:06 EDT 2010


Author: jeff.zhang
Date: 2010-04-22 04:20:05 -0400 (Thu, 22 Apr 2010)
New Revision: 104136

Added:
   projects/jboss-jca/trunk/codegenerator/src/main/java/org/jboss/jca/codegenerator/ConfigPropType.java
   projects/jboss-jca/trunk/codegenerator/src/main/java/org/jboss/jca/codegenerator/Definition.java
   projects/jboss-jca/trunk/codegenerator/src/main/resources/header.template
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/SimpleTemplate.java
   projects/jboss-jca/trunk/codegenerator/src/main/java/org/jboss/jca/codegenerator/Template.java
   projects/jboss-jca/trunk/codegenerator/src/test/java/org/jboss/jca/codegenerator/SimpleTemplateTestCase.java
Log:
[JBJCA-312] support code formmatter

Added: projects/jboss-jca/trunk/codegenerator/src/main/java/org/jboss/jca/codegenerator/ConfigPropType.java
===================================================================
--- projects/jboss-jca/trunk/codegenerator/src/main/java/org/jboss/jca/codegenerator/ConfigPropType.java	                        (rev 0)
+++ projects/jboss-jca/trunk/codegenerator/src/main/java/org/jboss/jca/codegenerator/ConfigPropType.java	2010-04-22 08:20:05 UTC (rev 104136)
@@ -0,0 +1,113 @@
+/*
+ * 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 ConfigPropType.
+ * 
+ * @author Jeff Zhang</a>
+ * @version $Revision: $
+ */
+public class ConfigPropType
+{
+   /** name */
+   private String name;
+   /** type */
+   private String type;
+   /** value */
+   private String value;
+
+   /**
+    * Set the name.
+    * 
+    * @param name The name to set.
+    * @param type The type to set.
+    * @param value The value to set.
+    */
+   public ConfigPropType(String name, String type, String value)
+   {
+   
+      this.name = name;
+      this.type = type;
+      this.value = value;
+   }
+   
+   /**
+    * 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;
+   }
+
+   /**
+    * Set the value.
+    * 
+    * @param value The value to set.
+    */
+   public void setValue(String value)
+   {
+      this.value = value;
+   }
+
+   /**
+    * Get the value.
+    * 
+    * @return the value.
+    */
+   public String getValue()
+   {
+      return value;
+   }
+}

Added: 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	                        (rev 0)
+++ projects/jboss-jca/trunk/codegenerator/src/main/java/org/jboss/jca/codegenerator/Definition.java	2010-04-22 08:20:05 UTC (rev 104136)
@@ -0,0 +1,100 @@
+/*
+ * 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.List;
+
+/**
+ * A Definition.
+ * 
+ * @author Jeff Zhang</a>
+ * @version $Revision: $
+ */
+public class Definition
+{
+   /** resource adapter package name */
+   private String raPackage;
+   /** resource adapter class name */
+   private String raClass;
+   /** resource adapter config properties */
+   private List<ConfigPropType> raConfigProps;
+
+   /**
+    * Set the raPackage.
+    * 
+    * @param raPackage The raPackage to set.
+    */
+   public void setRaPackage(String raPackage)
+   {
+      this.raPackage = raPackage;
+   }
+
+   /**
+    * Get the raPackage.
+    * 
+    * @return the raPackage.
+    */
+   public String getRaPackage()
+   {
+      return raPackage;
+   }
+
+   /**
+    * Set the raClass.
+    * 
+    * @param raClass The raClass to set.
+    */
+   public void setRaClass(String raClass)
+   {
+      this.raClass = raClass;
+   }
+
+   /**
+    * Get the raClass.
+    * 
+    * @return the raClass.
+    */
+   public String getRaClass()
+   {
+      return raClass;
+   }
+
+   /**
+    * Set the raConfigProps.
+    * 
+    * @param raConfigProps The raConfigProps to set.
+    */
+   public void setRaConfigProps(List<ConfigPropType> raConfigProps)
+   {
+      this.raConfigProps = raConfigProps;
+   }
+
+   /**
+    * Get the raConfigProps.
+    * 
+    * @return the raConfigProps.
+    */
+   public List<ConfigPropType> getRaConfigProps()
+   {
+      return raConfigProps;
+   }
+}

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-04-22 07:08:32 UTC (rev 104135)
+++ projects/jboss-jca/trunk/codegenerator/src/main/java/org/jboss/jca/codegenerator/Main.java	2010-04-22 08:20:05 UTC (rev 104136)
@@ -24,9 +24,6 @@
 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
@@ -47,19 +44,18 @@
       try 
       {
          BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
-         System.out.println("Please input ResourceAdapter package name: ");
+         System.out.print("Please input ResourceAdapter package name: ");
          String packageName = in.readLine();
-         System.out.println("Please input ResourceAdapter class name: ");
+         System.out.print("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);
-         
+         Template template = new SimpleTemplate();
+         Definition def = new Definition();
+         def.setRaPackage(packageName);
+         def.setRaClass(className);
+
          FileWriter fw = new FileWriter(className + ".java");
-         template.process(varMap, fw);
+         template.process(def, fw);
          fw.close();
          System.out.println("Java file wrote");
       }

Modified: 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	2010-04-22 07:08:32 UTC (rev 104135)
+++ projects/jboss-jca/trunk/codegenerator/src/main/java/org/jboss/jca/codegenerator/SimpleTemplate.java	2010-04-22 08:20:05 UTC (rev 104136)
@@ -27,7 +27,6 @@
 import java.io.Reader;
 import java.io.Writer;
 import java.net.URL;
-import java.util.Map;
 
 /**
  * A SimpleTemplate.
@@ -37,101 +36,331 @@
  */
 public class SimpleTemplate implements Template
 {
-   /** template file */
-   
-   private URL input;
-   
-   /** template string */
-   String templateText = null;
-   
+
    /**
     * SimpleTemplate
-    * @param input template string
     */
-   public SimpleTemplate(String input)
+   public SimpleTemplate()
    {
-      this.templateText = input;
    }
    
+  
    /**
-    * SimpleTemplate
-    * @param input template string
-    */
-   public SimpleTemplate(URL input)
-   {
-      this.input = input;
-   }
-   
-   /**
     * Processes the template
-    * @param varMap variable map
+    * @param def Definition 
     * @param out the writer to output the text to.
     */
    @Override
-   public void process(Map<String, String> varMap, Writer out)
+   public void process(Definition def, Writer out)
    {
       try
       {
-         if (templateText == null)
-         {
-            templateText = readFileIntoString(input);
-         }
-         String replacedString = replace(varMap);
-         out.write(replacedString);
+         writeDown(def, out);
          out.flush();
       }
       catch (IOException e)
       {
          e.printStackTrace();
       }
+   }
 
-      //System.out.println(templateString);
+   /**
+    * Output generation code
+    * @param def definition
+    * @param out Writer
+    * @throws IOException ioException
+    */
+   public void writeDown(Definition def, Writer out) throws IOException
+   {
+      writeheader(def, out);
+      writeImport(def, out);
+      writeClassComment(def, out);
+      writeClassBody(def, out);
+      
    }
 
    /**
-    * Replace string in the template text
-    * @param varMap variable map
-    * @return replaced string
+    * Output class head, for example license
+    * @param def definition
+    * @param out Writer
+    * @throws IOException ioException
     */
-   public String replace(Map<String, String> varMap)
+   private void writeheader(Definition def, Writer out) throws IOException
    {
-      StringBuilder newString = new StringBuilder();
+      URL headerFile = SimpleTemplate.class.getResource("/header.template");
+      String headerString = readFileIntoString(headerFile);
+      out.write(headerString);
+      writeEol(out);
+   }
 
-      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();
+   /**
+    * Output class comment
+    * @param def definition
+    * @param out Writer
+    * @throws IOException ioException
+    */
+   private void writeClassComment(Definition def, Writer out) throws IOException
+   {
+      out.write("/**");
+      writeEol(out);
+      out.write(" * " + def.getRaClass());
+      writeEol(out);
+      out.write(" * @version $Revision: $");
+      writeEol(out);
+      out.write(" */");
+      writeEol(out);
    }
 
    /**
+    * Output class import
+    * @param def definition
+    * @param out Writer
+    * @throws IOException ioException
+    */
+   private void writeImport(Definition def, Writer out) throws IOException
+   {
+      out.write("package " + def.getRaPackage() + ";");
+      writeEol(out);
+      out.write("import javax.resource.ResourceException;");
+      writeEol(out);
+      out.write("import javax.resource.spi.ActivationSpec;");
+      writeEol(out);
+      out.write("import javax.resource.spi.BootstrapContext;");
+      writeEol(out);
+      out.write("import javax.resource.spi.ResourceAdapter;");
+      writeEol(out);
+      out.write("import javax.resource.spi.ResourceAdapterInternalException;");
+      writeEol(out);
+      out.write("import javax.resource.spi.endpoint.MessageEndpointFactory;");
+      writeEol(out);
+      out.write("import javax.transaction.xa.XAResource;");
+      writeEol(out);
+      out.write("import org.jboss.logging.Logger;");
+      writeEol(out);
+   }
+
+   /**
+    * Output eol 
+    * @param out Writer
+    * @throws IOException ioException
+    */
+   private void writeEol(Writer out) throws IOException
+   {
+      out.write("\n");
+   }
+   
+   /**
+    * Output left curly bracket
+    * @param out Writer
+    */
+   private void writeLeftCurlyBracket(Writer out, int indent) throws IOException
+   {
+      writeEol(out);
+      writeIndent(out, indent);
+      out.write("{");
+      writeEol(out);
+   }
+
+   /**
+    * Output right curly bracket
+    * @param out Writer
+    */
+   private void writeRightCurlyBracket(Writer out, int indent) throws IOException
+   {
+      writeEol(out);
+      writeIndent(out, indent);
+      out.write("}");
+      writeEol(out);
+   }
+   
+   /**
+    * Output space
+    * @param out Writer
+    */
+   private void writeIndent(Writer out, int indent) throws IOException
+   {
+      for (int i = 0; i < indent; i++)
+         out.write("   ");      
+   }
+
+   /**
+    * Output class boby
+    * @param def definition
+    * @param out Writer
+    */
+   private void writeClassBody(Definition def, Writer out) throws IOException
+   {
+      out.write("public class " + def.getRaClass() + " implements ResourceAdapter");
+      writeLeftCurlyBracket(out, 0);
+      writeEol(out);
+      
+      int indent = 1;
+      writeIndent(out, indent);
+      out.write("private static Logger log = Logger.getLogger(" + def.getRaClass() + ".class);");
+      writeEol(out);
+      writeEol(out);
+      
+      writeConfigProps(def, out, indent);
+      writeEndpointLifecycle(def, out, indent);
+      writeLifecycle(def, out, indent);
+      writeXAResource(def, out, indent);
+      writeHashEquals(def, out, indent);
+      
+      writeRightCurlyBracket(out, 0);
+   }
+
+   /**
+    * Output class boby
+    * @param def definition
+    * @param out Writer
+    * @param indent space number
+    */
+   private void writeConfigProps(Definition def, Writer out, int indent) throws IOException
+   {
+   }
+
+   /**
+    * Upcase first letter
+    * @param name string
+    * @param out Writer
+    * @return String name string
+    */
+   private String upcaseFisrt(String name)
+   {
+      StringBuilder sb = new StringBuilder();
+      sb.append(name.substring(0, 1).toUpperCase());
+      sb.append(name.substring(1));
+      return sb.toString();
+   }
+
+
+   /**
+    * Output class boby
+    * @param def definition
+    * @param out Writer
+    * @param indent space number
+    */
+   private void writeHashEquals(Definition def, Writer out, int indent) throws IOException
+   {
+      writeIndent(out, indent);
+      out.write("@Override");
+      writeEol(out);
+      writeIndent(out, indent);
+      out.write("public int hashCode()");
+      writeLeftCurlyBracket(out, indent);
+      writeIndent(out, indent + 1);
+      out.write("return 43;");
+      writeRightCurlyBracket(out, indent);
+      writeEol(out);
+
+      writeIndent(out, indent);
+      out.write("@Override");
+      writeIndent(out, indent);
+      out.write("public boolean equals(Object other)");
+      writeEol(out);
+      writeLeftCurlyBracket(out, indent);
+      writeIndent(out, indent + 1);
+      out.write("if (other == null)");
+      writeEol(out);
+      writeIndent(out, indent + 2);
+      out.write("return false;");
+      writeEol(out);
+      writeIndent(out, indent + 1);
+      out.write("return getClass().equals(other.getClass());");
+      writeRightCurlyBracket(out, indent);
+      writeEol(out);
+   }
+
+   /**
+    * Output class boby
+    * @param def definition
+    * @param out Writer
+    * @param indent space number
+    */
+   private void writeXAResource(Definition def, Writer out, int indent) throws IOException
+   {
+      writeIndent(out, indent);
+      out.write("public XAResource[] getXAResources(ActivationSpec[] specs)");
+      writeEol(out);
+      writeIndent(out, indent + 1);
+      out.write("throws ResourceException");
+      writeLeftCurlyBracket(out, indent);
+      writeIndent(out, indent + 1);
+      out.write("log.debug(\"call getXAResources\");");
+      writeEol(out);
+      writeIndent(out, indent + 1);
+      out.write("return null;");
+      writeRightCurlyBracket(out, indent);
+      writeEol(out);
+   }
+
+   /**
+    * Output class boby
+    * @param def definition
+    * @param out Writer
+    * @param indent space number
+    */
+   private void writeLifecycle(Definition def, Writer out, int indent) throws IOException
+   {
+      writeIndent(out, indent);
+      out.write("public void start(BootstrapContext ctx)");
+      writeEol(out);
+      writeIndent(out, indent + 1);
+      out.write("throws ResourceAdapterInternalException");
+      writeLeftCurlyBracket(out, indent);
+      writeIndent(out, indent + 1);
+      out.write("log.debug(\"call start\");");
+      writeRightCurlyBracket(out, indent);
+      writeEol(out);
+
+      writeIndent(out, indent);
+      out.write("public void stop()");
+      writeEol(out);
+      writeLeftCurlyBracket(out, indent);
+      writeIndent(out, indent + 1);
+      out.write("log.debug(\"call stop\");");
+      writeRightCurlyBracket(out, indent);
+      writeEol(out);
+   }
+
+   /**
+    * Output class boby
+    * @param def definition
+    * @param out Writer
+    * @param indent space number
+    */
+   private void writeEndpointLifecycle(Definition def, Writer out, int indent) throws IOException
+   {
+      writeIndent(out, indent);
+      out.write("public void endpointActivation(MessageEndpointFactory endpointFactory,");
+      writeEol(out);
+      writeIndent(out, indent + 1);
+      out.write("ActivationSpec spec) throws ResourceException");
+      writeLeftCurlyBracket(out, indent);
+      writeIndent(out, indent + 1);
+      out.write("log.debug(\"call endpointActivation\");");
+      writeRightCurlyBracket(out, indent);
+      writeEol(out);
+
+      writeIndent(out, indent);
+      out.write("public void endpointDeactivation(MessageEndpointFactory endpointFactory,");
+      writeEol(out);
+      writeIndent(out, indent + 1);
+      out.write("ActivationSpec spec) throws ResourceException");
+      writeLeftCurlyBracket(out, indent);
+      writeIndent(out, indent + 1);
+      out.write("log.debug(\"call endpointDeactivation\");");
+      writeRightCurlyBracket(out, indent);
+      writeEol(out);
+   }
+
+
+   /**
     *  Reads the contents of a file into a string variable.
     * 
     * @param input
     * @return
-    * @throws IOException
+    * @throws IOException ioException
     */
    private String readFileIntoString(URL input) throws IOException
    {
@@ -158,7 +387,7 @@
     * 
     * @param reader
     * @return
-    * @throws IOException
+    * @throws IOException ioException
     */
    private String readStreamIntoString(Reader reader) throws IOException
    {

Modified: 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	2010-04-22 07:08:32 UTC (rev 104135)
+++ projects/jboss-jca/trunk/codegenerator/src/main/java/org/jboss/jca/codegenerator/Template.java	2010-04-22 08:20:05 UTC (rev 104136)
@@ -22,7 +22,6 @@
 package org.jboss.jca.codegenerator;
 
 import java.io.Writer;
-import java.util.Map;
 
 /**
  * Template interface.
@@ -34,8 +33,8 @@
 {
    /**
     * Processes the template
-    * @param varMap variable map
+    * @param def Definition
     * @param out the writer to output the text to.
     */
-   public void process(Map<String, String> varMap, Writer out);
+   public void process(Definition def, Writer out);
 }

Added: projects/jboss-jca/trunk/codegenerator/src/main/resources/header.template
===================================================================
--- projects/jboss-jca/trunk/codegenerator/src/main/resources/header.template	                        (rev 0)
+++ projects/jboss-jca/trunk/codegenerator/src/main/resources/header.template	2010-04-22 08:20:05 UTC (rev 104136)
@@ -0,0 +1,21 @@
+/*
+ * 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.
+ */
\ No newline at end of file

Modified: 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	2010-04-22 07:08:32 UTC (rev 104135)
+++ projects/jboss-jca/trunk/codegenerator/src/test/java/org/jboss/jca/codegenerator/SimpleTemplateTestCase.java	2010-04-22 08:20:05 UTC (rev 104136)
@@ -23,9 +23,8 @@
 package org.jboss.jca.codegenerator;
 
 import java.io.StringWriter;
-import java.net.URL;
-import java.util.HashMap;
-import java.util.Map;
+import java.util.ArrayList;
+import java.util.List;
 
 import org.jboss.logging.Logger;
 
@@ -42,95 +41,27 @@
 {
    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");
+      SimpleTemplate template = new SimpleTemplate();
+      Definition def = new Definition();
+      def.setRaPackage("org.jboss.jca.test");
+      def.setRaClass("BaseResourceAdapter");
+
+      List<ConfigPropType> props = new ArrayList<ConfigPropType>();
+      ConfigPropType config = new ConfigPropType("myProp", "String", "Hello");
+      props.add(config);
+      def.setRaConfigProps(props);
+      
       StringWriter writer = new StringWriter();
-      template.process(varMap, writer);
+      template.process(def, writer);
       assertTrue(writer.toString().indexOf("org.jboss.jca.test") > 0);
+      //System.out.println(writer.toString());
    }
 }




More information about the jboss-cvs-commits mailing list