[jboss-cvs] JBossAS SVN: r105294 - 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
Thu May 27 04:01:44 EDT 2010


Author: jeff.zhang
Date: 2010-05-27 04:01:41 -0400 (Thu, 27 May 2010)
New Revision: 105294

Added:
   projects/jboss-jca/trunk/codegenerator/src/main/java/org/jboss/jca/codegenerator/AsCodeGen.java
   projects/jboss-jca/trunk/codegenerator/src/main/java/org/jboss/jca/codegenerator/MlCodeGen.java
Modified:
   projects/jboss-jca/trunk/codegenerator/src/main/java/org/jboss/jca/codegenerator/Definition.java
   projects/jboss-jca/trunk/codegenerator/src/main/java/org/jboss/jca/codegenerator/JCA16AnnoProfile.java
   projects/jboss-jca/trunk/codegenerator/src/main/java/org/jboss/jca/codegenerator/Main.java
   projects/jboss-jca/trunk/codegenerator/src/main/resources/codegenerator.properties
   projects/jboss-jca/trunk/codegenerator/src/main/resources/ra.xml.template
Log:
[JBJCA-336] Inbound java classes generation

Added: projects/jboss-jca/trunk/codegenerator/src/main/java/org/jboss/jca/codegenerator/AsCodeGen.java
===================================================================
--- projects/jboss-jca/trunk/codegenerator/src/main/java/org/jboss/jca/codegenerator/AsCodeGen.java	                        (rev 0)
+++ projects/jboss-jca/trunk/codegenerator/src/main/java/org/jboss/jca/codegenerator/AsCodeGen.java	2010-05-27 08:01:41 UTC (rev 105294)
@@ -0,0 +1,211 @@
+/*
+ * 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;
+
+/**
+ * A ActivationSpec CodeGen.
+ * 
+ * @author Jeff Zhang
+ * @version $Revision: $
+ */
+public class AsCodeGen extends AbstractCodeGen
+{
+
+   /**
+    * Output class
+    * @param def definition
+    * @param out Writer
+    * @throws IOException ioException
+    */
+   @Override
+   public void writeClassBody(Definition def, Writer out) throws IOException
+   {
+      if (def.isUseAnnotation())
+      {
+         out.write("@Activation(messageListeners = {" + def.getRaPackage() + "." + def.getMlClass() + ".class})");
+         writeEol(out);
+      }
+      out.write("public class " + getClassName(def) + " implements ActivationSpec");
+      writeLeftCurlyBracket(out, 0);
+      writeEol(out);
+
+      int indent = 1;
+      writeIndent(out, indent);
+      out.write("/** The logger */");
+      writeEol(out);
+      writeIndent(out, indent);
+      out.write("private static Logger log = Logger.getLogger(" + getClassName(def) + ".class);");
+      writeEol(out);
+      writeEol(out);
+
+      writeDefaultConstructor(def, out, indent);
+      
+      writeValidate(def, out, indent);
+      writeResourceAdapter(def, out, indent);
+      
+      writeRightCurlyBracket(out, 0);
+   }
+   
+   /**
+    * Output class import
+    * @param def definition
+    * @param out Writer
+    * @throws IOException ioException
+    */
+   @Override
+   public void writeImport(Definition def, Writer out) throws IOException
+   {
+      out.write("package " + def.getRaPackage() + ";");
+      writeEol(out);
+      writeEol(out);
+      out.write("import java.io.PrintWriter;");
+      writeEol(out);
+      writeEol(out);
+      out.write("import javax.resource.ResourceException;");
+      writeEol(out);
+      out.write("import javax.resource.spi.Activation;");
+      writeEol(out);
+      out.write("import javax.resource.spi.ActivationSpec;");
+      writeEol(out);
+      out.write("import javax.resource.spi.InvalidPropertyException;");
+      writeEol(out);
+      out.write("import javax.resource.spi.ResourceAdapter;");
+      writeEol(out);
+      writeEol(out);
+      out.write("import org.jboss.logging.Logger;");
+      writeEol(out);
+      writeEol(out);
+   }
+   
+   /**
+    * get this class name
+    * @param def definition
+    * @return String class name
+    */
+   @Override
+   public String getClassName(Definition def)
+   {
+      return def.getAsClass();
+   }
+   
+   /**
+    * Output validate method
+    * @param def definition
+    * @param out Writer
+    * @param indent space number
+    * @throws IOException ioException
+    */
+   private void writeValidate(Definition def, Writer out, int indent) throws IOException
+   {
+      writeIndent(out, indent);
+      out.write("/**");
+      writeEol(out);
+      writeIndent(out, indent);
+      out.write(" * This method may be called by a deployment tool to validate the overall");
+      writeEol(out);
+      writeIndent(out, indent);
+      out.write(" * activation configuration information provided by the endpoint deployer.");
+      writeEol(out);
+      writeIndent(out, indent);
+      out.write(" *");
+      writeEol(out);
+      writeIndent(out, indent);
+      out.write(" * @throws InvalidPropertyException indicates invalid onfiguration property settings.");
+      writeEol(out);
+      writeIndent(out, indent);
+      out.write(" */");
+      writeEol(out);
+      
+      writeIndent(out, indent);
+      out.write("public void validate() throws InvalidPropertyException");
+      writeLeftCurlyBracket(out, indent);
+      writeIndent(out, indent + 1);
+      out.write("log.debug(\"call validate\");");
+
+      writeRightCurlyBracket(out, indent);
+      writeEol(out);
+   }
+   
+   /**
+    * Output ResourceAdapter method
+    * @param def definition
+    * @param out Writer
+    * @param indent space number
+    * @throws IOException ioException
+    */
+   private void writeResourceAdapter(Definition def, Writer out, int indent) throws IOException
+   {      
+      writeIndent(out, indent);
+      out.write("/**");
+      writeEol(out);
+      writeIndent(out, indent);
+      out.write(" * Get the resource adapter");
+      writeEol(out);
+      writeIndent(out, indent);
+      out.write(" *");
+      writeEol(out);
+      writeIndent(out, indent);
+      out.write(" * @return The handle");
+      writeEol(out);
+      writeIndent(out, indent);
+      out.write(" */");
+      writeEol(out);
+      
+      writeIndent(out, indent);
+      out.write("public ResourceAdapter getResourceAdapter()");
+      writeLeftCurlyBracket(out, indent);
+      writeIndent(out, indent + 1);
+      out.write("log.debug(\"call getResourceAdapter\");");
+      writeEol(out);
+      writeIndent(out, indent + 1);
+      out.write("return null;");
+      writeRightCurlyBracket(out, indent);
+      writeEol(out);
+      
+      writeIndent(out, indent);
+      out.write("/**");
+      writeEol(out);
+      writeIndent(out, indent);
+      out.write(" * Set the resource adapter");
+      writeEol(out);
+      writeIndent(out, indent);
+      out.write(" *");
+      writeEol(out);
+      writeIndent(out, indent);
+      out.write(" * @param ra The handle");
+      writeEol(out);
+      writeIndent(out, indent);
+      out.write(" */");
+      writeEol(out);
+      
+      writeIndent(out, indent);
+      out.write("public void setResourceAdapter(ResourceAdapter ra)");
+      writeLeftCurlyBracket(out, indent);
+      writeIndent(out, indent + 1);
+      out.write("log.debug(\"call setResourceAdapter\");");
+      writeRightCurlyBracket(out, indent);
+      writeEol(out);
+   }
+}

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-27 07:40:09 UTC (rev 105293)
+++ projects/jboss-jca/trunk/codegenerator/src/main/java/org/jboss/jca/codegenerator/Definition.java	2010-05-27 08:01:41 UTC (rev 105294)
@@ -80,6 +80,13 @@
    /** use annotation or ra.xml  */
    private boolean useAnnotation;
    
+   /** support inbound  */
+   private boolean supportInbound;
+   /** connection metadata class name */
+   private String mlClass;
+   /** connection spec class name */
+   private String asClass;
+   
    /**
     * Set the outputDir.
     * 
@@ -514,4 +521,63 @@
       return useAnnotation;
    }
 
+   /**
+    * Set the supportInbound.
+    * 
+    * @param supportInbound The supportInbound to set.
+    */
+   public void setSupportInbound(boolean supportInbound)
+   {
+      this.supportInbound = supportInbound;
+   }
+
+   /**
+    * Get the supportInbound.
+    * 
+    * @return the supportInbound.
+    */
+   public boolean isSupportInbound()
+   {
+      return supportInbound;
+   }
+
+   /**
+    * Set the messageListenerClass.
+    * 
+    * @param messageListenerClass The messageListenerClass to set.
+    */
+   public void setMlClass(String messageListenerClass)
+   {
+      this.mlClass = messageListenerClass;
+   }
+
+   /**
+    * Get the messageListenerClass.
+    * 
+    * @return the messageListenerClass.
+    */
+   public String getMlClass()
+   {
+      return mlClass;
+   }
+
+   /**
+    * Set the activationSpecClass.
+    * 
+    * @param activationSpecClass The activationSpecClass to set.
+    */
+   public void setAsClass(String activationSpecClass)
+   {
+      this.asClass = activationSpecClass;
+   }
+
+   /**
+    * Get the activationSpecClass.
+    * 
+    * @return the activationSpecClass.
+    */
+   public String getAsClass()
+   {
+      return asClass;
+   }
 }

Modified: projects/jboss-jca/trunk/codegenerator/src/main/java/org/jboss/jca/codegenerator/JCA16AnnoProfile.java
===================================================================
--- projects/jboss-jca/trunk/codegenerator/src/main/java/org/jboss/jca/codegenerator/JCA16AnnoProfile.java	2010-05-27 07:40:09 UTC (rev 105293)
+++ projects/jboss-jca/trunk/codegenerator/src/main/java/org/jboss/jca/codegenerator/JCA16AnnoProfile.java	2010-05-27 08:01:41 UTC (rev 105294)
@@ -70,6 +70,12 @@
          generateClassCode(def, "RaMeta");
          generateClassCode(def, "ConnSpec");
       }
+      
+      if (def.isSupportInbound())
+      {
+         generateClassCode(def, "Ml");
+         generateClassCode(def, "As");
+      }
    }
 
    /**

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-27 07:40:09 UTC (rev 105293)
+++ projects/jboss-jca/trunk/codegenerator/src/main/java/org/jboss/jca/codegenerator/Main.java	2010-05-27 08:01:41 UTC (rev 105294)
@@ -175,6 +175,28 @@
             def.setConnImplClass(connImplName);
          }
          
+         System.out.print(dbconf.getString("support.inbound"));
+         String inbound = in.readLine();
+         if (inbound == null)
+            def.setSupportInbound(false);
+         else
+         {
+            if (inbound.equals("Y") || inbound.equals("y") || inbound.equals("Yes"))
+               def.setSupportInbound(true);
+            else
+               def.setSupportInbound(false);
+         }
+         
+         if (def.isSupportInbound())
+         {
+            System.out.print(dbconf.getString("ml.interface.name"));
+            String mlClassName = in.readLine();
+            def.setMlClass(mlClassName);
+            System.out.print(dbconf.getString("as.class.name"));
+            String asClassName = in.readLine();
+            def.setAsClass(asClassName);
+         }
+         
          def.setOutputDir(outputDir);
 
          profile.generate(def, packageName);
@@ -235,6 +257,26 @@
          varMap.put("mcf.config.props", raProps);
       }
       
+      if (def.isSupportInbound() && !def.isUseAnnotation())
+      {
+         StringBuilder inboundString = new StringBuilder();
+         inboundString.append("<inbound-resourceadapter>\n");
+         inboundString.append("         <messageadapter>\n");
+         inboundString.append("           <messagelistener>\n");
+         inboundString.append("             <messagelistener-type>");
+         inboundString.append(def.getRaPackage()).append(".").append(def.getMlClass());
+         inboundString.append("</messagelistener-type>\n");
+         inboundString.append("             <activationspec>\n");
+         inboundString.append("                <activationspec-class>");
+         inboundString.append(def.getRaPackage()).append(".").append(def.getAsClass());
+         inboundString.append("</activationspec-class>\n");
+         inboundString.append("             </activationspec>\n");
+         inboundString.append("           </messagelistener>\n");
+         inboundString.append("         </messageadapter>\n");
+         inboundString.append("      </inbound-resourceadapter>\n");
+         varMap.put("inbound", inboundString.toString());
+      }
+      
       template.process(varMap, rafw);
       rafw.close();
    }

Added: projects/jboss-jca/trunk/codegenerator/src/main/java/org/jboss/jca/codegenerator/MlCodeGen.java
===================================================================
--- projects/jboss-jca/trunk/codegenerator/src/main/java/org/jboss/jca/codegenerator/MlCodeGen.java	                        (rev 0)
+++ projects/jboss-jca/trunk/codegenerator/src/main/java/org/jboss/jca/codegenerator/MlCodeGen.java	2010-05-27 08:01:41 UTC (rev 105294)
@@ -0,0 +1,91 @@
+/*
+ * 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;
+
+/**
+ * A message listener CodeGen.
+ * 
+ * @author Jeff Zhang
+ * @version $Revision: $
+ */
+public class MlCodeGen extends AbstractCodeGen
+{
+
+   /**
+    * Output class
+    * @param def definition
+    * @param out Writer
+    * @throws IOException ioException
+    */
+   @Override
+   public void writeClassBody(Definition def, Writer out) throws IOException
+   {
+      int indent = 1;
+      out.write("public interface " + getClassName(def));
+      writeLeftCurlyBracket(out, 0);
+      writeIndent(out, indent);
+      out.write("/**");
+      writeEol(out);
+      writeIndent(out, indent);
+      out.write(" * receive message");
+      writeEol(out);
+      writeIndent(out, indent);
+      out.write(" * @param msg String.");
+      writeEol(out);
+      writeIndent(out, indent);
+      out.write(" */");
+      writeEol(out);
+      
+      writeIndent(out, indent);
+      out.write("public void onMessage(String msg);");
+
+      writeRightCurlyBracket(out, 0);
+   }
+   
+   /**
+    * Output class import
+    * @param def definition
+    * @param out Writer
+    * @throws IOException ioException
+    */
+   @Override
+   public void writeImport(Definition def, Writer out) throws IOException
+   {
+      out.write("package " + def.getRaPackage() + ";");
+      writeEol(out);
+      writeEol(out);
+   }
+   
+   /**
+    * get this class name
+    * @param def definition
+    * @return String class name
+    */
+   @Override
+   public String getClassName(Definition def)
+   {
+      return def.getMlClass();
+   }
+}

Modified: projects/jboss-jca/trunk/codegenerator/src/main/resources/codegenerator.properties
===================================================================
--- projects/jboss-jca/trunk/codegenerator/src/main/resources/codegenerator.properties	2010-05-27 07:40:09 UTC (rev 105293)
+++ projects/jboss-jca/trunk/codegenerator/src/main/resources/codegenerator.properties	2010-05-27 08:01:41 UTC (rev 105294)
@@ -16,4 +16,7 @@
 mcf.impl.raa=Use ResourceAdapterAssociation: [Y/N/Yes/No] 
 mcf.use.cci=Use CCI: [Y/N/Yes/No] 
 output.dir=Output directory: 
-code.wrote=Code generated
\ No newline at end of file
+code.wrote=Code generated
+support.inbound=Support inbound: [Y/N/Yes/No] 
+ml.interface.name=MessageListener interface name: 
+as.class.name=ActivationSpec class name: 
\ No newline at end of file

Modified: projects/jboss-jca/trunk/codegenerator/src/main/resources/ra.xml.template
===================================================================
--- projects/jboss-jca/trunk/codegenerator/src/main/resources/ra.xml.template	2010-05-27 07:40:09 UTC (rev 105293)
+++ projects/jboss-jca/trunk/codegenerator/src/main/resources/ra.xml.template	2010-05-27 08:01:41 UTC (rev 105294)
@@ -29,5 +29,7 @@
          <transaction-support>NoTransaction</transaction-support>
          <reauthentication-support>false</reauthentication-support>
       </outbound-resourceadapter>
+      
+      ${inbound}
    </resourceadapter>
 </connector>
\ No newline at end of file




More information about the jboss-cvs-commits mailing list