[jboss-cvs] JBossAS SVN: r106230 - 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
Wed Jun 23 05:14:11 EDT 2010


Author: jeff.zhang
Date: 2010-06-23 05:14:11 -0400 (Wed, 23 Jun 2010)
New Revision: 106230

Added:
   projects/jboss-jca/trunk/codegenerator/src/main/java/org/jboss/jca/codegenerator/ObjectFactory.java
   projects/jboss-jca/trunk/codegenerator/src/main/resources/definition.xml
Modified:
   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/java/org/jboss/jca/codegenerator/Main.java
   projects/jboss-jca/trunk/codegenerator/src/main/java/org/jboss/jca/codegenerator/MethodForConnection.java
Log:
[JBJCA-366] input definition from xml file

Modified: 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	2010-06-23 06:28:09 UTC (rev 106229)
+++ projects/jboss-jca/trunk/codegenerator/src/main/java/org/jboss/jca/codegenerator/ConfigPropType.java	2010-06-23 09:14:11 UTC (rev 106230)
@@ -39,7 +39,14 @@
    private boolean required;
 
    /**
-    * Set the name.
+    * constructor
+    */
+   public ConfigPropType()
+   {
+   }
+   
+   /**
+    * constructor with initial value
     * 
     * @param name The name to set.
     * @param type The type to set.

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-06-23 06:28:09 UTC (rev 106229)
+++ projects/jboss-jca/trunk/codegenerator/src/main/java/org/jboss/jca/codegenerator/Definition.java	2010-06-23 09:14:11 UTC (rev 106230)
@@ -23,55 +23,79 @@
 
 import java.util.List;
 
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
+
 /**
  * A Definition.
  * 
  * @author Jeff Zhang</a>
  * @version $Revision: $
  */
+ at XmlRootElement(name = "definition")
+ at XmlAccessorType(XmlAccessType.FIELD)
 public class Definition
 {
    /** jca version  */
+   @XmlElement(name = "version")
    private String version;
    /** output directory  */
    private String outputDir;
    /** resource adapter package name */
+   @XmlElement(name = "package")
    private String raPackage;
    
    /** default value for proper input */
    private String defaultValue = "Acme";
    
    /** use annotation or ra.xml  */
+   @XmlElement(name = "annotation")
    private boolean useAnnotation;
    /** use resource adapter  */
+   @XmlElement(name = "UseResourceAdapter")
    private boolean useRa;
-   /** support transaction  */
-   private String supportTransaction;
 
    /** resource adapter class name */
+   @XmlElement(name = "ResourceAdapter")
    private String raClass;
    /** resource adapter configuration properties */
+   @XmlElement(name = "RaConfigProp") 
    private List<ConfigPropType> raConfigProps;
    
    /** managed connection factory class name */
+   @XmlElement(name = "ManagedConnectionFactory")
    private String mcfClass;
    /** resource adapter configuration properties */
+   @XmlElement(name = "McfConfigProp") 
    private List<ConfigPropType> mcfConfigProps;
    
+   /** support transaction  */
+   @XmlElement(name = "Transaction") 
+   private String supportTransaction;
+
    /** managed connection class name */
+   @XmlElement(name = "ManagedConnection")
    private String mcClass;
    /** connection interface name */
+   @XmlElement(name = "ConnectionInterface")
    private String connInterfaceClass;
    /** connection impl class name */
+   @XmlElement(name = "ConnectionImpl")
    private String connImplClass;
    /** connection factory interface name */
+   @XmlElement(name = "ConnectionFactoryInterface")
    private String cfInterfaceClass;
    /** connection factory class name */
+   @XmlElement(name = "ConnectionFactoryImpl")
    private String cfClass;
    
    /** ResourceAdapterAssociation optional  */
+   @XmlElement(name = "ImplRaAssociation")
    private boolean implRaAssociation;
    /** ResourceAdapterAssociation optional  */
+   @XmlElement(name = "UseCciConnection")
    private boolean useCciConnection;
    
    /** cci connection factory class name */
@@ -91,21 +115,29 @@
    private String raMetaClass;
 
    /** support outbound  */
+   @XmlElement(name = "SupportOutbound")
    private boolean supportOutbound;
    /** support inbound  */
+   @XmlElement(name = "SupportInbound")
    private boolean supportInbound;
-   /** connection metadata class name */
+   /** connection message listener class name */
+   @XmlElement(name = "MessageListener")
    private String mlClass;
    /** ActivationSpec class name */
+   @XmlElement(name = "ActivationSpec")
    private String asClass;
    /** ActivationSpec configuration properties */
+   @XmlElement(name = "AsConfigProp")
    private List<ConfigPropType> asConfigProps;
    /** Activation class name */
+   @XmlElement(name = "Activation")
    private String activationClass;
    
-   /** support self deined method in connection interface  */
+   /** support self defined method in connection class  */
+   @XmlElement(name = "DefineMethod") 
    private boolean defineMethodInConnection;
-   /** connection metadata class name */
+   /** define methods */
+   @XmlElement(name = "Method") 
    private List<MethodForConnection> methods;
    
    /**

Modified: projects/jboss-jca/trunk/codegenerator/src/main/java/org/jboss/jca/codegenerator/Main.java
===================================================================
--- projects/jboss-jca/trunk/codegenerator/src/main/java/org/jboss/jca/codegenerator/Main.java	2010-06-23 06:28:09 UTC (rev 106229)
+++ projects/jboss-jca/trunk/codegenerator/src/main/java/org/jboss/jca/codegenerator/Main.java	2010-06-23 09:14:11 UTC (rev 106230)
@@ -30,6 +30,11 @@
 import java.util.Locale;
 import java.util.ResourceBundle;
 
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.JAXBException;
+import javax.xml.bind.Unmarshaller;
+
+
 /**
  * Code generator main class
  * 
@@ -38,6 +43,8 @@
  */
 public class Main
 {
+   private static final int SUCCESS = 0;
+   private static final int ERROR = 1;
    private static final int OTHER = 2;
 
    /** ResourceBundle */
@@ -51,6 +58,7 @@
    public static void main(String[] args)
    {
       String outputDir = "out"; //default output directory
+      String defxml = null;
       int arg = 0;
  
       if (args.length > 0)
@@ -69,6 +77,16 @@
                   }
                   outputDir = args[arg];
                }
+               else if (args[arg].equals("-f"))
+               {
+                  arg++;
+                  if (arg >= args.length)
+                  {
+                     usage();
+                     System.exit(OTHER);
+                  }
+                  defxml = args[arg];
+               }
             } 
             else
             {
@@ -83,25 +101,73 @@
          File out = new File(outputDir);
          Utils.recursiveDelete(out);
 
-         inputFromCommandLine(outputDir);
+         Definition def = null;
          
+         if (defxml == null)
+            def = inputFromCommandLine();
+         else
+            def = inputFromXml(defxml);
+         
+         if (def == null)
+            System.exit(ERROR);
+         
+         def.setOutputDir(outputDir);
+
+         Profile profile;
+         if (def.getVersion().equals("1.6"))
+         {
+            profile = new JCA16Profile();
+         }
+         else if (def.getVersion().equals("1.5"))
+         {
+            profile = new JCA15Profile();
+         }
+         else
+         {
+            profile = new JCA10Profile();
+         }
+         profile.generate(def);
+         
          copyAllJars(outputDir);
          
          System.out.println(rb.getString("code.wrote"));
+         System.exit(SUCCESS);
       }
       catch (IOException e)
       {
          e.printStackTrace();
       }
+      catch (JAXBException e)
+      {
+         e.printStackTrace();
+      }
    }
+   
+   /**
+    * input from xml file
+    * 
+    * @param defxml definition xml file
+    * @throws IOException ioException
+    * @throws JAXBException jaxb exception
+    * @return Definition definition from input
+    */
+   private static Definition inputFromXml(String defxml) throws IOException, JAXBException
+   {
+      JAXBContext context = JAXBContext.newInstance("org.jboss.jca.codegenerator");
+      Unmarshaller unmarshaller = context.createUnmarshaller();
+      Definition def = (Definition)unmarshaller.unmarshal(new File(defxml));
+      //System.out.println(def.getVersion());
 
+      return def;
+   }
+
    /**
     * input from command line 
     * 
-    * @param outputDir output directory
     * @throws IOException ioException
+    * @return Definition definition from input
     */
-   private static void inputFromCommandLine(String outputDir) throws IOException
+   private static Definition inputFromCommandLine() throws IOException
    {
       BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
       Definition def = new Definition();
@@ -322,7 +388,6 @@
             }
          }
       }
-      
 
       //inbound
       if (def.isSupportInbound())
@@ -336,7 +401,7 @@
             setDefaultValue(def, mlClassName, "MessageListener");
             setDefaultValue(def, mlClassName, "Ml");
          }
-         
+
          System.out.print(rb.getString("as.class.name"));
          System.out.print("[" + def.getAsClass() + "] ");
          String asClassName = in.readLine();
@@ -352,23 +417,8 @@
          if (actiClassName != null && !actiClassName.equals(""))
             def.setActivationClass(actiClassName);
       }
-      
-      def.setOutputDir(outputDir);
 
-      Profile profile;
-      if (version.equals("1.6"))
-      {
-         profile = new JCA16Profile();
-      }
-      else if (version.equals("1.5"))
-      {
-         profile = new JCA15Profile();
-      }
-      else
-      {
-         profile = new JCA10Profile();
-      }
-      profile.generate(def);
+      return def;
    }
 
    /**

Modified: projects/jboss-jca/trunk/codegenerator/src/main/java/org/jboss/jca/codegenerator/MethodForConnection.java
===================================================================
--- projects/jboss-jca/trunk/codegenerator/src/main/java/org/jboss/jca/codegenerator/MethodForConnection.java	2010-06-23 06:28:09 UTC (rev 106229)
+++ projects/jboss-jca/trunk/codegenerator/src/main/java/org/jboss/jca/codegenerator/MethodForConnection.java	2010-06-23 09:14:11 UTC (rev 106230)
@@ -24,21 +24,29 @@
 import java.util.ArrayList;
 import java.util.List;
 
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlElement;
+
 /**
  * A MethodForConnection.
  * 
  * @author Jeff Zhang</a>
  * @version $Revision: $
  */
+ at XmlAccessorType(XmlAccessType.FIELD)
 public class MethodForConnection
 {
    /** name */
+   @XmlElement(name = "MethodName")
    private String methodName;
    /** type */
+   @XmlElement(name = "ReturnType")
    private String returnType = "void";
    /** value */
    private List<MethodParam> params = new ArrayList<MethodParam>();
    /** required */
+   @XmlElement(name = "ExceptionType")
    private List<String> exceptionType = new ArrayList<String>();
 
    /**

Added: projects/jboss-jca/trunk/codegenerator/src/main/java/org/jboss/jca/codegenerator/ObjectFactory.java
===================================================================
--- projects/jboss-jca/trunk/codegenerator/src/main/java/org/jboss/jca/codegenerator/ObjectFactory.java	                        (rev 0)
+++ projects/jboss-jca/trunk/codegenerator/src/main/java/org/jboss/jca/codegenerator/ObjectFactory.java	2010-06-23 09:14:11 UTC (rev 106230)
@@ -0,0 +1,52 @@
+/*
+ * 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 javax.xml.bind.annotation.XmlRegistry;
+
+/**
+ * A ObjectFactory.
+ * 
+ * @author Jeff Zhang
+ * @version $Revision: $
+ */
+ at XmlRegistry
+public class ObjectFactory
+{
+   /**
+    * Create a new ObjectFactory that can be used to create new instances of schema derived classes
+    * 
+    */
+   public ObjectFactory() 
+   {
+   }
+   
+   /**
+    * Create an instance of {@link Definition }
+    * 
+    * @return Definition Definition
+    */
+   public Definition createDefinition()
+   {
+      return new Definition();
+   }
+}

Added: projects/jboss-jca/trunk/codegenerator/src/main/resources/definition.xml
===================================================================
--- projects/jboss-jca/trunk/codegenerator/src/main/resources/definition.xml	                        (rev 0)
+++ projects/jboss-jca/trunk/codegenerator/src/main/resources/definition.xml	2010-06-23 09:14:11 UTC (rev 106230)
@@ -0,0 +1,64 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<definition>
+
+   <version>1.6</version>
+   <package>org.jca</package>
+   <annotation>true</annotation>
+
+   <SupportOutbound>true</SupportOutbound>
+   <SupportInbound>true</SupportInbound>
+
+   <UseResourceAdapter>true</UseResourceAdapter>
+   <ResourceAdapter>AcmeResourceAdapter</ResourceAdapter>
+   <RaConfigProp>
+      <name>p1</name>
+      <type>java.lang.String</type>
+      <value>hello</value>
+   </RaConfigProp>
+   <RaAssociation/>
+   <ImplRaAssociation>true</ImplRaAssociation>
+   
+   <ManagedConnectionFactory>AcmeManagedConnectionFactory</ManagedConnectionFactory>
+   <McfConfigProp>
+      <name>p2</name>
+      <type>java.lang.Integer</type>
+      <value>13</value>
+   </McfConfigProp>
+   <ManagedConnection>AcmeManagedConnection</ManagedConnection>
+
+   <Transaction>LocalTransaction</Transaction>
+
+   <UseCciConnection>false</UseCciConnection>
+   <ConnectionFactoryInterface>AcmeConnectionFactoryInterface</ConnectionFactoryInterface>
+   <ConnectionFactoryImpl>AcmeConnectionFactoryImpl</ConnectionFactoryImpl>
+   <ConnectionInterface>AcmeConnectionInterface</ConnectionInterface>
+   <ConnectionImpl>AcmeConnectionImpl</ConnectionImpl>
+
+   <DefineMethod>true</DefineMethod>
+   <Method>
+      <MethodName>callMe</MethodName>
+      <ReturnType>void</ReturnType>
+      <params>
+         <name>m1</name>
+         <type>java.lang.Integer</type>
+      </params>
+      <params>
+         <name>m2</name>
+         <type>java.lang.String</type>
+      </params>
+      <ExceptionType>Exception</ExceptionType>
+   </Method>
+
+
+   <MessageListener>AcmeMessageListener</MessageListener>
+   <ActivationSpec>AcmeActivationSpec</ActivationSpec>
+   <AsConfigProp>
+      <name>p3</name>
+      <type>java.lang.Float</type>
+      <value>3.14</value>
+      <required>3.14</required>
+   </AsConfigProp>
+   <Activation>AcmeActivation</Activation>
+
+</definition>



More information about the jboss-cvs-commits mailing list