[jboss-cvs] JBossAS SVN: r109064 - in projects/jboss-jca/trunk/codegenerator/src/main/java/org/jboss/jca/codegenerator: code and 1 other directory.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Tue Nov 2 04:09:17 EDT 2010
Author: jeff.zhang
Date: 2010-11-02 04:09:17 -0400 (Tue, 02 Nov 2010)
New Revision: 109064
Added:
projects/jboss-jca/trunk/codegenerator/src/main/java/org/jboss/jca/codegenerator/code/MbeanImplCodeGen.java
projects/jboss-jca/trunk/codegenerator/src/main/java/org/jboss/jca/codegenerator/code/MbeanInterfaceCodeGen.java
Modified:
projects/jboss-jca/trunk/codegenerator/src/main/java/org/jboss/jca/codegenerator/BaseProfile.java
projects/jboss-jca/trunk/codegenerator/src/main/java/org/jboss/jca/codegenerator/Definition.java
Log:
[JBJCA-457] Generate MBean test artifact
Modified: projects/jboss-jca/trunk/codegenerator/src/main/java/org/jboss/jca/codegenerator/BaseProfile.java
===================================================================
--- projects/jboss-jca/trunk/codegenerator/src/main/java/org/jboss/jca/codegenerator/BaseProfile.java 2010-11-02 06:58:45 UTC (rev 109063)
+++ projects/jboss-jca/trunk/codegenerator/src/main/java/org/jboss/jca/codegenerator/BaseProfile.java 2010-11-02 08:09:17 UTC (rev 109064)
@@ -62,7 +62,8 @@
generateRaCode(def);
generateOutboundCode(def);
generateInboundCode(def);
-
+ generateMBeanCode(def);
+
generateTestCode(def);
if (def.getBuild().equals("ivy"))
@@ -130,30 +131,43 @@
{
if (def.isSupportInbound())
{
- generateClassCode(def, "Ml", true);
- generateClassCode(def, "As", true);
- generateClassCode(def, "Activation", true);
+ generateClassCode(def, "Ml", "inflow");
+ generateClassCode(def, "As", "inflow");
+ generateClassCode(def, "Activation", "inflow");
}
}
/**
+ * generate MBean code
+ *
+ * @param def Definition
+ */
+ void generateMBeanCode(Definition def)
+ {
+ if (def.isSupportOutbound())
+ {
+ generateClassCode(def, "MbeanInterface", "mbean");
+ generateClassCode(def, "MbeanImpl", "mbean");
+ }
+ }
+
+ /**
* generate class code
* @param def Definition
* @param className class name
*/
void generateClassCode(Definition def, String className)
{
- //by default inflow is false
- generateClassCode(def, className, false);
+ generateClassCode(def, className, null);
}
/**
* generate class code
* @param def Definition
* @param className class name
- * @param inflow inbound class put into sub-directory
+ * @param subDir sub-directory name
*/
- void generateClassCode(Definition def, String className, boolean inflow)
+ void generateClassCode(Definition def, String className, String subDir)
{
if (className == null || className.equals(""))
return;
@@ -164,10 +178,10 @@
String javaFile = (String)Definition.class.getMethod(
"get" + className + "Class").invoke(def, (Object[])null) + ".java";
FileWriter fw = null;
- if (!inflow)
+ if (subDir == null)
fw = Utils.createSrcFile(javaFile, def.getRaPackage(), def.getOutputDir());
else
- fw = Utils.createSrcFile(javaFile, def.getRaPackage() + ".inflow", def.getOutputDir());
+ fw = Utils.createSrcFile(javaFile, def.getRaPackage() + "." + subDir, def.getOutputDir());
Class<?> clazz = Class.forName(clazzName, true, Thread.currentThread().getContextClassLoader());
AbstractCodeGen codeGen = (AbstractCodeGen)clazz.newInstance();
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-11-02 06:58:45 UTC (rev 109063)
+++ projects/jboss-jca/trunk/codegenerator/src/main/java/org/jboss/jca/codegenerator/Definition.java 2010-11-02 08:09:17 UTC (rev 109064)
@@ -153,6 +153,13 @@
@XmlElement(name = "build")
private String build = "A";
+ /** MBean test interface */
+ @XmlElement(name = "MBeanInterface")
+ private String mbeanInterfaceClass = "TestMBean";
+ /** MBean test impl */
+ @XmlElement(name = "MBeanImpl")
+ private String mbeanImplClass = "Test";
+
/**
* Set the version.
*
@@ -946,5 +953,23 @@
{
return build;
}
-
+
+ /**
+ * Get the mbeanInterfaceClass.
+ *
+ * @return the mbeanInterfaceClass.
+ */
+ public String getMbeanInterfaceClass()
+ {
+ return mbeanInterfaceClass;
+ }
+ /**
+ * Get the mbeanImplClass.
+ *
+ * @return the mbeanImplClass.
+ */
+ public String getMbeanImplClass()
+ {
+ return mbeanImplClass;
+ }
}
Added: projects/jboss-jca/trunk/codegenerator/src/main/java/org/jboss/jca/codegenerator/code/MbeanImplCodeGen.java
===================================================================
--- projects/jboss-jca/trunk/codegenerator/src/main/java/org/jboss/jca/codegenerator/code/MbeanImplCodeGen.java (rev 0)
+++ projects/jboss-jca/trunk/codegenerator/src/main/java/org/jboss/jca/codegenerator/code/MbeanImplCodeGen.java 2010-11-02 08:09:17 UTC (rev 109064)
@@ -0,0 +1,203 @@
+/*
+ * 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.code;
+
+import org.jboss.jca.codegenerator.Definition;
+import org.jboss.jca.codegenerator.MethodForConnection;
+import org.jboss.jca.codegenerator.MethodParam;
+
+import java.io.IOException;
+import java.io.Writer;
+
+/**
+ * A mbean impl CodeGen.
+ *
+ * @author Jeff Zhang
+ * @version $Revision: $
+ */
+public class MbeanImplCodeGen 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 class " + getClassName(def) + " implements " + def.getMbeanInterfaceClass());
+ writeLeftCurlyBracket(out, 0);
+
+ writeIndent(out, indent);
+ out.write("private static final String JNDI_NAME = \"java:/eis/" + def.getDefaultValue() + "\";");
+ writeEol(out);
+ writeEol(out);
+
+ if (def.isDefineMethodInConnection())
+ {
+ if (def.getMethods().size() > 0)
+ {
+ for (MethodForConnection method : def.getMethods())
+ {
+ writeIndent(out, indent);
+ out.write("/**");
+ writeEol(out);
+ writeIndent(out, indent);
+ out.write(" * call " + method.getMethodName());
+ writeEol(out);
+ writeIndent(out, indent);
+ out.write(" */");
+ writeEol(out);
+
+ writeIndent(out, indent);
+ out.write("public " + method.getReturnType() + " " +
+ method.getMethodName() + "(");
+ int paramSize = method.getParams().size();
+ for (int i = 0; i < paramSize; i++)
+ {
+ MethodParam param = method.getParams().get(i);
+ out.write(param.getType());
+ out.write(" ");
+ out.write(param.getName());
+ if (i + 1 < paramSize)
+ out.write(", ");
+ }
+ out.write(") throws Exception");
+
+ writeLeftCurlyBracket(out, indent);
+ writeIndent(out, indent + 1);
+ if (!method.getReturnType().equals("void"))
+ {
+ out.write("return ");
+ }
+ out.write("getConnection()." + method.getMethodName() + "(");
+ for (int i = 0; i < paramSize; i++)
+ {
+ MethodParam param = method.getParams().get(i);
+ out.write(param.getName());
+ if (i + 1 < paramSize)
+ out.write(", ");
+ }
+ out.write(");");
+ writeEol(out);
+
+ writeRightCurlyBracket(out, indent);
+ }
+ }
+ }
+ else
+ {
+ writeIndent(out, indent);
+ out.write("/**");
+ writeEol(out);
+ writeIndent(out, indent);
+ out.write(" * call me");
+ writeEol(out);
+ writeIndent(out, indent);
+ out.write(" */");
+ writeEol(out);
+ writeIndent(out, indent);
+ out.write("@Override");
+ writeEol(out);
+ writeIndent(out, indent);
+ out.write("public void callMe() throws Exception");
+ writeLeftCurlyBracket(out, indent);
+ writeIndent(out, indent + 1);
+ out.write("getConnection().callMe();");
+
+ writeRightCurlyBracket(out, indent);
+ }
+
+ writeIndent(out, indent);
+ out.write("/**");
+ writeEol(out);
+ writeIndent(out, indent);
+ out.write(" * getConnection");
+ writeEol(out);
+ writeIndent(out, indent);
+ out.write(" */");
+ writeEol(out);
+ writeIndent(out, indent);
+ out.write("private " + def.getConnInterfaceClass() + " getConnection() throws Exception");
+ writeLeftCurlyBracket(out, indent);
+ writeIndent(out, indent + 1);
+
+ out.write("InitialContext context = new InitialContext();");
+ writeEol(out);
+ writeIndent(out, indent + 1);
+ out.write(def.getCfInterfaceClass() + " factory = (" + def.getCfInterfaceClass() +
+ ")context.lookup(JNDI_NAME);");
+ writeEol(out);
+ writeIndent(out, indent + 1);
+ out.write(def.getConnInterfaceClass() + " conn = factory.getConnection();");
+ writeEol(out);
+ writeIndent(out, indent + 1);
+ out.write("if (conn == null)");
+ writeLeftCurlyBracket(out, indent + 1);
+ writeIndent(out, indent + 2);
+ out.write("throw new RuntimeException(\"No connection\");");
+ writeRightCurlyBracket(out, indent + 1);
+
+ writeIndent(out, indent + 1);
+ out.write("return conn;");
+
+ writeRightCurlyBracket(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() + ".mbean;");
+ writeEol(out);
+ writeEol(out);
+ out.write("import javax.naming.InitialContext;");
+ writeEol(out);
+ writeEol(out);
+ out.write("import " + def.getRaPackage() + "." + def.getConnInterfaceClass() + ";");
+ writeEol(out);
+ out.write("import " + def.getRaPackage() + "." + def.getCfInterfaceClass() + ";");
+ writeEol(out);
+ writeEol(out);
+ }
+
+ /**
+ * get this class name
+ * @param def definition
+ * @return String class name
+ */
+ @Override
+ public String getClassName(Definition def)
+ {
+ return def.getMbeanImplClass();
+ }
+}
Added: projects/jboss-jca/trunk/codegenerator/src/main/java/org/jboss/jca/codegenerator/code/MbeanInterfaceCodeGen.java
===================================================================
--- projects/jboss-jca/trunk/codegenerator/src/main/java/org/jboss/jca/codegenerator/code/MbeanInterfaceCodeGen.java (rev 0)
+++ projects/jboss-jca/trunk/codegenerator/src/main/java/org/jboss/jca/codegenerator/code/MbeanInterfaceCodeGen.java 2010-11-02 08:09:17 UTC (rev 109064)
@@ -0,0 +1,147 @@
+/*
+ * 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.code;
+
+import org.jboss.jca.codegenerator.Definition;
+import org.jboss.jca.codegenerator.MethodForConnection;
+import org.jboss.jca.codegenerator.MethodParam;
+
+import java.io.IOException;
+import java.io.Writer;
+
+/**
+ * A MbeanInterface CodeGen.
+ *
+ * @author Jeff Zhang
+ * @version $Revision: $
+ */
+public class MbeanInterfaceCodeGen 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);
+
+ if (def.isDefineMethodInConnection())
+ {
+ if (def.getMethods().size() > 0)
+ {
+ for (MethodForConnection method : def.getMethods())
+ {
+ writeIndent(out, indent);
+ out.write("/**");
+ writeEol(out);
+ writeIndent(out, indent);
+ out.write(" * " + method.getMethodName());
+ writeEol(out);
+ for (MethodParam param : method.getParams())
+ {
+ writeIndent(out, indent);
+ out.write(" * @param " + param.getName() + " " + param.getName());
+ writeEol(out);
+ }
+ if (!method.getReturnType().equals("void"))
+ {
+ writeIndent(out, indent);
+ out.write(" * @return " + method.getReturnType());
+ writeEol(out);
+ }
+ writeIndent(out, indent);
+ out.write(" * @throws Exception");
+ writeEol(out);
+ writeIndent(out, indent);
+ out.write(" */");
+ writeEol(out);
+
+ writeIndent(out, indent);
+ out.write("public " + method.getReturnType() + " " +
+ method.getMethodName() + "(");
+ int paramSize = method.getParams().size();
+ for (int i = 0; i < paramSize; i++)
+ {
+ MethodParam param = method.getParams().get(i);
+ out.write(param.getType());
+ out.write(" ");
+ out.write(param.getName());
+ if (i + 1 < paramSize)
+ out.write(", ");
+ }
+ out.write(") throws Exception;");
+
+ writeEol(out);
+ writeEol(out);
+ }
+ }
+ }
+ else
+ {
+ writeIndent(out, indent);
+ out.write("/**");
+ writeEol(out);
+ writeIndent(out, indent);
+ out.write(" * call me");
+ writeEol(out);
+ writeIndent(out, indent);
+ out.write(" */");
+ writeEol(out);
+
+ writeIndent(out, indent);
+ out.write("public void callMe() throws Exception;");
+ }
+
+ 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() + ".mbean;");
+ writeEol(out);
+ writeEol(out);
+ }
+
+ /**
+ * get this class name
+ * @param def definition
+ * @return String class name
+ */
+ @Override
+ public String getClassName(Definition def)
+ {
+ return def.getMbeanInterfaceClass();
+ }
+}
More information about the jboss-cvs-commits
mailing list