[jboss-cvs] JBossAS SVN: r104547 - 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 6 23:21:41 EDT 2010
Author: jeff.zhang
Date: 2010-05-06 23:21:39 -0400 (Thu, 06 May 2010)
New Revision: 104547
Added:
projects/jboss-jca/trunk/codegenerator/src/main/java/org/jboss/jca/codegenerator/PropsCodeGen.java
Modified:
projects/jboss-jca/trunk/codegenerator/src/main/java/org/jboss/jca/codegenerator/ConnImplCodeGen.java
projects/jboss-jca/trunk/codegenerator/src/main/java/org/jboss/jca/codegenerator/ConnInterfaceCodeGen.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/McfCodeGen.java
projects/jboss-jca/trunk/codegenerator/src/main/java/org/jboss/jca/codegenerator/RaCodeGen.java
projects/jboss-jca/trunk/codegenerator/src/main/resources/codegenerator.properties
Log:
[JBJCA-307] config properties for mcf java code
Modified: projects/jboss-jca/trunk/codegenerator/src/main/java/org/jboss/jca/codegenerator/ConnImplCodeGen.java
===================================================================
--- projects/jboss-jca/trunk/codegenerator/src/main/java/org/jboss/jca/codegenerator/ConnImplCodeGen.java 2010-05-07 02:09:44 UTC (rev 104546)
+++ projects/jboss-jca/trunk/codegenerator/src/main/java/org/jboss/jca/codegenerator/ConnImplCodeGen.java 2010-05-07 03:21:39 UTC (rev 104547)
@@ -42,16 +42,17 @@
@Override
public void writeClassBody(Definition def, Writer out) throws IOException
{
- int indent = 1;
+
out.write("public class " + getClassName(def) + " implements " + def.getConnInterfaceClass());
writeLeftCurlyBracket(out, 0);
+ int indent = 1;
writeIndent(out, indent);
out.write("private static Logger log = Logger.getLogger(" + getClassName(def) + ".class);");
writeEol(out);
writeEol(out);
writeIndent(out, indent);
out.write("public void callMe()");
- writeLeftCurlyBracket(out, 0);
+ writeLeftCurlyBracket(out, indent);
writeIndent(out, indent + 1);
out.write("log.debug(\"call callMe\");");
Modified: projects/jboss-jca/trunk/codegenerator/src/main/java/org/jboss/jca/codegenerator/ConnInterfaceCodeGen.java
===================================================================
--- projects/jboss-jca/trunk/codegenerator/src/main/java/org/jboss/jca/codegenerator/ConnInterfaceCodeGen.java 2010-05-07 02:09:44 UTC (rev 104546)
+++ projects/jboss-jca/trunk/codegenerator/src/main/java/org/jboss/jca/codegenerator/ConnInterfaceCodeGen.java 2010-05-07 03:21:39 UTC (rev 104547)
@@ -48,7 +48,6 @@
writeIndent(out, indent);
out.write("public void callMe();");
- writeEol(out);
writeRightCurlyBracket(out, 0);
}
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-07 02:09:44 UTC (rev 104546)
+++ projects/jboss-jca/trunk/codegenerator/src/main/java/org/jboss/jca/codegenerator/Definition.java 2010-05-07 03:21:39 UTC (rev 104547)
@@ -39,8 +39,12 @@
private String raClass;
/** resource adapter configuration properties */
private List<ConfigPropType> raConfigProps;
+
/** managed connection factory class name */
private String mcfClass;
+ /** resource adapter configuration properties */
+ private List<ConfigPropType> mcfConfigProps;
+
/** managed connection class name */
private String mcClass;
/** connection interface name */
@@ -208,4 +212,24 @@
return connImplClass;
}
+ /**
+ * Set the mcfConfigProps.
+ *
+ * @param mcfConfigProps The mcfConfigProps to set.
+ */
+ public void setMcfConfigProps(List<ConfigPropType> mcfConfigProps)
+ {
+ this.mcfConfigProps = mcfConfigProps;
+ }
+
+ /**
+ * Get the mcfConfigProps.
+ *
+ * @return the mcfConfigProps.
+ */
+ public List<ConfigPropType> getMcfConfigProps()
+ {
+ return mcfConfigProps;
+ }
+
}
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-07 02:09:44 UTC (rev 104546)
+++ projects/jboss-jca/trunk/codegenerator/src/main/java/org/jboss/jca/codegenerator/Main.java 2010-05-07 03:21:39 UTC (rev 104547)
@@ -92,7 +92,7 @@
def.setRaPackage(packageName);
def.setRaClass(raClassName);
- List<ConfigPropType> props = new ArrayList<ConfigPropType>();
+ List<ConfigPropType> raProps = new ArrayList<ConfigPropType>();
while (true)
{
System.out.println(dbconf.getString("ra.config.properties"));
@@ -107,13 +107,33 @@
System.out.println();
ConfigPropType config = new ConfigPropType(name, type, value);
- props.add(config);
+ raProps.add(config);
}
- def.setRaConfigProps(props);
+ def.setRaConfigProps(raProps);
System.out.print(dbconf.getString("mcf.class.name"));
String mcfClassName = in.readLine();
def.setMcfClass(mcfClassName);
+
+ List<ConfigPropType> mcfProps = new ArrayList<ConfigPropType>();
+ while (true)
+ {
+ System.out.println(dbconf.getString("mcf.config.properties"));
+ System.out.print(" " + dbconf.getString("config.properties.name"));
+ String name = in.readLine();
+ if (name == null || name.equals(""))
+ break;
+ System.out.print(" " + dbconf.getString("config.properties.type"));
+ String type = in.readLine();
+ System.out.print(" " + dbconf.getString("config.properties.value"));
+ String value = in.readLine();
+ System.out.println();
+
+ ConfigPropType config = new ConfigPropType(name, type, value);
+ mcfProps.add(config);
+ }
+ def.setMcfConfigProps(mcfProps);
+
System.out.print(dbconf.getString("mc.class.name"));
String mcClassName = in.readLine();
def.setMcClass(mcClassName);
Modified: projects/jboss-jca/trunk/codegenerator/src/main/java/org/jboss/jca/codegenerator/McfCodeGen.java
===================================================================
--- projects/jboss-jca/trunk/codegenerator/src/main/java/org/jboss/jca/codegenerator/McfCodeGen.java 2010-05-07 02:09:44 UTC (rev 104546)
+++ projects/jboss-jca/trunk/codegenerator/src/main/java/org/jboss/jca/codegenerator/McfCodeGen.java 2010-05-07 03:21:39 UTC (rev 104547)
@@ -23,6 +23,7 @@
import java.io.IOException;
import java.io.Writer;
+import java.util.List;
/**
* A McfCodeGen.
@@ -30,7 +31,7 @@
* @author Jeff Zhang
* @version $Revision: $
*/
-public class McfCodeGen extends AbstractCodeGen
+public class McfCodeGen extends PropsCodeGen
{
/**
@@ -80,6 +81,7 @@
writeRightCurlyBracket(out, indent);
writeEol(out);
+ writeConfigProps(def, out, indent);
writeConnectionFactory(def, out, indent);
writeManagedConnection(def, out, indent);
writeLogWriter(def, out, indent);
@@ -110,6 +112,8 @@
writeEol(out);
out.write("import javax.resource.ResourceException;");
writeEol(out);
+ out.write("import javax.resource.spi.ConfigProperty;");
+ writeEol(out);
out.write("import javax.resource.spi.ConnectionDefinition;");
writeEol(out);
out.write("import javax.resource.spi.ConnectionManager;");
@@ -145,6 +149,17 @@
}
/**
+ * get list of ConfigPropType
+ * @param def definition
+ * @return List<ConfigPropType> List of ConfigPropType
+ */
+ @Override
+ public List<ConfigPropType> getConfigProps(Definition def)
+ {
+ return def.getMcfConfigProps();
+ }
+
+ /**
* Output ConnectionFactory method
* @param def definition
* @param out Writer
Added: projects/jboss-jca/trunk/codegenerator/src/main/java/org/jboss/jca/codegenerator/PropsCodeGen.java
===================================================================
--- projects/jboss-jca/trunk/codegenerator/src/main/java/org/jboss/jca/codegenerator/PropsCodeGen.java (rev 0)
+++ projects/jboss-jca/trunk/codegenerator/src/main/java/org/jboss/jca/codegenerator/PropsCodeGen.java 2010-05-07 03:21:39 UTC (rev 104547)
@@ -0,0 +1,225 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.jca.codegenerator;
+
+import java.io.IOException;
+import java.io.Writer;
+import java.util.List;
+
+/**
+ * A properties code generator
+ *
+ * @author Jeff Zhang
+ * @version $Revision: $
+ */
+public abstract class PropsCodeGen extends AbstractCodeGen
+{
+ /**
+ * Output Configuration Properties
+ * @param def definition
+ * @param out Writer
+ * @param indent space number
+ * @throws IOException ioException
+ */
+ void writeConfigProps(Definition def, Writer out, int indent) throws IOException
+ {
+ if (getConfigProps(def) == null)
+ return;
+
+ for (int i = 0; i < getConfigProps(def).size(); i++)
+ {
+ writeIndent(out, indent);
+ out.write("@ConfigProperty(defaultValue=\"" + getConfigProps(def).get(i).getValue() + "\")");
+ writeEol(out);
+ writeIndent(out, indent);
+ out.write("private " +
+ getConfigProps(def).get(i).getType() +
+ " " +
+ getConfigProps(def).get(i).getName() +
+ ";");
+ writeEol(out);
+ writeEol(out);
+ }
+
+ for (int i = 0; i < getConfigProps(def).size(); i++)
+ {
+ String name = getConfigProps(def).get(i).getName();
+ String upcaseName = upcaseFisrt(name);
+ //set
+ writeIndent(out, indent);
+ out.write("public void set" +
+ upcaseName +
+ "(" +
+ getConfigProps(def).get(i).getType() +
+ " " +
+ name +
+ ")");
+ writeLeftCurlyBracket(out, indent);
+ writeIndent(out, indent + 1);
+ out.write("this." + name + " = " + name + ";");
+ writeRightCurlyBracket(out, indent);
+ writeEol(out);
+
+ //get
+ writeIndent(out, indent);
+ out.write("public " +
+ getConfigProps(def).get(i).getType() +
+ " get" +
+ upcaseName +
+ "()");
+ writeLeftCurlyBracket(out, indent);
+ writeIndent(out, indent + 1);
+ out.write("return " + name + ";");
+ writeRightCurlyBracket(out, indent);
+ writeEol(out);
+ }
+ }
+
+ /**
+ * Output hashCode method
+ * @param def definition
+ * @param out Writer
+ * @param indent space number
+ * @throws IOException ioException
+ */
+ @Override
+ void writeHashCode(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("int result = 17;");
+ writeEol(out);
+ for (int i = 0; i < getConfigProps(def).size(); i++)
+ {
+ writeIndent(out, indent + 1);
+ String type = getConfigProps(def).get(i).getType();
+ if (type.equals("int"))
+ {
+ out.write("result = 31 * result + " + getConfigProps(def).get(i).getName() + ";");
+ }
+ else if (type.equals("short") || type.equals("char") || type.equals("byte"))
+ {
+ out.write("result = 31 * result + (int)" + getConfigProps(def).get(i).getName() + ";");
+ }
+ else if (type.equals("boolean"))
+ {
+ out.write("result = 31 * result + (" + getConfigProps(def).get(i).getName() + " ? 0 : 1);");
+ }
+ else if (type.equals("long"))
+ {
+ out.write("result = 31 * result + (int)(" + getConfigProps(def).get(i).getName() +
+ " ^ (" + getConfigProps(def).get(i).getName() + " >>> 32));");
+ }
+ else if (type.equals("float"))
+ {
+ out.write("result = 31 * result + Float.floatToIntBits(" + getConfigProps(def).get(i).getName() + ");");
+ }
+ else if (type.equals("double"))
+ {
+ out.write("long tolong = Double.doubleToLongBits(" + getConfigProps(def).get(i).getName() + ");");
+ writeEol(out);
+ writeIndent(out, indent + 1);
+ out.write("result = 31 * result + (int)(tolong ^ (tolong >>> 32));");
+ }
+ else
+ {
+ out.write("result = 31 * result + " + getConfigProps(def).get(i).getName() + ".hashCode();");
+ }
+ writeEol(out);
+ }
+ writeIndent(out, indent + 1);
+ out.write("return result;");
+ writeRightCurlyBracket(out, indent);
+ writeEol(out);
+ }
+
+
+ /**
+ * Output equals method
+ * @param def definition
+ * @param out Writer
+ * @param indent space number
+ * @throws IOException ioException
+ */
+ @Override
+ void writeEquals(Definition def, Writer out, int indent) throws IOException
+ {
+ writeIndent(out, indent);
+ out.write("@Override");
+ writeEol(out);
+ writeIndent(out, indent);
+ out.write("public boolean equals(Object other)");
+ 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("if (other == this)");
+ writeEol(out);
+ writeIndent(out, indent + 2);
+ out.write("return true;");
+ writeEol(out);
+ writeIndent(out, indent + 1);
+ out.write("if (!(other instanceof " + getClassName(def) + "))");
+ writeEol(out);
+ writeIndent(out, indent + 2);
+ out.write("return false;");
+ writeEol(out);
+ writeIndent(out, indent + 1);
+ out.write(getClassName(def) + " obj = (" + getClassName(def) + ")other;");
+ writeEol(out);
+ writeIndent(out, indent + 1);
+ out.write("return ");
+ if (getConfigProps(def).size() == 0)
+ {
+ out.write("true");
+ }
+ for (int i = 0; i < getConfigProps(def).size(); i++)
+ {
+ if (i != 0)
+ {
+ writeEol(out);
+ writeIndent(out, indent + 2);
+ out.write("&& ");
+ }
+ out.write(getConfigProps(def).get(i).getName() + " == obj." + getConfigProps(def).get(i).getName());
+ }
+ out.write(";");
+ writeRightCurlyBracket(out, indent);
+ writeEol(out);
+ }
+
+ /**
+ * get list of ConfigPropType
+ * @param def TODO
+ * @return List<ConfigPropType> List of ConfigPropType
+ */
+ public abstract List<ConfigPropType> getConfigProps(Definition def);
+}
Modified: projects/jboss-jca/trunk/codegenerator/src/main/java/org/jboss/jca/codegenerator/RaCodeGen.java
===================================================================
--- projects/jboss-jca/trunk/codegenerator/src/main/java/org/jboss/jca/codegenerator/RaCodeGen.java 2010-05-07 02:09:44 UTC (rev 104546)
+++ projects/jboss-jca/trunk/codegenerator/src/main/java/org/jboss/jca/codegenerator/RaCodeGen.java 2010-05-07 03:21:39 UTC (rev 104547)
@@ -23,14 +23,15 @@
import java.io.IOException;
import java.io.Writer;
+import java.util.List;
/**
* A resource adapter code generator
*
* @author Jeff Zhang
- * @version $Revision: 1.1 $
+ * @version $Revision: $
*/
-public class RaCodeGen extends AbstractCodeGen
+public class RaCodeGen extends PropsCodeGen
{
/**
* Output ResourceAdapater class
@@ -106,191 +107,8 @@
writeEol(out);
writeEol(out);
}
-
- /**
- * Output Configuration Properties
- * @param def definition
- * @param out Writer
- * @param indent space number
- * @throws IOException ioException
- */
- private void writeConfigProps(Definition def, Writer out, int indent) throws IOException
- {
- if (def.getRaConfigProps() == null)
- return;
-
- for (int i = 0; i < def.getRaConfigProps().size(); i++)
- {
- writeIndent(out, indent);
- out.write("@ConfigProperty(defaultValue=\"" + def.getRaConfigProps().get(i).getValue() + "\")");
- writeEol(out);
- writeIndent(out, indent);
- out.write("private " +
- def.getRaConfigProps().get(i).getType() +
- " " +
- def.getRaConfigProps().get(i).getName() +
- ";");
- writeEol(out);
- writeEol(out);
- }
- for (int i = 0; i < def.getRaConfigProps().size(); i++)
- {
- String name = def.getRaConfigProps().get(i).getName();
- String upcaseName = upcaseFisrt(name);
- //set
- writeIndent(out, indent);
- out.write("public void set" +
- upcaseName +
- "(" +
- def.getRaConfigProps().get(i).getType() +
- " " +
- name +
- ")");
- writeLeftCurlyBracket(out, indent);
- writeIndent(out, indent + 1);
- out.write("this." + name + " = " + name + ";");
- writeRightCurlyBracket(out, indent);
- writeEol(out);
-
- //get
- writeIndent(out, indent);
- out.write("public " +
- def.getRaConfigProps().get(i).getType() +
- " get" +
- upcaseName +
- "()");
- writeLeftCurlyBracket(out, indent);
- writeIndent(out, indent + 1);
- out.write("return " + name + ";");
- writeRightCurlyBracket(out, indent);
- writeEol(out);
- }
- }
-
/**
- * Output hashCode method
- * @param def definition
- * @param out Writer
- * @param indent space number
- * @throws IOException ioException
- */
- @Override
- void writeHashCode(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("int result = 17;");
- writeEol(out);
- for (int i = 0; i < def.getRaConfigProps().size(); i++)
- {
- writeIndent(out, indent + 1);
- String type = def.getRaConfigProps().get(i).getType();
- if (type.equals("int"))
- {
- out.write("result = 31 * result + " + def.getRaConfigProps().get(i).getName() + ";");
- }
- else if (type.equals("short") || type.equals("char") || type.equals("byte"))
- {
- out.write("result = 31 * result + (int)" + def.getRaConfigProps().get(i).getName() + ";");
- }
- else if (type.equals("boolean"))
- {
- out.write("result = 31 * result + (" + def.getRaConfigProps().get(i).getName() + " ? 0 : 1);");
- }
- else if (type.equals("long"))
- {
- out.write("result = 31 * result + (int)(" + def.getRaConfigProps().get(i).getName() +
- " ^ (" + def.getRaConfigProps().get(i).getName() + " >>> 32));");
- }
- else if (type.equals("float"))
- {
- out.write("result = 31 * result + Float.floatToIntBits(" + def.getRaConfigProps().get(i).getName() + ");");
- }
- else if (type.equals("double"))
- {
- out.write("long tolong = Double.doubleToLongBits(" + def.getRaConfigProps().get(i).getName() + ");");
- writeEol(out);
- writeIndent(out, indent + 1);
- out.write("result = 31 * result + (int)(tolong ^ (tolong >>> 32));");
- }
- else
- {
- out.write("result = 31 * result + " + def.getRaConfigProps().get(i).getName() + ".hashCode();");
- }
- writeEol(out);
- }
- writeIndent(out, indent + 1);
- out.write("return result;");
- writeRightCurlyBracket(out, indent);
- writeEol(out);
- }
-
-
- /**
- * Output equals method
- * @param def definition
- * @param out Writer
- * @param indent space number
- * @throws IOException ioException
- */
- @Override
- void writeEquals(Definition def, Writer out, int indent) throws IOException
- {
- writeIndent(out, indent);
- out.write("@Override");
- writeEol(out);
- writeIndent(out, indent);
- out.write("public boolean equals(Object other)");
- 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("if (other == this)");
- writeEol(out);
- writeIndent(out, indent + 2);
- out.write("return true;");
- writeEol(out);
- writeIndent(out, indent + 1);
- out.write("if (!(other instanceof " + def.getRaClass() + "))");
- writeEol(out);
- writeIndent(out, indent + 2);
- out.write("return false;");
- writeEol(out);
- writeIndent(out, indent + 1);
- out.write(def.getRaClass() + " ra = (" + def.getRaClass() + ")other;");
- writeEol(out);
- writeIndent(out, indent + 1);
- out.write("return ");
- if (def.getRaConfigProps().size() == 0)
- {
- out.write("true");
- }
- for (int i = 0; i < def.getRaConfigProps().size(); i++)
- {
- if (i != 0)
- {
- writeEol(out);
- writeIndent(out, indent + 2);
- out.write("&& ");
- }
- out.write(def.getRaConfigProps().get(i).getName() + " == ra." + def.getRaConfigProps().get(i).getName());
- }
- out.write(";");
- writeRightCurlyBracket(out, indent);
- writeEol(out);
- }
-
- /**
* Output getXAResources method
* @param def definition
* @param out Writer
@@ -385,4 +203,15 @@
{
return def.getRaClass();
}
+
+ /**
+ * get list of ConfigPropType
+ * @param def definition
+ * @return List<ConfigPropType> List of ConfigPropType
+ */
+ @Override
+ public List<ConfigPropType> getConfigProps(Definition def)
+ {
+ return def.getRaConfigProps();
+ }
}
Modified: projects/jboss-jca/trunk/codegenerator/src/main/resources/codegenerator.properties
===================================================================
--- projects/jboss-jca/trunk/codegenerator/src/main/resources/codegenerator.properties 2010-05-07 02:09:44 UTC (rev 104546)
+++ projects/jboss-jca/trunk/codegenerator/src/main/resources/codegenerator.properties 2010-05-07 03:21:39 UTC (rev 104547)
@@ -8,5 +8,6 @@
config.properties.name=Name:
config.properties.type=Type:
config.properties.value=Value:
+mcf.config.properties=Managed connection factory config properties [enter to quit]:
output.dir=Output directory:
code.wrote=Code generated
\ No newline at end of file
More information about the jboss-cvs-commits
mailing list