[jboss-cvs] JBossAS SVN: r112723 - in projects/jboss-jca/tags: IRONJACAMAR_1_0_8_FINAL/codegenerator/src/main/java/org/jboss/jca/codegenerator and 4 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Fri Mar 2 08:22:23 EST 2012
Author: jesper.pedersen
Date: 2012-03-02 08:22:21 -0500 (Fri, 02 Mar 2012)
New Revision: 112723
Added:
projects/jboss-jca/tags/IRONJACAMAR_1_0_8_FINAL/
projects/jboss-jca/tags/IRONJACAMAR_1_0_8_FINAL/codegenerator/src/main/java/org/jboss/jca/codegenerator/BaseProfile.java
projects/jboss-jca/tags/IRONJACAMAR_1_0_8_FINAL/codegenerator/src/main/java/org/jboss/jca/codegenerator/Main.java
projects/jboss-jca/tags/IRONJACAMAR_1_0_8_FINAL/codegenerator/src/main/java/org/jboss/jca/codegenerator/code/AoImplCodeGen.java
projects/jboss-jca/tags/IRONJACAMAR_1_0_8_FINAL/codegenerator/src/main/java/org/jboss/jca/codegenerator/code/TestCodeGen.java
projects/jboss-jca/tags/IRONJACAMAR_1_0_8_FINAL/codegenerator/src/main/java/org/jboss/jca/codegenerator/xml/IronjacamarXmlGen.java
projects/jboss-jca/tags/IRONJACAMAR_1_0_8_FINAL/codegenerator/src/main/resources/header.template
projects/jboss-jca/tags/IRONJACAMAR_1_0_8_FINAL/codegenerator/src/main/resources/pom.xml.template
projects/jboss-jca/tags/IRONJACAMAR_1_0_8_FINAL/core/src/main/java/org/jboss/jca/core/rar/EndpointImpl.java
projects/jboss-jca/tags/IRONJACAMAR_1_0_8_FINAL/core/src/main/java/org/jboss/jca/core/rar/SecurityActions.java
Removed:
projects/jboss-jca/tags/IRONJACAMAR_1_0_8_FINAL/codegenerator/src/main/java/org/jboss/jca/codegenerator/BaseProfile.java
projects/jboss-jca/tags/IRONJACAMAR_1_0_8_FINAL/codegenerator/src/main/java/org/jboss/jca/codegenerator/Main.java
projects/jboss-jca/tags/IRONJACAMAR_1_0_8_FINAL/codegenerator/src/main/java/org/jboss/jca/codegenerator/code/AoImplCodeGen.java
projects/jboss-jca/tags/IRONJACAMAR_1_0_8_FINAL/codegenerator/src/main/java/org/jboss/jca/codegenerator/code/TestCodeGen.java
projects/jboss-jca/tags/IRONJACAMAR_1_0_8_FINAL/codegenerator/src/main/java/org/jboss/jca/codegenerator/xml/IronjacamarXmlGen.java
projects/jboss-jca/tags/IRONJACAMAR_1_0_8_FINAL/codegenerator/src/main/resources/header.template
projects/jboss-jca/tags/IRONJACAMAR_1_0_8_FINAL/codegenerator/src/main/resources/pom.xml.template
projects/jboss-jca/tags/IRONJACAMAR_1_0_8_FINAL/core/src/main/java/org/jboss/jca/core/rar/EndpointImpl.java
projects/jboss-jca/tags/IRONJACAMAR_1_0_8_FINAL/core/src/main/java/org/jboss/jca/core/rar/SecurityActions.java
Log:
IronJacamar 1.0.8
Deleted: projects/jboss-jca/tags/IRONJACAMAR_1_0_8_FINAL/codegenerator/src/main/java/org/jboss/jca/codegenerator/BaseProfile.java
===================================================================
--- projects/jboss-jca/branches/Branch_1_0/codegenerator/src/main/java/org/jboss/jca/codegenerator/BaseProfile.java 2012-02-24 20:13:12 UTC (rev 112694)
+++ projects/jboss-jca/tags/IRONJACAMAR_1_0_8_FINAL/codegenerator/src/main/java/org/jboss/jca/codegenerator/BaseProfile.java 2012-03-02 13:22:21 UTC (rev 112723)
@@ -1,561 +0,0 @@
-/*
- * 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 org.jboss.jca.codegenerator.code.AbstractCodeGen;
-import org.jboss.jca.codegenerator.code.AoImplCodeGen;
-import org.jboss.jca.codegenerator.code.AoInterfaceCodeGen;
-import org.jboss.jca.codegenerator.xml.BuildIvyXmlGen;
-import org.jboss.jca.codegenerator.xml.BuildXmlGen;
-import org.jboss.jca.codegenerator.xml.IronjacamarXmlGen;
-import org.jboss.jca.codegenerator.xml.IvySettingsXmlGen;
-import org.jboss.jca.codegenerator.xml.IvyXmlGen;
-import org.jboss.jca.codegenerator.xml.MbeanXmlGen;
-import org.jboss.jca.codegenerator.xml.PackageHtmlGen;
-import org.jboss.jca.codegenerator.xml.PomXmlGen;
-import org.jboss.jca.codegenerator.xml.RaXmlGen;
-
-import java.io.File;
-import java.io.FileWriter;
-import java.io.IOException;
-import java.net.URL;
-import java.util.Locale;
-
-/**
- * A BaseProfile.
- *
- * @author Jeff Zhang
- * @version $Revision: $
- */
-public class BaseProfile implements Profile
-{
-
- /**
- * BaseProfile
- */
- public BaseProfile()
- {
- }
-
-
- /**
- * generate code
- * @param def Definition
- */
- @Override
- public void generate(Definition def)
- {
- generatePackageHtml(def, def.getOutputDir(), null);
-
- generateRaCode(def);
- generateOutboundCode(def);
- generateInboundCode(def);
-
- generateTestCode(def);
-
- if (def.getBuild().equals("ivy"))
- generateAntIvyXml(def, def.getOutputDir());
- else if (def.getBuild().equals("maven"))
- generateMavenXml(def, def.getOutputDir());
- else
- generateAntXml(def, def.getOutputDir());
-
- generateRaXml(def, def.getOutputDir());
- if (def.isSupportOutbound())
- generateIronjacamarXml(def, def.getOutputDir());
-
- if (def.isGenMbean() &&
- def.isSupportOutbound() &&
- !def.getMcfDefs().get(0).isUseCciConnection())
- {
- generateMBeanCode(def);
- generateMbeanXml(def, def.getOutputDir());
- }
- }
-
- /**
- * generate resource adapter code
- *
- * @param def Definition
- */
- void generateRaCode(Definition def)
- {
- if (def.isUseRa())
- {
- generateClassCode(def, "Ra");
- generateClassCode(def, "RaMeta");
- }
- if (def.isGenAdminObject())
- {
- for (int i = 0; i < def.getAdminObjects().size(); i++)
- {
- generateMultiAdminObjectClassCode(def, "AoImpl", i);
- generateMultiAdminObjectClassCode(def, "AoInterface", i);
- }
- }
- }
-
- /**
- * generate outbound code
- *
- * @param def Definition
- */
- void generateOutboundCode(Definition def)
- {
- if (def.isSupportOutbound())
- {
- if (def.getMcfDefs() == null)
- throw new IllegalStateException("Should define at least one mcf class");
-
- for (int num = 0; num < def.getMcfDefs().size(); num++)
- {
- generateMultiMcfClassCode(def, "Mcf", num);
- generateMultiMcfClassCode(def, "Mc", num);
- generateMultiMcfClassCode(def, "McMeta", num);
-
- if (!def.getMcfDefs().get(num).isUseCciConnection())
- {
- generateMultiMcfClassCode(def, "CfInterface", num);
- generateMultiMcfClassCode(def, "Cf", num);
- generateMultiMcfClassCode(def, "ConnInterface", num);
- generateMultiMcfClassCode(def, "ConnImpl", num);
- }
- else
- {
- generateMultiMcfClassCode(def, "CciConn", num);
- generateMultiMcfClassCode(def, "CciConnFactory", num);
- generateMultiMcfClassCode(def, "ConnMeta", num);
- generateMultiMcfClassCode(def, "ConnSpec", num);
- }
- }
- }
- }
-
- /**
- * generate inbound code
- *
- * @param def Definition
- */
- void generateInboundCode(Definition def)
- {
- if (def.isSupportInbound())
- {
- if (def.isDefaultPackageInbound())
- generateClassCode(def, "Ml", "inflow");
- generateClassCode(def, "As", "inflow");
- generateClassCode(def, "Activation", "inflow");
- generatePackageHtml(def, def.getOutputDir(), "inflow");
- }
- }
-
- /**
- * generate MBean code
- *
- * @param def Definition
- */
- void generateMBeanCode(Definition def)
- {
- if (def.isSupportOutbound())
- {
- generateClassCode(def, "MbeanInterface", "mbean");
- generateClassCode(def, "MbeanImpl", "mbean");
- generatePackageHtml(def, def.getOutputDir(), "mbean");
- }
- }
-
- /**
- * generate class code
- * @param def Definition
- * @param className class name
- */
- void generateClassCode(Definition def, String className)
- {
- generateClassCode(def, className, null);
- }
-
- /**
- * generate class code
- * @param def Definition
- * @param className class name
- * @param subDir sub-directory name
- */
- void generateClassCode(Definition def, String className, String subDir)
- {
- if (className == null || className.equals(""))
- return;
-
- try
- {
- String clazzName = this.getClass().getPackage().getName() + ".code." + className + "CodeGen";
- String javaFile = (String)Definition.class.getMethod(
- "get" + className + "Class").invoke(def, (Object[])null) + ".java";
- FileWriter fw = null;
- if (subDir == null)
- fw = Utils.createSrcFile(javaFile, def.getRaPackage(), def.getOutputDir());
- else
- fw = Utils.createSrcFile(javaFile, def.getRaPackage() + "." + subDir, def.getOutputDir());
-
- Class<?> clazz = Class.forName(clazzName, true, Thread.currentThread().getContextClassLoader());
- AbstractCodeGen codeGen = (AbstractCodeGen)clazz.newInstance();
-
- codeGen.generate(def, fw);
-
- fw.flush();
- fw.close();
- }
- catch (IOException ioe)
- {
- ioe.printStackTrace();
- }
- catch (Exception e)
- {
- e.printStackTrace();
- }
- }
-
- /**
- * generate multi mcf class code
- * @param def Definition
- * @param className class name
- * @param num number of order
- */
- void generateMultiMcfClassCode(Definition def, String className, int num)
- {
- if (className == null || className.equals(""))
- return;
- if (num < 0 || num + 1 > def.getMcfDefs().size())
- return;
- try
- {
-
- String clazzName = this.getClass().getPackage().getName() + ".code." + className + "CodeGen";
-
- String javaFile = (String)McfDef.class.getMethod(
- "get" + className + "Class").invoke(def.getMcfDefs().get(num), (Object[])null) + ".java";
- FileWriter fw = null;
- fw = Utils.createSrcFile(javaFile, def.getRaPackage(), def.getOutputDir());
-
- Class<?> clazz = Class.forName(clazzName, true, Thread.currentThread().getContextClassLoader());
- AbstractCodeGen codeGen = (AbstractCodeGen)clazz.newInstance();
- codeGen.setNumOfMcf(num);
-
- codeGen.generate(def, fw);
-
- fw.flush();
- fw.close();
- }
- catch (IOException ioe)
- {
- ioe.printStackTrace();
- }
- catch (Exception e)
- {
- e.printStackTrace();
- }
- }
-
- /**
- * generate multi admin object class code
- * @param def Definition
- * @param className class name
- * @param num number of order
- */
- void generateMultiAdminObjectClassCode(Definition def, String className, int num)
- {
- if (className == null || className.equals(""))
- return;
-
- try
- {
- String clazzName = this.getClass().getPackage().getName() + ".code." + className + "CodeGen";
-
- Class<?> clazz = Class.forName(clazzName, true, Thread.currentThread().getContextClassLoader());
- AbstractCodeGen codeGen = (AbstractCodeGen)clazz.newInstance();
-
- String javaFile = "";
- if (codeGen instanceof AoImplCodeGen)
- {
- ((AoImplCodeGen)codeGen).setNumOfAo(num);
- javaFile = def.getAdminObjects().get(num).getAdminObjectClass() + ".java";
- }
- else if (codeGen instanceof AoInterfaceCodeGen)
- {
- ((AoInterfaceCodeGen)codeGen).setNumOfAo(num);
- javaFile = def.getAdminObjects().get(num).getAdminObjectInterface() + ".java";
- }
-
- FileWriter fw = Utils.createSrcFile(javaFile, def.getRaPackage(), def.getOutputDir());
- codeGen.generate(def, fw);
-
- fw.flush();
- fw.close();
- }
- catch (IOException ioe)
- {
- ioe.printStackTrace();
- }
- catch (Exception e)
- {
- e.printStackTrace();
- }
- }
-
- /**
- * generate ant build.xml
- * @param def Definition
- * @param outputDir output directory
- */
- void generateAntXml(Definition def, String outputDir)
- {
- try
- {
- FileWriter antfw = Utils.createFile("build.xml", outputDir);
- BuildXmlGen bxGen = new BuildXmlGen();
- bxGen.generate(def, antfw);
- antfw.close();
- }
- catch (IOException ioe)
- {
- ioe.printStackTrace();
- }
- }
-
- /**
- * generate ant + ivy build.xml and ivy files
- * @param def Definition
- * @param outputDir output directory
- */
- void generateAntIvyXml(Definition def, String outputDir)
- {
- try
- {
- FileWriter antfw = Utils.createFile("build.xml", outputDir);
- BuildIvyXmlGen bxGen = new BuildIvyXmlGen();
- bxGen.generate(def, antfw);
- antfw.close();
-
- FileWriter ivyfw = Utils.createFile("ivy.xml", outputDir);
- IvyXmlGen ixGen = new IvyXmlGen();
- ixGen.generate(def, ivyfw);
- ivyfw.close();
-
- FileWriter ivySettingsfw = Utils.createFile("ivy.settings.xml", outputDir);
- IvySettingsXmlGen isxGen = new IvySettingsXmlGen();
- isxGen.generate(def, ivySettingsfw);
- ivySettingsfw.close();
- }
- catch (IOException ioe)
- {
- ioe.printStackTrace();
- }
- }
-
- /**
- * generate ant build.xml
- * @param def Definition
- * @param outputDir output directory
- */
- void generateMavenXml(Definition def, String outputDir)
- {
- try
- {
- FileWriter pomfw = Utils.createFile("pom.xml", outputDir);
- PomXmlGen pxGen = new PomXmlGen();
- pxGen.generate(def, pomfw);
- pomfw.close();
- }
- catch (IOException ioe)
- {
- ioe.printStackTrace();
- }
- }
-
- /**
- * generate ra.xml
- * @param def Definition
- * @param outputDir output directory
- */
- void generateRaXml(Definition def, String outputDir)
- {
- if (!def.isUseAnnotation())
- {
- try
- {
- outputDir = outputDir + File.separatorChar + "src" + File.separatorChar +
- "main" + File.separatorChar + "resources";
- FileWriter rafw = Utils.createFile("ra.xml", outputDir + File.separatorChar + "META-INF");
- RaXmlGen raGen = getRaXmlGen(def);
- raGen.generate(def, rafw);
- rafw.close();
- }
- catch (IOException ioe)
- {
- ioe.printStackTrace();
- }
- }
- }
-
- /**
- * get right profile ra xmlGen
- * @param def Definition
- * @return RaXmlGen profile ra xmlGen
- */
- RaXmlGen getRaXmlGen(Definition def)
- {
- return null;
- }
-
- /**
- * generate ant ironjacamar.xml
- * @param def Definition
- * @param outputDir output directory
- */
- void generateIronjacamarXml(Definition def, String outputDir)
- {
- try
- {
- outputDir = outputDir + File.separatorChar + "src" + File.separatorChar +
- "main" + File.separatorChar + "resources";
- FileWriter ijfw = Utils.createFile("ironjacamar.xml", outputDir + File.separatorChar + "META-INF");
- IronjacamarXmlGen ijxGen = new IronjacamarXmlGen();
- ijxGen.generate(def, ijfw);
- ijfw.close();
- }
- catch (IOException ioe)
- {
- ioe.printStackTrace();
- }
- }
-
- /**
- * generate mbean deployment xml
- * @param def Definition
- * @param outputDir output directory
- */
- void generateMbeanXml(Definition def, String outputDir)
- {
- String mbeanName = def.getDefaultValue().toLowerCase(Locale.US);
- if (def.getRaPackage() != null && !def.getRaPackage().equals(""))
- {
- if (def.getRaPackage().indexOf('.') >= 0)
- {
- mbeanName = def.getRaPackage().substring(def.getRaPackage().lastIndexOf('.') + 1);
- }
- else
- mbeanName = def.getRaPackage();
- }
-
- try
- {
- outputDir = outputDir + File.separatorChar + "src" + File.separatorChar +
- "main" + File.separatorChar + "resources";
- FileWriter mbfw = Utils.createFile(mbeanName + ".xml", outputDir);
- MbeanXmlGen mbGen = new MbeanXmlGen();
- mbGen.generate(def, mbfw);
- mbfw.close();
- }
- catch (IOException ioe)
- {
- ioe.printStackTrace();
- }
- }
-
- /**
- * generate package.html
- * @param def Definition
- * @param outputDir output directory
- * @param subDir sub-directory
- */
- void generatePackageHtml(Definition def, String outputDir, String subDir)
- {
- try
- {
- FileWriter fw = null;
- if (subDir == null)
- fw = Utils.createSrcFile("package.html", def.getRaPackage(), def.getOutputDir());
- else
- fw = Utils.createSrcFile("package.html", def.getRaPackage() + "." + subDir, def.getOutputDir());
- PackageHtmlGen phGen = new PackageHtmlGen();
- phGen.generate(def, fw);
- fw.close();
- }
- catch (IOException ioe)
- {
- ioe.printStackTrace();
- }
- }
-
- /**
- * generate test code
- *
- * @param def Definition
- */
- void generateTestCode(Definition def)
- {
- if (!def.isSupportOutbound())
- return;
-
- try
- {
- String clazzName = this.getClass().getPackage().getName() + ".code.TestCodeGen";
- String javaFile = "ConnectorTestCase.java";
- FileWriter fw = Utils.createTestFile(javaFile, def.getRaPackage(), def.getOutputDir());
-
- Class<?> clazz = Class.forName(clazzName, true, Thread.currentThread().getContextClassLoader());
- AbstractCodeGen codeGen = (AbstractCodeGen)clazz.newInstance();
-
- codeGen.generate(def, fw);
-
- fw.flush();
- fw.close();
-
- copyTestResourceFiles(def.getOutputDir(), "logging.properties");
- copyTestResourceFiles(def.getOutputDir(), "jndi.properties");
- }
- catch (IOException ioe)
- {
- ioe.printStackTrace();
- }
- catch (Exception e)
- {
- e.printStackTrace();
- }
- }
-
- /**
- * copy some test resource files
- *
- * @param outputDir output directory
- * @param filename filename
- * @throws IOException ioException
- */
- private void copyTestResourceFiles(String outputDir, String filename) throws IOException
- {
- String testResourceDir = outputDir + "/src/test/resources";
- FileWriter fw = Utils.createFile(filename, testResourceDir);
- URL buildFile = BaseProfile.class.getResource("/" + filename + ".template");
- String buildString = Utils.readFileIntoString(buildFile);
- fw.write(buildString);
- fw.close();
- }
-
-}
Copied: projects/jboss-jca/tags/IRONJACAMAR_1_0_8_FINAL/codegenerator/src/main/java/org/jboss/jca/codegenerator/BaseProfile.java (from rev 112698, projects/jboss-jca/branches/Branch_1_0/codegenerator/src/main/java/org/jboss/jca/codegenerator/BaseProfile.java)
===================================================================
--- projects/jboss-jca/tags/IRONJACAMAR_1_0_8_FINAL/codegenerator/src/main/java/org/jboss/jca/codegenerator/BaseProfile.java (rev 0)
+++ projects/jboss-jca/tags/IRONJACAMAR_1_0_8_FINAL/codegenerator/src/main/java/org/jboss/jca/codegenerator/BaseProfile.java 2012-03-02 13:22:21 UTC (rev 112723)
@@ -0,0 +1,580 @@
+/*
+ * 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 org.jboss.jca.codegenerator.code.AbstractCodeGen;
+import org.jboss.jca.codegenerator.code.AoImplCodeGen;
+import org.jboss.jca.codegenerator.code.AoInterfaceCodeGen;
+import org.jboss.jca.codegenerator.xml.BuildIvyXmlGen;
+import org.jboss.jca.codegenerator.xml.BuildXmlGen;
+import org.jboss.jca.codegenerator.xml.IronjacamarXmlGen;
+import org.jboss.jca.codegenerator.xml.IvySettingsXmlGen;
+import org.jboss.jca.codegenerator.xml.IvyXmlGen;
+import org.jboss.jca.codegenerator.xml.MbeanXmlGen;
+import org.jboss.jca.codegenerator.xml.PackageHtmlGen;
+import org.jboss.jca.codegenerator.xml.PomXmlGen;
+import org.jboss.jca.codegenerator.xml.RaXmlGen;
+
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.net.URL;
+import java.util.Locale;
+
+/**
+ * A BaseProfile.
+ *
+ * @author Jeff Zhang
+ * @version $Revision: $
+ */
+public class BaseProfile implements Profile
+{
+
+ /**
+ * BaseProfile
+ */
+ public BaseProfile()
+ {
+ }
+
+
+ /**
+ * generate code
+ * @param def Definition
+ */
+ @Override
+ public void generate(Definition def)
+ {
+ generatePackageHtml(def, def.getOutputDir(), null);
+
+ generateRaCode(def);
+ generateOutboundCode(def);
+ generateInboundCode(def);
+
+ generateTestCode(def);
+
+ if (def.getBuild().equals("ivy"))
+ generateAntIvyXml(def, def.getOutputDir());
+ else if (def.getBuild().equals("maven"))
+ generateMavenXml(def, def.getOutputDir());
+ else
+ generateAntXml(def, def.getOutputDir());
+
+ generateRaXml(def, def.getOutputDir());
+ if (def.isSupportOutbound())
+ generateIronjacamarXml(def, def.getOutputDir());
+
+ if (def.isGenMbean() &&
+ def.isSupportOutbound() &&
+ !def.getMcfDefs().get(0).isUseCciConnection())
+ {
+ generateMBeanCode(def);
+ generateMbeanXml(def, def.getOutputDir());
+ }
+ }
+
+ /**
+ * generate resource adapter code
+ *
+ * @param def Definition
+ */
+ void generateRaCode(Definition def)
+ {
+ if (def.isUseRa())
+ {
+ generateClassCode(def, "Ra");
+ generateClassCode(def, "RaMeta");
+ }
+ if (def.isGenAdminObject())
+ {
+ for (int i = 0; i < def.getAdminObjects().size(); i++)
+ {
+ generateMultiAdminObjectClassCode(def, "AoImpl", i);
+ generateMultiAdminObjectClassCode(def, "AoInterface", i);
+ }
+ }
+ }
+
+ /**
+ * generate outbound code
+ *
+ * @param def Definition
+ */
+ void generateOutboundCode(Definition def)
+ {
+ if (def.isSupportOutbound())
+ {
+ if (def.getMcfDefs() == null)
+ throw new IllegalStateException("Should define at least one mcf class");
+
+ for (int num = 0; num < def.getMcfDefs().size(); num++)
+ {
+ generateMultiMcfClassCode(def, "Mcf", num);
+ generateMultiMcfClassCode(def, "Mc", num);
+ generateMultiMcfClassCode(def, "McMeta", num);
+
+ if (!def.getMcfDefs().get(num).isUseCciConnection())
+ {
+ generateMultiMcfClassCode(def, "CfInterface", num);
+ generateMultiMcfClassCode(def, "Cf", num);
+ generateMultiMcfClassCode(def, "ConnInterface", num);
+ generateMultiMcfClassCode(def, "ConnImpl", num);
+ }
+ else
+ {
+ generateMultiMcfClassCode(def, "CciConn", num);
+ generateMultiMcfClassCode(def, "CciConnFactory", num);
+ generateMultiMcfClassCode(def, "ConnMeta", num);
+ generateMultiMcfClassCode(def, "ConnSpec", num);
+ }
+ }
+ }
+ }
+
+ /**
+ * generate inbound code
+ *
+ * @param def Definition
+ */
+ void generateInboundCode(Definition def)
+ {
+ if (def.isSupportInbound())
+ {
+ if (def.isDefaultPackageInbound())
+ generateClassCode(def, "Ml", "inflow");
+ generateClassCode(def, "As", "inflow");
+ generateClassCode(def, "Activation", "inflow");
+ generatePackageHtml(def, def.getOutputDir(), "inflow");
+ }
+ }
+
+ /**
+ * generate MBean code
+ *
+ * @param def Definition
+ */
+ void generateMBeanCode(Definition def)
+ {
+ if (def.isSupportOutbound())
+ {
+ generateClassCode(def, "MbeanInterface", "mbean");
+ generateClassCode(def, "MbeanImpl", "mbean");
+ generatePackageHtml(def, def.getOutputDir(), "mbean");
+ }
+ }
+
+ /**
+ * generate class code
+ * @param def Definition
+ * @param className class name
+ */
+ void generateClassCode(Definition def, String className)
+ {
+ generateClassCode(def, className, null);
+ }
+
+ /**
+ * generate class code
+ * @param def Definition
+ * @param className class name
+ * @param subDir sub-directory name
+ */
+ void generateClassCode(Definition def, String className, String subDir)
+ {
+ if (className == null || className.equals(""))
+ return;
+
+ try
+ {
+ String clazzName = this.getClass().getPackage().getName() + ".code." + className + "CodeGen";
+ String javaFile = (String)Definition.class.getMethod(
+ "get" + className + "Class").invoke(def, (Object[])null) + ".java";
+ FileWriter fw = null;
+ if (subDir == null)
+ fw = Utils.createSrcFile(javaFile, def.getRaPackage(), def.getOutputDir());
+ else
+ fw = Utils.createSrcFile(javaFile, def.getRaPackage() + "." + subDir, def.getOutputDir());
+
+ Class<?> clazz = Class.forName(clazzName, true, Thread.currentThread().getContextClassLoader());
+ AbstractCodeGen codeGen = (AbstractCodeGen)clazz.newInstance();
+
+ codeGen.generate(def, fw);
+
+ fw.flush();
+ fw.close();
+ }
+ catch (IOException ioe)
+ {
+ ioe.printStackTrace();
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ }
+
+ /**
+ * generate multi mcf class code
+ * @param def Definition
+ * @param className class name
+ * @param num number of order
+ */
+ void generateMultiMcfClassCode(Definition def, String className, int num)
+ {
+ if (className == null || className.equals(""))
+ return;
+ if (num < 0 || num + 1 > def.getMcfDefs().size())
+ return;
+ try
+ {
+
+ String clazzName = this.getClass().getPackage().getName() + ".code." + className + "CodeGen";
+
+ String javaFile = (String)McfDef.class.getMethod(
+ "get" + className + "Class").invoke(def.getMcfDefs().get(num), (Object[])null) + ".java";
+ FileWriter fw = null;
+ fw = Utils.createSrcFile(javaFile, def.getRaPackage(), def.getOutputDir());
+
+ Class<?> clazz = Class.forName(clazzName, true, Thread.currentThread().getContextClassLoader());
+ AbstractCodeGen codeGen = (AbstractCodeGen)clazz.newInstance();
+ codeGen.setNumOfMcf(num);
+
+ codeGen.generate(def, fw);
+
+ fw.flush();
+ fw.close();
+ }
+ catch (IOException ioe)
+ {
+ ioe.printStackTrace();
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ }
+
+ /**
+ * generate multi admin object class code
+ * @param def Definition
+ * @param className class name
+ * @param num number of order
+ */
+ void generateMultiAdminObjectClassCode(Definition def, String className, int num)
+ {
+ if (className == null || className.equals(""))
+ return;
+
+ try
+ {
+ String clazzName = this.getClass().getPackage().getName() + ".code." + className + "CodeGen";
+
+ Class<?> clazz = Class.forName(clazzName, true, Thread.currentThread().getContextClassLoader());
+ AbstractCodeGen codeGen = (AbstractCodeGen)clazz.newInstance();
+
+ String javaFile = "";
+ if (codeGen instanceof AoImplCodeGen)
+ {
+ ((AoImplCodeGen)codeGen).setNumOfAo(num);
+ javaFile = def.getAdminObjects().get(num).getAdminObjectClass() + ".java";
+ }
+ else if (codeGen instanceof AoInterfaceCodeGen)
+ {
+ ((AoInterfaceCodeGen)codeGen).setNumOfAo(num);
+ javaFile = def.getAdminObjects().get(num).getAdminObjectInterface() + ".java";
+ }
+
+ FileWriter fw = Utils.createSrcFile(javaFile, def.getRaPackage(), def.getOutputDir());
+ codeGen.generate(def, fw);
+
+ fw.flush();
+ fw.close();
+ }
+ catch (IOException ioe)
+ {
+ ioe.printStackTrace();
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ }
+
+ /**
+ * generate ant build.xml
+ * @param def Definition
+ * @param outputDir output directory
+ */
+ void generateAntXml(Definition def, String outputDir)
+ {
+ try
+ {
+ FileWriter antfw = Utils.createFile("build.xml", outputDir);
+ BuildXmlGen bxGen = new BuildXmlGen();
+ bxGen.generate(def, antfw);
+ antfw.close();
+ }
+ catch (IOException ioe)
+ {
+ ioe.printStackTrace();
+ }
+ }
+
+ /**
+ * generate ant + ivy build.xml and ivy files
+ * @param def Definition
+ * @param outputDir output directory
+ */
+ void generateAntIvyXml(Definition def, String outputDir)
+ {
+ try
+ {
+ FileWriter antfw = Utils.createFile("build.xml", outputDir);
+ BuildIvyXmlGen bxGen = new BuildIvyXmlGen();
+ bxGen.generate(def, antfw);
+ antfw.close();
+
+ FileWriter ivyfw = Utils.createFile("ivy.xml", outputDir);
+ IvyXmlGen ixGen = new IvyXmlGen();
+ ixGen.generate(def, ivyfw);
+ ivyfw.close();
+
+ FileWriter ivySettingsfw = Utils.createFile("ivy.settings.xml", outputDir);
+ IvySettingsXmlGen isxGen = new IvySettingsXmlGen();
+ isxGen.generate(def, ivySettingsfw);
+ ivySettingsfw.close();
+ }
+ catch (IOException ioe)
+ {
+ ioe.printStackTrace();
+ }
+ }
+
+ /**
+ * generate ant build.xml
+ * @param def Definition
+ * @param outputDir output directory
+ */
+ void generateMavenXml(Definition def, String outputDir)
+ {
+ try
+ {
+ FileWriter pomfw = Utils.createFile("pom.xml", outputDir);
+ PomXmlGen pxGen = new PomXmlGen();
+ pxGen.generate(def, pomfw);
+ pomfw.close();
+ }
+ catch (IOException ioe)
+ {
+ ioe.printStackTrace();
+ }
+ }
+
+ /**
+ * generate ra.xml
+ * @param def Definition
+ * @param outputDir output directory
+ */
+ void generateRaXml(Definition def, String outputDir)
+ {
+ if (!def.isUseAnnotation())
+ {
+ try
+ {
+ outputDir = outputDir + File.separatorChar + "src" + File.separatorChar +
+ "main" + File.separatorChar + "resources";
+ FileWriter rafw = Utils.createFile("ra.xml", outputDir + File.separatorChar + "META-INF");
+ RaXmlGen raGen = getRaXmlGen(def);
+ raGen.generate(def, rafw);
+ rafw.close();
+ }
+ catch (IOException ioe)
+ {
+ ioe.printStackTrace();
+ }
+ }
+ }
+
+ /**
+ * get right profile ra xmlGen
+ * @param def Definition
+ * @return RaXmlGen profile ra xmlGen
+ */
+ RaXmlGen getRaXmlGen(Definition def)
+ {
+ return null;
+ }
+
+ /**
+ * generate ant ironjacamar.xml
+ * @param def Definition
+ * @param outputDir output directory
+ */
+ void generateIronjacamarXml(Definition def, String outputDir)
+ {
+ try
+ {
+ String resourceDir = outputDir + File.separatorChar + "src" + File.separatorChar +
+ "main" + File.separatorChar + "resources";
+ writeIronjacamarXml(def, resourceDir);
+
+ if (def.getBuild().equals("maven"))
+ {
+ String rarDir = outputDir + File.separatorChar + "src" + File.separatorChar +
+ "main" + File.separatorChar + "rar";
+ writeIronjacamarXml(def, rarDir);
+ }
+ }
+ catch (IOException ioe)
+ {
+ ioe.printStackTrace();
+ }
+ }
+
+
+ /**
+ * writeIronjacamarXml
+ * @param def Definition
+ * @param outputDir output directory
+ * @throws IOException output exception
+ */
+ private void writeIronjacamarXml(Definition def, String outputDir) throws IOException
+ {
+ FileWriter ijfw = Utils.createFile("ironjacamar.xml", outputDir + File.separatorChar + "META-INF");
+ IronjacamarXmlGen ijxGen = new IronjacamarXmlGen();
+ ijxGen.generate(def, ijfw);
+ ijfw.close();
+ }
+
+ /**
+ * generate mbean deployment xml
+ * @param def Definition
+ * @param outputDir output directory
+ */
+ void generateMbeanXml(Definition def, String outputDir)
+ {
+ String mbeanName = def.getDefaultValue().toLowerCase(Locale.US);
+ if (def.getRaPackage() != null && !def.getRaPackage().equals(""))
+ {
+ if (def.getRaPackage().indexOf('.') >= 0)
+ {
+ mbeanName = def.getRaPackage().substring(def.getRaPackage().lastIndexOf('.') + 1);
+ }
+ else
+ mbeanName = def.getRaPackage();
+ }
+
+ try
+ {
+ outputDir = outputDir + File.separatorChar + "src" + File.separatorChar +
+ "main" + File.separatorChar + "resources";
+ FileWriter mbfw = Utils.createFile(mbeanName + ".xml", outputDir);
+ MbeanXmlGen mbGen = new MbeanXmlGen();
+ mbGen.generate(def, mbfw);
+ mbfw.close();
+ }
+ catch (IOException ioe)
+ {
+ ioe.printStackTrace();
+ }
+ }
+
+ /**
+ * generate package.html
+ * @param def Definition
+ * @param outputDir output directory
+ * @param subDir sub-directory
+ */
+ void generatePackageHtml(Definition def, String outputDir, String subDir)
+ {
+ try
+ {
+ FileWriter fw = null;
+ if (subDir == null)
+ fw = Utils.createSrcFile("package.html", def.getRaPackage(), def.getOutputDir());
+ else
+ fw = Utils.createSrcFile("package.html", def.getRaPackage() + "." + subDir, def.getOutputDir());
+ PackageHtmlGen phGen = new PackageHtmlGen();
+ phGen.generate(def, fw);
+ fw.close();
+ }
+ catch (IOException ioe)
+ {
+ ioe.printStackTrace();
+ }
+ }
+
+ /**
+ * generate test code
+ *
+ * @param def Definition
+ */
+ void generateTestCode(Definition def)
+ {
+ if (!def.isSupportOutbound())
+ return;
+
+ try
+ {
+ String clazzName = this.getClass().getPackage().getName() + ".code.TestCodeGen";
+ String javaFile = "ConnectorTestCase.java";
+ FileWriter fw = Utils.createTestFile(javaFile, def.getRaPackage(), def.getOutputDir());
+
+ Class<?> clazz = Class.forName(clazzName, true, Thread.currentThread().getContextClassLoader());
+ AbstractCodeGen codeGen = (AbstractCodeGen)clazz.newInstance();
+
+ codeGen.generate(def, fw);
+
+ fw.flush();
+ fw.close();
+
+ copyTestResourceFiles(def.getOutputDir(), "logging.properties");
+ copyTestResourceFiles(def.getOutputDir(), "jndi.properties");
+ }
+ catch (IOException ioe)
+ {
+ ioe.printStackTrace();
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ }
+
+ /**
+ * copy some test resource files
+ *
+ * @param outputDir output directory
+ * @param filename filename
+ * @throws IOException ioException
+ */
+ private void copyTestResourceFiles(String outputDir, String filename) throws IOException
+ {
+ String testResourceDir = outputDir + "/src/test/resources";
+ FileWriter fw = Utils.createFile(filename, testResourceDir);
+ URL buildFile = BaseProfile.class.getResource("/" + filename + ".template");
+ String buildString = Utils.readFileIntoString(buildFile);
+ fw.write(buildString);
+ fw.close();
+ }
+
+}
Deleted: projects/jboss-jca/tags/IRONJACAMAR_1_0_8_FINAL/codegenerator/src/main/java/org/jboss/jca/codegenerator/Main.java
===================================================================
--- projects/jboss-jca/branches/Branch_1_0/codegenerator/src/main/java/org/jboss/jca/codegenerator/Main.java 2012-02-24 20:13:12 UTC (rev 112694)
+++ projects/jboss-jca/tags/IRONJACAMAR_1_0_8_FINAL/codegenerator/src/main/java/org/jboss/jca/codegenerator/Main.java 2012-03-02 13:22:21 UTC (rev 112723)
@@ -1,741 +0,0 @@
-/*
- * 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.BufferedReader;
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStreamReader;
-import java.util.ArrayList;
-import java.util.List;
-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
- *
- * @author Jeff Zhang
- * @version $Revision: $
- */
-public class Main
-{
- private static final int SUCCESS = 0;
- private static final int ERROR = 1;
- private static final int OTHER = 2;
-
- /** ResourceBundle */
- private static ResourceBundle rb = ResourceBundle.getBundle("codegenerator", Locale.getDefault());
-
- /**
- * Code generator stand alone tool
- *
- * @param args command line arguments
- */
- public static void main(String[] args)
- {
- String outputDir = "out"; //default output directory
- String defxml = null;
- int arg = 0;
-
- if (args.length > 0)
- {
- while (args.length > arg + 1)
- {
- if (args[arg].startsWith("-"))
- {
- if (args[arg].equals("-o"))
- {
- arg++;
- if (arg >= args.length)
- {
- usage();
- System.exit(OTHER);
- }
- outputDir = args[arg];
- }
- else if (args[arg].equals("-f"))
- {
- arg++;
- if (arg >= args.length)
- {
- usage();
- System.exit(OTHER);
- }
- defxml = args[arg];
- }
- }
- else
- {
- usage();
- System.exit(OTHER);
- }
- arg++;
- }
- }
- try
- {
- File out = new File(outputDir);
- Utils.recursiveDelete(out);
-
- 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);
-
- if (def.getBuild().equals("ant"))
- 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
- *
- * @throws IOException ioException
- * @return Definition definition from input
- */
- private static Definition inputFromCommandLine() throws IOException
- {
- BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
- Definition def = new Definition();
-
- //profile version
- String version = null;
- do
- {
- System.out.print(rb.getString("profile.version") + "[1.6]: ");
- version = in.readLine();
- if (version == null || version.equals(""))
- version = "1.6";
- }
- while (!(version.equals("1.6") || version.equals("1.5") || version.equals("1.0")));
- def.setVersion(version);
-
- //by default, support outbound, but not inbound
- def.setSupportOutbound(true);
- def.setSupportInbound(false);
-
- //bound
- if (!version.equals("1.0"))
- {
- System.out.print(rb.getString("support.bound") + "[O]: ");
- String bound = in.readLine();
- if (bound == null || bound.equals("") || bound.equals("O") || bound.equals("o") || bound.equals("Outbound"))
- {
- //keep default bound
- }
- else if (bound.equals("I") || bound.equals("i") || bound.equals("Inbound"))
- {
- def.setSupportOutbound(false);
- def.setSupportInbound(true);
- }
- else if (bound.equals("B") || bound.equals("b") || bound.equals("Bidirectional"))
- {
- def.setSupportOutbound(true);
- def.setSupportInbound(true);
- }
- }
-
- //package name
- System.out.print(rb.getString("package.name"));
- String packageName = in.readLine();
- def.setRaPackage(packageName);
-
- //transaction
- if (def.isSupportOutbound())
- {
- System.out.print(rb.getString("support.transaction") + "[N]: ");
- String trans = in.readLine();
- if (trans == null || trans.equals(""))
- def.setSupportTransaction("NoTransaction");
- else if (trans.equals("L") || trans.equals("l") || trans.equals("LocalTransaction"))
- {
- def.setSupportTransaction("LocalTransaction");
- }
- else if (trans.equals("X") || trans.equals("x") || trans.equals("XATransaction"))
- {
- def.setSupportTransaction("XATransaction");
- }
- else
- {
- def.setSupportTransaction("NoTransaction");
- }
- }
-
- //reauthentication
- if (def.isSupportOutbound() && !version.equals("1.0"))
- {
- System.out.print(rb.getString("support.reauthentication") + "[N]: ");
- String reauth = in.readLine();
- if (reauth == null || reauth.equals(""))
- def.setSupportReauthen(false);
- else if (reauth.equals("Y") || reauth.equals("y") || reauth.equals("Yes"))
- {
- def.setSupportReauthen(true);
- }
- else
- {
- def.setSupportReauthen(false);
- }
- }
-
- //support annotation
- if (version.equals("1.6"))
- {
- System.out.print(rb.getString("use.annotation") + "[Y]: ");
- String useAnnotation = in.readLine();
- if (useAnnotation == null)
- def.setUseAnnotation(true);
- else
- {
- if (useAnnotation.equals("N") || useAnnotation.equals("n") || useAnnotation.equals("No"))
- def.setUseAnnotation(false);
- else
- def.setUseAnnotation(true);
- }
- }
- else
- {
- def.setUseAnnotation(false);
- }
-
- //use resource adapter
- if (def.isSupportOutbound() && !def.isSupportInbound() && (version.equals("1.6") || version.equals("1.5")))
- {
- System.out.print(rb.getString("use.ra") + "[Y]: ");
- String useRa = in.readLine();
- if (useRa == null)
- def.setUseRa(true);
- else
- {
- if (useRa.equals("N") || useRa.equals("n") || useRa.equals("No"))
- def.setUseRa(false);
- else
- def.setUseRa(true);
- }
- }
- else if (version.equals("1.0"))
- {
- def.setUseRa(false);
- }
- else
- {
- def.setUseRa(true);
- }
-
- //input ra class name
- if (def.isUseRa() || def.isSupportInbound())
- {
- System.out.print(rb.getString("ra.class.name"));
- System.out.print("[" + def.getRaClass() + "]: ");
- String raClassName = in.readLine();
- if (raClassName != null && !raClassName.equals(""))
- {
- def.setRaClass(raClassName);
- setDefaultValue(def, raClassName, "ResourceAdapter");
- setDefaultValue(def, raClassName, "Ra");
- }
-
- List<ConfigPropType> raProps = inputProperties("ra", in, false);
- def.setRaConfigProps(raProps);
- }
-
- //outbound
- if (def.isSupportOutbound())
- {
- List<McfDef> mcfDefs = new ArrayList<McfDef>();
- def.setMcfDefs(mcfDefs);
- int mcfID = 1;
- boolean moreMcf;
- do
- {
- McfDef mcfdef = new McfDef(mcfID, def);
-
- System.out.print(rb.getString("mcf.class.name"));
- System.out.print("[" + mcfdef.getMcfClass() + "]: ");
- String mcfClassName = in.readLine();
- if (mcfClassName != null && !mcfClassName.equals(""))
- {
- mcfdef.setMcfClass(mcfClassName);
- setDefaultValue(def, mcfClassName, mcfID + "ManagedConnectionfactory");
- setDefaultValue(def, mcfClassName, mcfID + "Mcf");
- }
-
- List<ConfigPropType> mcfProps = inputProperties("mcf", in, false);
- mcfdef.setMcfConfigProps(mcfProps);
-
- if (def.isUseRa())
- {
- System.out.print(rb.getString("mcf.impl.raa") + "[Y]: ");
- String raAssociation = in.readLine();
- if (raAssociation == null || raAssociation.equals(""))
- mcfdef.setImplRaAssociation(true);
- else
- {
- if (raAssociation.equals("Y") || raAssociation.equals("y") || raAssociation.equals("Yes"))
- mcfdef.setImplRaAssociation(true);
- else
- mcfdef.setImplRaAssociation(false);
- }
- }
-
- System.out.print(rb.getString("mc.class.name"));
- System.out.print("[" + mcfdef.getMcClass() + "]: ");
- String mcClassName = in.readLine();
- if (mcClassName != null && !mcClassName.equals(""))
- mcfdef.setMcClass(mcClassName);
-
- System.out.print(rb.getString("mcf.use.cci") + "[N]: ");
- String useCciConnection = in.readLine();
- if (useCciConnection == null)
- mcfdef.setUseCciConnection(false);
- else
- {
- if (useCciConnection.equals("Y") || useCciConnection.equals("y") || useCciConnection.equals("Yes"))
- mcfdef.setUseCciConnection(true);
- else
- mcfdef.setUseCciConnection(false);
- }
-
- if (!mcfdef.isUseCciConnection())
- {
- System.out.print(rb.getString("cf.interface.name"));
- System.out.print("[" + mcfdef.getCfInterfaceClass() + "]: ");
- String cfInterfaceName = in.readLine();
- if (cfInterfaceName != null && !cfInterfaceName.equals(""))
- mcfdef.setCfInterfaceClass(cfInterfaceName);
-
- System.out.print(rb.getString("cf.class.name"));
- System.out.print("[" + mcfdef.getCfClass() + "]: ");
- String cfClassName = in.readLine();
- if (cfClassName != null && !cfClassName.equals(""))
- mcfdef.setCfClass(cfClassName);
-
- System.out.print(rb.getString("conn.interface.name"));
- System.out.print("[" + mcfdef.getConnInterfaceClass() + "]: ");
- String connInterfaceName = in.readLine();
- if (connInterfaceName != null && !connInterfaceName.equals(""))
- mcfdef.setConnInterfaceClass(connInterfaceName);
-
- System.out.print(rb.getString("conn.class.name"));
- System.out.print("[" + mcfdef.getConnImplClass() + "]: ");
- String connImplName = in.readLine();
- if (connImplName != null && !connImplName.equals(""))
- mcfdef.setConnImplClass(connImplName);
-
- System.out.print(rb.getString("connection.method.support") + "[N]: ");
- String supportMethod = in.readLine();
- if (supportMethod == null)
- mcfdef.setDefineMethodInConnection(false);
- else
- {
- if (supportMethod.equals("Y") || supportMethod.equals("y") || supportMethod.equals("Yes"))
- mcfdef.setDefineMethodInConnection(true);
- else
- mcfdef.setDefineMethodInConnection(false);
- }
- if (mcfdef.isDefineMethodInConnection())
- {
- mcfdef.setMethods(inputMethod(in));
- }
- }
- mcfDefs.add(mcfdef);
- mcfID++;
- moreMcf = false;
-
- if (def.getVersion().equals("1.5") || def.getVersion().equals("1.6"))
- {
- System.out.print(rb.getString("more.mcf") + "[N]: ");
- String inputMoreMcf = in.readLine();
- if (inputMoreMcf != null &&
- (inputMoreMcf.equals("Y") || inputMoreMcf.equals("y") || inputMoreMcf.equals("Yes")))
- moreMcf = true;
- }
- }
- while (moreMcf);
- }
-
- //inbound
- if (def.isSupportInbound())
- {
- boolean defaultPackage = true;
- System.out.print(rb.getString("ml.interface.name"));
- System.out.print("[" + def.getMlClass() + "]: ");
- String mlClassName = in.readLine();
- if (mlClassName != null && !mlClassName.equals(""))
- {
- def.setMlClass(mlClassName);
- if (mlClassName.indexOf(".") != -1)
- defaultPackage = false;
- else
- {
- setDefaultValue(def, mlClassName, "MessageListener");
- setDefaultValue(def, mlClassName, "Ml");
- }
- }
- def.setDefaultPackageInbound(defaultPackage);
-
- System.out.print(rb.getString("as.class.name"));
- System.out.print("[" + def.getAsClass() + "]: ");
- String asClassName = in.readLine();
- if (asClassName != null && !asClassName.equals(""))
- def.setAsClass(asClassName);
-
- List<ConfigPropType> asProps = inputProperties("as", in, true);
- def.setAsConfigProps(asProps);
-
- System.out.print(rb.getString("acti.class.name"));
- System.out.print("[" + def.getActivationClass() + "]: ");
- String actiClassName = in.readLine();
- if (actiClassName != null && !actiClassName.equals(""))
- def.setActivationClass(actiClassName);
- }
-
- //admin object
- System.out.print(rb.getString("gen.adminobject") + "[N]: ");
- String genAo = in.readLine();
- if (genAo == null)
- def.setGenAdminObject(false);
- else
- {
- if (genAo.equals("Y") || genAo.equals("y") || genAo.equals("Yes"))
- def.setGenAdminObject(true);
- else
- def.setGenAdminObject(false);
- }
-
- if (def.isGenAdminObject())
- {
- System.out.print(rb.getString("adminobject.raa") + "[Y]: ");
- String aoRaAssociation = in.readLine();
- if (aoRaAssociation == null || aoRaAssociation.equals(""))
- def.setAdminObjectImplRaAssociation(true);
- else
- {
- if (aoRaAssociation.equals("Y") || aoRaAssociation.equals("y") || aoRaAssociation.equals("Yes"))
- def.setAdminObjectImplRaAssociation(true);
- else
- def.setAdminObjectImplRaAssociation(false);
- }
- }
- int numOfAo = 0;
- while (numOfAo >= 0 && def.isGenAdminObject())
- {
- String strOrder = numOfAo > 0 ? Integer.valueOf(numOfAo).toString() : "";
- AdminObjectType aoType = new AdminObjectType();
- System.out.print(rb.getString("adminobject.interface.name"));
- System.out.print("[" + def.getDefaultValue() + strOrder + "AdminObjectInterface]: ");
- String aoInterfaceName = in.readLine();
- if (aoInterfaceName != null && !aoInterfaceName.equals(""))
- {
- aoType.setAdminObjectInterface(aoInterfaceName);
- }
- else
- {
- aoType.setAdminObjectInterface(def.getDefaultValue() + strOrder + "AdminObjectInterface");
- }
-
- System.out.print(rb.getString("adminobject.class.name"));
- System.out.print("[" + def.getDefaultValue() + strOrder + "AdminObjectImpl]: ");
- String aoClassName = in.readLine();
- if (aoClassName != null && !aoClassName.equals(""))
- {
- aoType.setAdminObjectClass(aoClassName);
- }
- else
- {
- aoType.setAdminObjectClass(def.getDefaultValue() + strOrder + "AdminObjectImpl");
- }
-
- List<ConfigPropType> aoProps = inputProperties("adminobject", in, false);
- aoType.setAoConfigProps(aoProps);
-
- if (def.getAdminObjects() == null)
- def.setAdminObjects(new ArrayList<AdminObjectType>());
- def.getAdminObjects().add(aoType);
-
- System.out.print(rb.getString("gen.adminobject.other") + "[N]: ");
- String genAoAgain = in.readLine();
- if (genAoAgain == null)
- numOfAo = -1;
- else
- {
- if (genAoAgain.equals("Y") || genAoAgain.equals("y") || genAoAgain.equals("Yes"))
- numOfAo++;
- else
- numOfAo = -1;
- }
- }
-
- if (!def.getVersion().equals("1.0") &&
- def.isSupportOutbound() &&
- !def.getMcfDefs().get(0).isUseCciConnection())
- {
- //generate mbean classes
- System.out.print(rb.getString("gen.mbean") + "[Y]: ");
- String genMbean = in.readLine();
- if (genMbean == null)
- def.setGenMbean(true);
- else
- {
- if (genMbean.equals("N") || genMbean.equals("n") || genMbean.equals("No"))
- def.setGenMbean(false);
- else
- def.setGenMbean(true);
- }
- }
-
- //build environment
- System.out.print(rb.getString("build.env"));
- System.out.print("[" + def.getBuild() + "]: ");
- String buildEnv = in.readLine();
- if (buildEnv != null && !buildEnv.equals(""))
- {
- if (buildEnv.equalsIgnoreCase("i") ||
- buildEnv.equalsIgnoreCase("ant+ivy") ||
- buildEnv.equalsIgnoreCase("ivy"))
- {
- def.setBuild("ivy");
- }
- else if (buildEnv.equalsIgnoreCase("m") ||
- buildEnv.equalsIgnoreCase("maven"))
- {
- def.setBuild("maven");
- }
- else
- def.setBuild("ant");
- }
- else
- def.setBuild("ant");
-
- return def;
- }
-
- /**
- * check defalut value and set it
- *
- * @param def definition
- * @param className
- * @param stringvalue post-fix string
- */
- private static void setDefaultValue(Definition def, String className, String stringvalue)
- {
- if (className.endsWith(stringvalue))
- def.setDefaultValue(className.substring(0, className.length() - stringvalue.length()));
- }
-
- /**
- * copy all jars
- * @param outputDir output directory
- * @throws IOException ioException
- */
- private static void copyAllJars(String outputDir) throws IOException
- {
- File out = new File(outputDir);
- String path = out.getAbsolutePath();
- String targetPath = path + File.separatorChar + "lib";
-
- String libPath = path + File.separatorChar + ".." + File.separatorChar + ".." + File.separatorChar +
- ".." + File.separatorChar + "lib";
- Utils.copyFolder(libPath, targetPath, "jar");
-
- String binPath = path + File.separatorChar + ".." + File.separatorChar + ".." + File.separatorChar +
- ".." + File.separatorChar + "bin";
- Utils.copyFolder(binPath, targetPath, "jar");
- }
-
- /**
- * Input Properties
- * @param classname belong to which java class
- * @param in BufferedReader
- * @param supportRequired need input required property
- * @return List<ConfigPropType> list of properties
- * @throws IOException ioException
- */
- private static List<ConfigPropType> inputProperties(String classname,
- BufferedReader in, boolean supportRequired)
- throws IOException
- {
- List<ConfigPropType> props = new ArrayList<ConfigPropType>();
- while (true)
- {
- System.out.println(rb.getString(classname + ".config.properties"));
- System.out.print(" " + rb.getString("config.properties.name"));
- String name = in.readLine();
- if (name == null || name.equals(""))
- break;
- System.out.print(" " + rb.getString("config.properties.type"));
- String type = in.readLine();
-
- if (!BasicType.isBasicType(type))
- {
- System.out.print(rb.getString("config.properties.type.tip") + " [");
- System.out.println(BasicType.allBasicType() + "]");
- continue;
- }
- System.out.print(" " + rb.getString("config.properties.value"));
- String value = in.readLine();
- boolean required = false;
- if (supportRequired)
- {
- System.out.print(" " + rb.getString("config.properties.required") + "[N]: ");
- String propRequired = in.readLine();
- if (propRequired == null)
- required = false;
- else
- {
- if (propRequired.equals("Y") || propRequired.equals("y") || propRequired.equals("Yes"))
- required = true;
- else
- required = false;
- }
- }
- System.out.println();
-
- ConfigPropType config = new ConfigPropType(name, type, value, required);
- props.add(config);
- }
- return props;
- }
-
- /**
- * Input Methods
- * @param in BufferedReader
- * @return List<MethodForConnection> list of properties
- * @throws IOException ioException
- */
- private static List<MethodForConnection> inputMethod(BufferedReader in)
- throws IOException
- {
- List<MethodForConnection> methods = new ArrayList<MethodForConnection>();
- while (true)
- {
- System.out.print(" " + rb.getString("connection.method.name"));
- String methodName = in.readLine();
- if (methodName == null || methodName.equals(""))
- break;
- MethodForConnection method = new MethodForConnection();
- method.setMethodName(methodName);
- System.out.print(" " + rb.getString("connection.method.return"));
- String methodReturn = in.readLine();
- if (!(methodReturn == null || methodReturn.equals("")))
- method.setReturnType(methodReturn);
- while (true)
- {
- System.out.print(" " + rb.getString("connection.method.param.name"));
- String paramName = in.readLine();
- if (paramName == null || paramName.equals(""))
- break;
- String paramType = null;
- while (true)
- {
- System.out.print(" " + rb.getString("connection.method.param.type"));
- paramType = in.readLine();
- if (BasicType.isBasicType(paramType) || BasicType.isPrimitiveType(paramType))
- break;
- System.out.print(rb.getString("config.properties.type.tip") + " [");
- System.out.println(BasicType.allType() + "]");
- }
-
- MethodParam param = method.newParam(paramName, paramType);
- method.getParams().add(param);
- }
-
- while (true)
- {
- System.out.print(" " + rb.getString("connection.method.exception"));
- String exceptions = in.readLine();
- if (exceptions == null || exceptions.equals(""))
- break;
- method.getExceptionType().add(exceptions);
- }
- methods.add(method);
- }
-
- return methods;
-
- }
-
- /**
- * Tool usage
- */
- private static void usage()
- {
- System.out.println("Usage: codegenerator [-o directory]");
- }
-
-}
Copied: projects/jboss-jca/tags/IRONJACAMAR_1_0_8_FINAL/codegenerator/src/main/java/org/jboss/jca/codegenerator/Main.java (from rev 112698, projects/jboss-jca/branches/Branch_1_0/codegenerator/src/main/java/org/jboss/jca/codegenerator/Main.java)
===================================================================
--- projects/jboss-jca/tags/IRONJACAMAR_1_0_8_FINAL/codegenerator/src/main/java/org/jboss/jca/codegenerator/Main.java (rev 0)
+++ projects/jboss-jca/tags/IRONJACAMAR_1_0_8_FINAL/codegenerator/src/main/java/org/jboss/jca/codegenerator/Main.java 2012-03-02 13:22:21 UTC (rev 112723)
@@ -0,0 +1,813 @@
+/*
+ * 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.BufferedReader;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Locale;
+import java.util.ResourceBundle;
+import java.util.Set;
+
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.JAXBException;
+import javax.xml.bind.Unmarshaller;
+
+
+/**
+ * Code generator main class
+ *
+ * @author Jeff Zhang
+ * @version $Revision: $
+ */
+public class Main
+{
+ private static final int SUCCESS = 0;
+ private static final int ERROR = 1;
+ private static final int OTHER = 2;
+
+ /** ResourceBundle */
+ private static ResourceBundle rb = ResourceBundle.getBundle("codegenerator", Locale.getDefault());
+
+ /**
+ * Code generator stand alone tool
+ *
+ * @param args command line arguments
+ */
+ public static void main(String[] args)
+ {
+ String outputDir = "out"; //default output directory
+ String defxml = null;
+ int arg = 0;
+
+ if (args.length > 0)
+ {
+ while (args.length > arg + 1)
+ {
+ if (args[arg].startsWith("-"))
+ {
+ if (args[arg].equals("-o"))
+ {
+ arg++;
+ if (arg >= args.length)
+ {
+ usage();
+ System.exit(OTHER);
+ }
+ outputDir = args[arg];
+ }
+ else if (args[arg].equals("-f"))
+ {
+ arg++;
+ if (arg >= args.length)
+ {
+ usage();
+ System.exit(OTHER);
+ }
+ defxml = args[arg];
+ }
+ }
+ else
+ {
+ usage();
+ System.exit(OTHER);
+ }
+ arg++;
+ }
+ }
+ try
+ {
+ File out = new File(outputDir);
+ Utils.recursiveDelete(out);
+
+ 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);
+
+ if (def.getBuild().equals("ant"))
+ 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
+ *
+ * @throws IOException ioException
+ * @return Definition definition from input
+ */
+ private static Definition inputFromCommandLine() throws IOException
+ {
+ BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
+ Definition def = new Definition();
+ Set<String> classes = new HashSet<String>();
+
+ //profile version
+ String version = null;
+ do
+ {
+ System.out.print(rb.getString("profile.version") + "[1.6]: ");
+ version = in.readLine();
+ if (version == null || version.equals(""))
+ version = "1.6";
+ }
+ while (!(version.equals("1.6") || version.equals("1.5") || version.equals("1.0")));
+ def.setVersion(version);
+
+ //by default, support outbound, but not inbound
+ def.setSupportOutbound(true);
+ def.setSupportInbound(false);
+
+ //bound
+ if (!version.equals("1.0"))
+ {
+ System.out.print(rb.getString("support.bound") + "[O]: ");
+ String bound = in.readLine();
+ if (bound == null || bound.equals("") || bound.equals("O") || bound.equals("o") || bound.equals("Outbound"))
+ {
+ //keep default bound
+ }
+ else if (bound.equals("I") || bound.equals("i") || bound.equals("Inbound"))
+ {
+ def.setSupportOutbound(false);
+ def.setSupportInbound(true);
+ }
+ else if (bound.equals("B") || bound.equals("b") || bound.equals("Bidirectional"))
+ {
+ def.setSupportOutbound(true);
+ def.setSupportInbound(true);
+ }
+ }
+
+ //package name
+ System.out.print(rb.getString("package.name"));
+ String packageName = in.readLine();
+ def.setRaPackage(packageName);
+
+ //transaction
+ if (def.isSupportOutbound())
+ {
+ System.out.print(rb.getString("support.transaction") + "[N]: ");
+ String trans = in.readLine();
+ if (trans == null || trans.equals(""))
+ def.setSupportTransaction("NoTransaction");
+ else if (trans.equals("L") || trans.equals("l") || trans.equals("LocalTransaction"))
+ {
+ def.setSupportTransaction("LocalTransaction");
+ }
+ else if (trans.equals("X") || trans.equals("x") || trans.equals("XATransaction"))
+ {
+ def.setSupportTransaction("XATransaction");
+ }
+ else
+ {
+ def.setSupportTransaction("NoTransaction");
+ }
+ }
+
+ //reauthentication
+ if (def.isSupportOutbound() && !version.equals("1.0"))
+ {
+ System.out.print(rb.getString("support.reauthentication") + "[N]: ");
+ String reauth = in.readLine();
+ if (reauth == null || reauth.equals(""))
+ def.setSupportReauthen(false);
+ else if (reauth.equals("Y") || reauth.equals("y") || reauth.equals("Yes"))
+ {
+ def.setSupportReauthen(true);
+ }
+ else
+ {
+ def.setSupportReauthen(false);
+ }
+ }
+
+ //support annotation
+ if (version.equals("1.6"))
+ {
+ System.out.print(rb.getString("use.annotation") + "[Y]: ");
+ String useAnnotation = in.readLine();
+ if (useAnnotation == null)
+ def.setUseAnnotation(true);
+ else
+ {
+ if (useAnnotation.equals("N") || useAnnotation.equals("n") || useAnnotation.equals("No"))
+ def.setUseAnnotation(false);
+ else
+ def.setUseAnnotation(true);
+ }
+ }
+ else
+ {
+ def.setUseAnnotation(false);
+ }
+
+ //use resource adapter
+ if (def.isSupportOutbound() && !def.isSupportInbound() && (version.equals("1.6") || version.equals("1.5")))
+ {
+ System.out.print(rb.getString("use.ra") + "[Y]: ");
+ String useRa = in.readLine();
+ if (useRa == null)
+ def.setUseRa(true);
+ else
+ {
+ if (useRa.equals("N") || useRa.equals("n") || useRa.equals("No"))
+ def.setUseRa(false);
+ else
+ def.setUseRa(true);
+ }
+ }
+ else if (version.equals("1.0"))
+ {
+ def.setUseRa(false);
+ }
+ else
+ {
+ def.setUseRa(true);
+ }
+
+ //input ra class name
+ if (def.isUseRa() || def.isSupportInbound())
+ {
+ System.out.print(rb.getString("ra.class.name"));
+ System.out.print("[" + def.getRaClass() + "]: ");
+ String raClassName = in.readLine();
+ classes.add(raClassName);
+ if (raClassName != null && !raClassName.equals(""))
+ {
+ def.setRaClass(raClassName);
+ setDefaultValue(def, raClassName, "ResourceAdapter");
+ setDefaultValue(def, raClassName, "Ra");
+ }
+
+ List<ConfigPropType> raProps = inputProperties("ra", in, false);
+ def.setRaConfigProps(raProps);
+ }
+
+ //outbound
+ if (def.isSupportOutbound())
+ {
+ List<McfDef> mcfDefs = new ArrayList<McfDef>();
+ def.setMcfDefs(mcfDefs);
+ int mcfID = 1;
+ boolean moreMcf;
+ do
+ {
+ McfDef mcfdef = new McfDef(mcfID, def);
+ String mcfClassName = "";
+ do
+ {
+ System.out.print(rb.getString("mcf.class.name"));
+ System.out.print("[" + mcfdef.getMcfClass() + "]: ");
+ mcfClassName = in.readLine();
+ }
+ while (classes.contains(mcfClassName) && !mcfClassName.equals(""));
+ classes.add(mcfClassName);
+ if (mcfClassName != null && !mcfClassName.equals(""))
+ {
+ mcfdef.setMcfClass(mcfClassName);
+ setDefaultValue(def, mcfClassName, mcfID + "ManagedConnectionfactory");
+ setDefaultValue(def, mcfClassName, mcfID + "Mcf");
+ }
+
+ List<ConfigPropType> mcfProps = inputProperties("mcf", in, false);
+ mcfdef.setMcfConfigProps(mcfProps);
+
+ if (def.isUseRa())
+ {
+ System.out.print(rb.getString("mcf.impl.raa") + "[Y]: ");
+ String raAssociation = in.readLine();
+ if (raAssociation == null || raAssociation.equals(""))
+ mcfdef.setImplRaAssociation(true);
+ else
+ {
+ if (raAssociation.equals("Y") || raAssociation.equals("y") || raAssociation.equals("Yes"))
+ mcfdef.setImplRaAssociation(true);
+ else
+ mcfdef.setImplRaAssociation(false);
+ }
+ }
+
+ String mcClassName = "";
+ do
+ {
+ System.out.print(rb.getString("mc.class.name"));
+ System.out.print("[" + mcfdef.getMcClass() + "]: ");
+ mcClassName = in.readLine();
+ }
+ while (classes.contains(mcClassName) && !mcClassName.equals(""));
+ classes.add(mcClassName);
+
+ if (mcClassName != null && !mcClassName.equals(""))
+ mcfdef.setMcClass(mcClassName);
+
+ System.out.print(rb.getString("mcf.use.cci") + "[N]: ");
+ String useCciConnection = in.readLine();
+ if (useCciConnection == null)
+ mcfdef.setUseCciConnection(false);
+ else
+ {
+ if (useCciConnection.equals("Y") || useCciConnection.equals("y") || useCciConnection.equals("Yes"))
+ mcfdef.setUseCciConnection(true);
+ else
+ mcfdef.setUseCciConnection(false);
+ }
+
+ if (!mcfdef.isUseCciConnection())
+ {
+ String cfInterfaceName = "";
+ do
+ {
+ System.out.print(rb.getString("cf.interface.name"));
+ System.out.print("[" + mcfdef.getCfInterfaceClass() + "]: ");
+ cfInterfaceName = in.readLine();
+ }
+ while (classes.contains(cfInterfaceName) && !cfInterfaceName.equals(""));
+ classes.add(cfInterfaceName);
+ if (cfInterfaceName != null && !cfInterfaceName.equals(""))
+ mcfdef.setCfInterfaceClass(cfInterfaceName);
+
+ String cfClassName = "";
+ do
+ {
+ System.out.print(rb.getString("cf.class.name"));
+ System.out.print("[" + mcfdef.getCfClass() + "]: ");
+ cfClassName = in.readLine();
+ }
+ while (classes.contains(cfClassName) && !cfClassName.equals(""));
+ classes.add(cfClassName);
+ if (cfClassName != null && !cfClassName.equals(""))
+ mcfdef.setCfClass(cfClassName);
+
+ String connInterfaceName = "";
+ do
+ {
+ System.out.print(rb.getString("conn.interface.name"));
+ System.out.print("[" + mcfdef.getConnInterfaceClass() + "]: ");
+ connInterfaceName = in.readLine();
+ }
+ while (classes.contains(connInterfaceName) && !connInterfaceName.equals(""));
+ classes.add(connInterfaceName);
+ if (connInterfaceName != null && !connInterfaceName.equals(""))
+ mcfdef.setConnInterfaceClass(connInterfaceName);
+
+ String connImplName = "";
+ do
+ {
+ System.out.print(rb.getString("conn.class.name"));
+ System.out.print("[" + mcfdef.getConnImplClass() + "]: ");
+ connImplName = in.readLine();
+ }
+ while (classes.contains(connImplName) && !connImplName.equals(""));
+ classes.add(connImplName);
+ if (connImplName != null && !connImplName.equals(""))
+ mcfdef.setConnImplClass(connImplName);
+
+ System.out.print(rb.getString("connection.method.support") + "[N]: ");
+ String supportMethod = in.readLine();
+ if (supportMethod == null)
+ mcfdef.setDefineMethodInConnection(false);
+ else
+ {
+ if (supportMethod.equals("Y") || supportMethod.equals("y") || supportMethod.equals("Yes"))
+ mcfdef.setDefineMethodInConnection(true);
+ else
+ mcfdef.setDefineMethodInConnection(false);
+ }
+ if (mcfdef.isDefineMethodInConnection())
+ {
+ mcfdef.setMethods(inputMethod(in));
+ }
+ }
+ mcfDefs.add(mcfdef);
+ mcfID++;
+ moreMcf = false;
+
+ if (def.getVersion().equals("1.5") || def.getVersion().equals("1.6"))
+ {
+ System.out.print(rb.getString("more.mcf") + "[N]: ");
+ String inputMoreMcf = in.readLine();
+ if (inputMoreMcf != null &&
+ (inputMoreMcf.equals("Y") || inputMoreMcf.equals("y") || inputMoreMcf.equals("Yes")))
+ moreMcf = true;
+ }
+ }
+ while (moreMcf);
+ }
+
+ //inbound
+ if (def.isSupportInbound())
+ {
+ String mlClassName = "";
+ do
+ {
+ System.out.print(rb.getString("ml.interface.name"));
+ System.out.print("[" + def.getMlClass() + "]: ");
+ mlClassName = in.readLine();
+ }
+ while (classes.contains(mlClassName) && !mlClassName.equals(""));
+ classes.add(mlClassName);
+ boolean defaultPackage = true;
+ if (mlClassName != null && !mlClassName.equals(""))
+ {
+ def.setMlClass(mlClassName);
+ if (mlClassName.indexOf(".") != -1)
+ defaultPackage = false;
+ else
+ {
+ setDefaultValue(def, mlClassName, "MessageListener");
+ setDefaultValue(def, mlClassName, "Ml");
+ }
+ }
+ def.setDefaultPackageInbound(defaultPackage);
+
+ String asClassName = "";
+ do
+ {
+ System.out.print(rb.getString("as.class.name"));
+ System.out.print("[" + def.getAsClass() + "]: ");
+ asClassName = in.readLine();
+ }
+ while (classes.contains(asClassName) && !asClassName.equals(""));
+ classes.add(asClassName);
+ if (asClassName != null && !asClassName.equals(""))
+ def.setAsClass(asClassName);
+
+ List<ConfigPropType> asProps = inputProperties("as", in, true);
+ def.setAsConfigProps(asProps);
+
+ String actiClassName = "";
+ do
+ {
+ System.out.print(rb.getString("acti.class.name"));
+ System.out.print("[" + def.getActivationClass() + "]: ");
+ actiClassName = in.readLine();
+ }
+ while (classes.contains(actiClassName) && !actiClassName.equals(""));
+ classes.add(actiClassName);
+ if (actiClassName != null && !actiClassName.equals(""))
+ def.setActivationClass(actiClassName);
+ }
+
+ //admin object
+ System.out.print(rb.getString("gen.adminobject") + "[N]: ");
+ String genAo = in.readLine();
+ if (genAo == null)
+ def.setGenAdminObject(false);
+ else
+ {
+ if (genAo.equals("Y") || genAo.equals("y") || genAo.equals("Yes"))
+ def.setGenAdminObject(true);
+ else
+ def.setGenAdminObject(false);
+ }
+
+ if (def.isGenAdminObject())
+ {
+ System.out.print(rb.getString("adminobject.raa") + "[Y]: ");
+ String aoRaAssociation = in.readLine();
+ if (aoRaAssociation == null || aoRaAssociation.equals(""))
+ def.setAdminObjectImplRaAssociation(true);
+ else
+ {
+ if (aoRaAssociation.equals("Y") || aoRaAssociation.equals("y") || aoRaAssociation.equals("Yes"))
+ def.setAdminObjectImplRaAssociation(true);
+ else
+ def.setAdminObjectImplRaAssociation(false);
+ }
+ }
+ int numOfAo = 0;
+ while (numOfAo >= 0 && def.isGenAdminObject())
+ {
+ String strOrder = numOfAo > 0 ? Integer.valueOf(numOfAo).toString() : "";
+ AdminObjectType aoType = new AdminObjectType();
+
+ String aoInterfaceName = "";
+ do
+ {
+ System.out.print(rb.getString("adminobject.interface.name"));
+ System.out.print("[" + def.getDefaultValue() + strOrder + "AdminObjectInterface]: ");
+ aoInterfaceName = in.readLine();
+ }
+ while (classes.contains(aoInterfaceName) && !aoInterfaceName.equals(""));
+ classes.add(aoInterfaceName);
+
+ if (aoInterfaceName != null && !aoInterfaceName.equals(""))
+ {
+ aoType.setAdminObjectInterface(aoInterfaceName);
+ }
+ else
+ {
+ aoType.setAdminObjectInterface(def.getDefaultValue() + strOrder + "AdminObjectInterface");
+ }
+
+ String aoClassName = "";
+ do
+ {
+ System.out.print(rb.getString("adminobject.class.name"));
+ System.out.print("[" + def.getDefaultValue() + strOrder + "AdminObjectImpl]: ");
+ aoClassName = in.readLine();
+ }
+ while (classes.contains(aoClassName) && !aoClassName.equals(""));
+ classes.add(aoClassName);
+ if (aoClassName != null && !aoClassName.equals(""))
+ {
+ aoType.setAdminObjectClass(aoClassName);
+ }
+ else
+ {
+ aoType.setAdminObjectClass(def.getDefaultValue() + strOrder + "AdminObjectImpl");
+ }
+
+ List<ConfigPropType> aoProps = inputProperties("adminobject", in, false);
+ aoType.setAoConfigProps(aoProps);
+
+ if (def.getAdminObjects() == null)
+ def.setAdminObjects(new ArrayList<AdminObjectType>());
+ def.getAdminObjects().add(aoType);
+
+ System.out.print(rb.getString("gen.adminobject.other") + "[N]: ");
+ String genAoAgain = in.readLine();
+ if (genAoAgain == null)
+ numOfAo = -1;
+ else
+ {
+ if (genAoAgain.equals("Y") || genAoAgain.equals("y") || genAoAgain.equals("Yes"))
+ numOfAo++;
+ else
+ numOfAo = -1;
+ }
+ }
+
+ if (!def.getVersion().equals("1.0") &&
+ def.isSupportOutbound() &&
+ !def.getMcfDefs().get(0).isUseCciConnection())
+ {
+ //generate mbean classes
+ System.out.print(rb.getString("gen.mbean") + "[Y]: ");
+ String genMbean = in.readLine();
+ if (genMbean == null)
+ def.setGenMbean(true);
+ else
+ {
+ if (genMbean.equals("N") || genMbean.equals("n") || genMbean.equals("No"))
+ def.setGenMbean(false);
+ else
+ def.setGenMbean(true);
+ }
+ }
+
+ //build environment
+ System.out.print(rb.getString("build.env"));
+ System.out.print("[" + def.getBuild() + "]: ");
+ String buildEnv = in.readLine();
+ if (buildEnv != null && !buildEnv.equals(""))
+ {
+ if (buildEnv.equalsIgnoreCase("i") ||
+ buildEnv.equalsIgnoreCase("ant+ivy") ||
+ buildEnv.equalsIgnoreCase("ivy"))
+ {
+ def.setBuild("ivy");
+ }
+ else if (buildEnv.equalsIgnoreCase("m") ||
+ buildEnv.equalsIgnoreCase("maven"))
+ {
+ def.setBuild("maven");
+ }
+ else
+ def.setBuild("ant");
+ }
+ else
+ def.setBuild("ant");
+
+ return def;
+ }
+
+ /**
+ * check defalut value and set it
+ *
+ * @param def definition
+ * @param className
+ * @param stringvalue post-fix string
+ */
+ private static void setDefaultValue(Definition def, String className, String stringvalue)
+ {
+ if (className.endsWith(stringvalue))
+ def.setDefaultValue(className.substring(0, className.length() - stringvalue.length()));
+ }
+
+ /**
+ * copy all jars
+ * @param outputDir output directory
+ * @throws IOException ioException
+ */
+ private static void copyAllJars(String outputDir) throws IOException
+ {
+ File out = new File(outputDir);
+ String path = out.getAbsolutePath();
+ String targetPath = path + File.separatorChar + "lib";
+
+ String libPath = path + File.separatorChar + ".." + File.separatorChar + ".." + File.separatorChar +
+ ".." + File.separatorChar + "lib";
+ Utils.copyFolder(libPath, targetPath, "jar");
+
+ String binPath = path + File.separatorChar + ".." + File.separatorChar + ".." + File.separatorChar +
+ ".." + File.separatorChar + "bin";
+ Utils.copyFolder(binPath, targetPath, "jar");
+ }
+
+ /**
+ * Input Properties
+ * @param classname belong to which java class
+ * @param in BufferedReader
+ * @param supportRequired need input required property
+ * @return List<ConfigPropType> list of properties
+ * @throws IOException ioException
+ */
+ private static List<ConfigPropType> inputProperties(String classname,
+ BufferedReader in, boolean supportRequired)
+ throws IOException
+ {
+ List<ConfigPropType> props = new ArrayList<ConfigPropType>();
+ while (true)
+ {
+ System.out.println(rb.getString(classname + ".config.properties"));
+ System.out.print(" " + rb.getString("config.properties.name"));
+ String name = in.readLine();
+ if (name == null || name.equals(""))
+ break;
+ System.out.print(" " + rb.getString("config.properties.type"));
+ String type = in.readLine();
+
+ if (!BasicType.isBasicType(type))
+ {
+ System.out.print(rb.getString("config.properties.type.tip") + " [");
+ System.out.println(BasicType.allBasicType() + "]");
+ continue;
+ }
+ System.out.print(" " + rb.getString("config.properties.value"));
+ String value = in.readLine();
+ boolean required = false;
+ if (supportRequired)
+ {
+ System.out.print(" " + rb.getString("config.properties.required") + "[N]: ");
+ String propRequired = in.readLine();
+ if (propRequired == null)
+ required = false;
+ else
+ {
+ if (propRequired.equals("Y") || propRequired.equals("y") || propRequired.equals("Yes"))
+ required = true;
+ else
+ required = false;
+ }
+ }
+ System.out.println();
+
+ ConfigPropType config = new ConfigPropType(name, type, value, required);
+ props.add(config);
+ }
+ return props;
+ }
+
+ /**
+ * Input Methods
+ * @param in BufferedReader
+ * @return List<MethodForConnection> list of properties
+ * @throws IOException ioException
+ */
+ private static List<MethodForConnection> inputMethod(BufferedReader in)
+ throws IOException
+ {
+ List<MethodForConnection> methods = new ArrayList<MethodForConnection>();
+ while (true)
+ {
+ System.out.print(" " + rb.getString("connection.method.name"));
+ String methodName = in.readLine();
+ if (methodName == null || methodName.equals(""))
+ break;
+ MethodForConnection method = new MethodForConnection();
+ method.setMethodName(methodName);
+ System.out.print(" " + rb.getString("connection.method.return"));
+ String methodReturn = in.readLine();
+ if (!(methodReturn == null || methodReturn.equals("")))
+ method.setReturnType(methodReturn);
+ while (true)
+ {
+ System.out.print(" " + rb.getString("connection.method.param.name"));
+ String paramName = in.readLine();
+ if (paramName == null || paramName.equals(""))
+ break;
+ String paramType = null;
+ while (true)
+ {
+ System.out.print(" " + rb.getString("connection.method.param.type"));
+ paramType = in.readLine();
+ if (BasicType.isBasicType(paramType) || BasicType.isPrimitiveType(paramType))
+ break;
+ System.out.print(rb.getString("config.properties.type.tip") + " [");
+ System.out.println(BasicType.allType() + "]");
+ }
+
+ MethodParam param = method.newParam(paramName, paramType);
+ method.getParams().add(param);
+ }
+
+ while (true)
+ {
+ System.out.print(" " + rb.getString("connection.method.exception"));
+ String exceptions = in.readLine();
+ if (exceptions == null || exceptions.equals(""))
+ break;
+ method.getExceptionType().add(exceptions);
+ }
+ methods.add(method);
+ }
+
+ return methods;
+
+ }
+
+ /**
+ * Tool usage
+ */
+ private static void usage()
+ {
+ System.out.println("Usage: codegenerator [-o directory]");
+ }
+
+}
Deleted: projects/jboss-jca/tags/IRONJACAMAR_1_0_8_FINAL/codegenerator/src/main/java/org/jboss/jca/codegenerator/code/AoImplCodeGen.java
===================================================================
--- projects/jboss-jca/branches/Branch_1_0/codegenerator/src/main/java/org/jboss/jca/codegenerator/code/AoImplCodeGen.java 2012-02-24 20:13:12 UTC (rev 112694)
+++ projects/jboss-jca/tags/IRONJACAMAR_1_0_8_FINAL/codegenerator/src/main/java/org/jboss/jca/codegenerator/code/AoImplCodeGen.java 2012-03-02 13:22:21 UTC (rev 112723)
@@ -1,328 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2011, 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.ConfigPropType;
-import org.jboss.jca.codegenerator.Definition;
-
-import java.io.IOException;
-import java.io.Writer;
-import java.util.List;
-
-/**
- * An admin object class CodeGen.
- *
- * @author Jeff Zhang
- * @version $Revision: $
- */
-public class AoImplCodeGen extends PropsCodeGen
-{
- /** admin object order */
- int numOfAo = 0;
-
- /**
- * constructor
- */
- public AoImplCodeGen()
- {
- }
- /**
- * constructor
- * @param num admin object order
- */
- public AoImplCodeGen(int num)
- {
- numOfAo = num;
- }
-
- /**
- * Get the numOfAo.
- *
- * @return the numOfAo.
- */
- public int getNumOfAo()
- {
- return numOfAo;
- }
-
- /**
- * Set the numOfAo.
- *
- * @param numOfAo The numOfAo to set.
- */
- public void setNumOfAo(int numOfAo)
- {
- this.numOfAo = numOfAo;
- }
-
- /**
- * 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("@AdministeredObject(adminObjectInterfaces = { ");
- out.write(def.getAdminObjects().get(numOfAo).getAdminObjectInterface());
- out.write(".class })");
- writeEol(out);
- }
- out.write("public class " + getClassName(def) + " implements " +
- def.getAdminObjects().get(numOfAo).getAdminObjectInterface());
- if (def.isAdminObjectImplRaAssociation())
- {
- out.write(",");
- writeEol(out);
- writeIndent(out, 1);
- out.write("ResourceAdapterAssociation, Referenceable, Serializable");
- }
- writeLeftCurlyBracket(out, 0);
- int indent = 1;
-
- if (def.isAdminObjectImplRaAssociation())
- {
- writeIndent(out, indent);
- out.write("/** The resource adapter */");
- writeEol(out);
- writeIndent(out, indent);
- out.write("private ResourceAdapter ra;");
- writeEol(out);
- writeEol(out);
-
- writeIndent(out, indent);
- out.write("/** Reference */");
- writeEol(out);
- writeIndent(out, indent);
- out.write("private Reference reference;");
- writeEol(out);
- writeEol(out);
- }
- writeConfigPropsDeclare(def, out, indent);
-
- writeDefaultConstructor(def, out, indent);
-
- writeConfigProps(def, out, indent);
-
- if (def.isAdminObjectImplRaAssociation())
- {
- writeResourceAdapter(def, out, indent);
- writeReference(def, out, indent);
- }
- writeHashCode(def, out, indent);
- writeEquals(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);
- if (def.isAdminObjectImplRaAssociation())
- {
- out.write("import java.io.Serializable;");
- writeEol(out);
- writeEol(out);
- out.write("import javax.naming.NamingException;");
- writeEol(out);
- out.write("import javax.naming.Reference;");
- writeEol(out);
- writeEol(out);
- out.write("import javax.resource.Referenceable;");
- writeEol(out);
- }
- if (def.isUseAnnotation())
- {
- out.write("import javax.resource.spi.AdministeredObject;");
- writeEol(out);
- out.write("import javax.resource.spi.ConfigProperty;");
- writeEol(out);
- }
- if (def.isAdminObjectImplRaAssociation())
- {
- out.write("import javax.resource.spi.ResourceAdapter;");
- writeEol(out);
- out.write("import javax.resource.spi.ResourceAdapterAssociation;");
- writeEol(out);
- }
- writeEol(out);
- }
-
- /**
- * get this class name
- * @param def definition
- * @return String class name
- */
- @Override
- public String getClassName(Definition def)
- {
- return def.getAdminObjects().get(numOfAo).getAdminObjectClass();
- }
-
- /**
- * get list of ConfigPropType
- * @param def definition
- * @return List<ConfigPropType> List of ConfigPropType
- */
- @Override
- public List<ConfigPropType> getConfigProps(Definition def)
- {
- return def.getAdminObjects().get(numOfAo).getAoConfigProps();
- }
-
- /**
- * 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("return ra;");
- 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("this.ra = ra;");
- writeRightCurlyBracket(out, indent);
- writeEol(out);
- }
-
- /**
- * Output Reference method
- * @param def definition
- * @param out Writer
- * @param indent space number
- * @throws IOException ioException
- */
- private void writeReference(Definition def, Writer out, int indent) throws IOException
- {
- writeIndent(out, indent);
- out.write("/**");
- writeEol(out);
- writeIndent(out, indent);
- out.write(" * Get the Reference instance.");
- writeEol(out);
- writeIndent(out, indent);
- out.write(" *");
- writeEol(out);
- writeIndent(out, indent);
- out.write(" * @return Reference instance");
- writeEol(out);
- writeIndent(out, indent);
- out.write(" * @exception NamingException Thrown if a reference can't be obtained");
- writeEol(out);
- writeIndent(out, indent);
- out.write(" */");
- writeEol(out);
-
- writeIndent(out, indent);
- out.write("@Override");
- writeEol(out);
- writeIndent(out, indent);
- out.write("public Reference getReference() throws NamingException");
- writeLeftCurlyBracket(out, indent);
- writeIndent(out, indent + 1);
- out.write("return reference;");
- writeRightCurlyBracket(out, indent);
- writeEol(out);
-
- writeIndent(out, indent);
- out.write("/**");
- writeEol(out);
- writeIndent(out, indent);
- out.write(" * Set the Reference instance.");
- writeEol(out);
- writeIndent(out, indent);
- out.write(" *");
- writeEol(out);
- writeIndent(out, indent);
- out.write(" * @param reference A Reference instance");
- writeEol(out);
- writeIndent(out, indent);
- out.write(" */");
- writeEol(out);
-
- writeIndent(out, indent);
- out.write("@Override");
- writeEol(out);
- writeIndent(out, indent);
- out.write("public void setReference(Reference reference)");
- writeLeftCurlyBracket(out, indent);
- writeIndent(out, indent + 1);
- out.write("this.reference = reference;");
- writeRightCurlyBracket(out, indent);
- writeEol(out);
- }
-}
Copied: projects/jboss-jca/tags/IRONJACAMAR_1_0_8_FINAL/codegenerator/src/main/java/org/jboss/jca/codegenerator/code/AoImplCodeGen.java (from rev 112698, projects/jboss-jca/branches/Branch_1_0/codegenerator/src/main/java/org/jboss/jca/codegenerator/code/AoImplCodeGen.java)
===================================================================
--- projects/jboss-jca/tags/IRONJACAMAR_1_0_8_FINAL/codegenerator/src/main/java/org/jboss/jca/codegenerator/code/AoImplCodeGen.java (rev 0)
+++ projects/jboss-jca/tags/IRONJACAMAR_1_0_8_FINAL/codegenerator/src/main/java/org/jboss/jca/codegenerator/code/AoImplCodeGen.java 2012-03-02 13:22:21 UTC (rev 112723)
@@ -0,0 +1,336 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2011, 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.ConfigPropType;
+import org.jboss.jca.codegenerator.Definition;
+
+import java.io.IOException;
+import java.io.Writer;
+import java.util.List;
+
+/**
+ * An admin object class CodeGen.
+ *
+ * @author Jeff Zhang
+ * @version $Revision: $
+ */
+public class AoImplCodeGen extends PropsCodeGen
+{
+ /** admin object order */
+ int numOfAo = 0;
+
+ /**
+ * constructor
+ */
+ public AoImplCodeGen()
+ {
+ }
+ /**
+ * constructor
+ * @param num admin object order
+ */
+ public AoImplCodeGen(int num)
+ {
+ numOfAo = num;
+ }
+
+ /**
+ * Get the numOfAo.
+ *
+ * @return the numOfAo.
+ */
+ public int getNumOfAo()
+ {
+ return numOfAo;
+ }
+
+ /**
+ * Set the numOfAo.
+ *
+ * @param numOfAo The numOfAo to set.
+ */
+ public void setNumOfAo(int numOfAo)
+ {
+ this.numOfAo = numOfAo;
+ }
+
+ /**
+ * 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("@AdministeredObject(adminObjectInterfaces = { ");
+ out.write(def.getAdminObjects().get(numOfAo).getAdminObjectInterface());
+ out.write(".class })");
+ writeEol(out);
+ }
+ out.write("public class " + getClassName(def) + " implements " +
+ def.getAdminObjects().get(numOfAo).getAdminObjectInterface());
+ if (def.isAdminObjectImplRaAssociation())
+ {
+ out.write(",");
+ writeEol(out);
+ writeIndent(out, 1);
+ out.write("ResourceAdapterAssociation, Referenceable, Serializable");
+ }
+ writeLeftCurlyBracket(out, 0);
+ int indent = 1;
+
+ writeIndent(out, indent);
+ out.write("/** Serial version uid */");
+ writeEol(out);
+ writeIndent(out, indent);
+ out.write("private static final long serialVersionUID = 1L;");
+ writeEol(out);
+ writeEol(out);
+
+ if (def.isAdminObjectImplRaAssociation())
+ {
+ writeIndent(out, indent);
+ out.write("/** The resource adapter */");
+ writeEol(out);
+ writeIndent(out, indent);
+ out.write("private ResourceAdapter ra;");
+ writeEol(out);
+ writeEol(out);
+
+ writeIndent(out, indent);
+ out.write("/** Reference */");
+ writeEol(out);
+ writeIndent(out, indent);
+ out.write("private Reference reference;");
+ writeEol(out);
+ writeEol(out);
+ }
+ writeConfigPropsDeclare(def, out, indent);
+
+ writeDefaultConstructor(def, out, indent);
+
+ writeConfigProps(def, out, indent);
+
+ if (def.isAdminObjectImplRaAssociation())
+ {
+ writeResourceAdapter(def, out, indent);
+ writeReference(def, out, indent);
+ }
+ writeHashCode(def, out, indent);
+ writeEquals(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);
+ if (def.isAdminObjectImplRaAssociation())
+ {
+ out.write("import java.io.Serializable;");
+ writeEol(out);
+ writeEol(out);
+ out.write("import javax.naming.NamingException;");
+ writeEol(out);
+ out.write("import javax.naming.Reference;");
+ writeEol(out);
+ writeEol(out);
+ out.write("import javax.resource.Referenceable;");
+ writeEol(out);
+ }
+ if (def.isUseAnnotation())
+ {
+ out.write("import javax.resource.spi.AdministeredObject;");
+ writeEol(out);
+ out.write("import javax.resource.spi.ConfigProperty;");
+ writeEol(out);
+ }
+ if (def.isAdminObjectImplRaAssociation())
+ {
+ out.write("import javax.resource.spi.ResourceAdapter;");
+ writeEol(out);
+ out.write("import javax.resource.spi.ResourceAdapterAssociation;");
+ writeEol(out);
+ }
+ writeEol(out);
+ }
+
+ /**
+ * get this class name
+ * @param def definition
+ * @return String class name
+ */
+ @Override
+ public String getClassName(Definition def)
+ {
+ return def.getAdminObjects().get(numOfAo).getAdminObjectClass();
+ }
+
+ /**
+ * get list of ConfigPropType
+ * @param def definition
+ * @return List<ConfigPropType> List of ConfigPropType
+ */
+ @Override
+ public List<ConfigPropType> getConfigProps(Definition def)
+ {
+ return def.getAdminObjects().get(numOfAo).getAoConfigProps();
+ }
+
+ /**
+ * 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("return ra;");
+ 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("this.ra = ra;");
+ writeRightCurlyBracket(out, indent);
+ writeEol(out);
+ }
+
+ /**
+ * Output Reference method
+ * @param def definition
+ * @param out Writer
+ * @param indent space number
+ * @throws IOException ioException
+ */
+ private void writeReference(Definition def, Writer out, int indent) throws IOException
+ {
+ writeIndent(out, indent);
+ out.write("/**");
+ writeEol(out);
+ writeIndent(out, indent);
+ out.write(" * Get the Reference instance.");
+ writeEol(out);
+ writeIndent(out, indent);
+ out.write(" *");
+ writeEol(out);
+ writeIndent(out, indent);
+ out.write(" * @return Reference instance");
+ writeEol(out);
+ writeIndent(out, indent);
+ out.write(" * @exception NamingException Thrown if a reference can't be obtained");
+ writeEol(out);
+ writeIndent(out, indent);
+ out.write(" */");
+ writeEol(out);
+
+ writeIndent(out, indent);
+ out.write("@Override");
+ writeEol(out);
+ writeIndent(out, indent);
+ out.write("public Reference getReference() throws NamingException");
+ writeLeftCurlyBracket(out, indent);
+ writeIndent(out, indent + 1);
+ out.write("return reference;");
+ writeRightCurlyBracket(out, indent);
+ writeEol(out);
+
+ writeIndent(out, indent);
+ out.write("/**");
+ writeEol(out);
+ writeIndent(out, indent);
+ out.write(" * Set the Reference instance.");
+ writeEol(out);
+ writeIndent(out, indent);
+ out.write(" *");
+ writeEol(out);
+ writeIndent(out, indent);
+ out.write(" * @param reference A Reference instance");
+ writeEol(out);
+ writeIndent(out, indent);
+ out.write(" */");
+ writeEol(out);
+
+ writeIndent(out, indent);
+ out.write("@Override");
+ writeEol(out);
+ writeIndent(out, indent);
+ out.write("public void setReference(Reference reference)");
+ writeLeftCurlyBracket(out, indent);
+ writeIndent(out, indent + 1);
+ out.write("this.reference = reference;");
+ writeRightCurlyBracket(out, indent);
+ writeEol(out);
+ }
+}
Deleted: projects/jboss-jca/tags/IRONJACAMAR_1_0_8_FINAL/codegenerator/src/main/java/org/jboss/jca/codegenerator/code/TestCodeGen.java
===================================================================
--- projects/jboss-jca/branches/Branch_1_0/codegenerator/src/main/java/org/jboss/jca/codegenerator/code/TestCodeGen.java 2012-02-24 20:13:12 UTC (rev 112694)
+++ projects/jboss-jca/tags/IRONJACAMAR_1_0_8_FINAL/codegenerator/src/main/java/org/jboss/jca/codegenerator/code/TestCodeGen.java 2012-03-02 13:22:21 UTC (rev 112723)
@@ -1,397 +0,0 @@
-/*
- * 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.BasicType;
-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 Test CodeGen.
- *
- * @author Jeff Zhang
- * @version $Revision: $
- */
-public class TestCodeGen 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("@RunWith(Arquillian.class)");
- writeEol(out);
- out.write("public class " + getClassName(def));
- writeLeftCurlyBracket(out, 0);
- writeIndent(out, indent);
- out.write("private static Logger log = Logger.getLogger(\"" + getClassName(def) + "\");");
- writeEol(out);
- writeEol(out);
- writeIndent(out, indent);
- out.write("private static String deploymentName = \"" + getClassName(def) + "\";");
- writeEol(out);
- writeEol(out);
-
- writeDeployment(def, out, indent);
- writeResource(def, out, indent);
-
- for (int num = 0; num < def.getMcfDefs().size(); num++)
- {
- if (def.getMcfDefs().get(num).isDefineMethodInConnection())
- {
- writeTestMethod(def, out, indent, num + 1);
- }
- else
- writeTestBasic(def, out, indent, num + 1);
- }
-
- 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.util.UUID;");
- writeEol(out);
- out.write("import java.util.logging.Logger;");
- writeEol(out);
- writeEol(out);
- out.write("import javax.annotation.Resource;");
- writeEol(out);
- writeEol(out);
- out.write("import org.jboss.arquillian.container.test.api.Deployment;");
- writeEol(out);
- out.write("import org.jboss.arquillian.junit.Arquillian;");
- writeEol(out);
- writeEol(out);
- out.write("import org.jboss.shrinkwrap.api.ShrinkWrap;");
- writeEol(out);
- out.write("import org.jboss.shrinkwrap.api.spec.JavaArchive;");
- writeEol(out);
- out.write("import org.jboss.shrinkwrap.api.spec.ResourceAdapterArchive;");
- writeEol(out);
- writeEol(out);
- out.write("import org.junit.Test;");
- writeEol(out);
- out.write("import org.junit.runner.RunWith;");
- writeEol(out);
- out.write("import static org.junit.Assert.*;");
- writeEol(out);
- writeEol(out);
-
- out.write("import " + def.getRaPackage() + ".*;");
- writeEol(out);
- writeEol(out);
- }
-
- /**
- * get this class name
- * @param def definition
- * @return String class name
- */
- @Override
- public String getClassName(Definition def)
- {
- return "ConnectorTestCase";
- }
-
- /**
- * Output create deployment method
- * @param def definition
- * @param out Writer
- * @param indent space number
- * @throws IOException ioException
- */
- private void writeDeployment(Definition def, Writer out, int indent) throws IOException
- {
- writeIndent(out, indent);
- out.write("/**");
- writeEol(out);
- writeIndent(out, indent);
- out.write(" * Define the deployment");
- writeEol(out);
- writeIndent(out, indent);
- out.write(" *");
- writeEol(out);
- writeIndent(out, indent);
- out.write(" * @return The deployment archive");
- writeEol(out);
- writeIndent(out, indent);
- out.write(" */");
- writeEol(out);
-
- writeIndent(out, indent);
- out.write("@Deployment");
- writeEol(out);
- writeIndent(out, indent);
- out.write("public static ResourceAdapterArchive createDeployment()");
- writeLeftCurlyBracket(out, indent);
-
- writeIndent(out, indent + 1);
- out.write("ResourceAdapterArchive raa =");
- writeEol(out);
- writeIndent(out, indent + 2);
- out.write("ShrinkWrap.create(ResourceAdapterArchive.class, deploymentName + \".rar\");");
- writeEol(out);
- writeIndent(out, indent + 1);
- out.write("JavaArchive ja = ShrinkWrap.create(JavaArchive.class, UUID.randomUUID().toString() + \".jar\");");
- writeEol(out);
- writeIndent(out, indent + 1);
- out.write("ja.addClasses(");
-
- if (def.isUseRa())
- {
- out.write(def.getRaClass() + ".class, ");
- }
- for (int num = 0; num < def.getMcfDefs().size(); num++)
- {
- out.write(def.getMcfDefs().get(num).getMcfClass() + ".class, " +
- def.getMcfDefs().get(num).getMcClass() + ".class, ");
- if (def.getMcfDefs().get(num).isUseCciConnection())
- {
- out.write(def.getMcfDefs().get(num).getCciConnFactoryClass() + ".class, " +
- def.getMcfDefs().get(num).getCciConnFactoryClass() + ".class, " +
- def.getMcfDefs().get(num).getConnMetaClass() + ".class, " +
- def.getRaMetaClass() + ".class, " +
- def.getMcfDefs().get(num).getConnSpecClass() + ".class");
- }
- else
- {
- out.write(def.getMcfDefs().get(num).getCfInterfaceClass() + ".class, " +
- def.getMcfDefs().get(num).getCfClass() + ".class, " +
- def.getMcfDefs().get(num).getConnInterfaceClass() + ".class, " +
- def.getMcfDefs().get(num).getConnImplClass() + ".class");
- }
- if (num < def.getMcfDefs().size() - 1)
- {
- out.write(",");
- writeEol(out);
- writeIndent(out, indent + 2);
- }
- }
-
- out.write(");");
- writeEol(out);
- writeIndent(out, indent + 1);
- out.write("raa.addAsLibrary(ja);");
- writeEol(out);
- writeEol(out);
- if (!def.isUseAnnotation())
- {
- writeIndent(out, indent + 1);
- out.write("raa.addAsManifestResource(\"META-INF/ra.xml\", \"ra.xml\");");
- writeEol(out);
- writeEol(out);
- }
- writeIndent(out, indent + 1);
- out.write("raa.addAsManifestResource(\"META-INF/ironjacamar.xml\", \"ironjacamar.xml\");");
- writeEol(out);
- writeEol(out);
- writeIndent(out, indent + 1);
- out.write("return raa;");
-
- writeRightCurlyBracket(out, indent);
- writeEol(out);
- }
-
- /**
- * Output resource for conection factory
- * @param def definition
- * @param out Writer
- * @param indent space number
- * @throws IOException ioException
- */
- private void writeResource(Definition def, Writer out, int indent) throws IOException
- {
- for (int num = 0; num < def.getMcfDefs().size(); num++)
- {
- writeIndent(out, indent);
- out.write("/** Resource */");
- writeEol(out);
- writeIndent(out, indent);
- out.write("@Resource(mappedName = \"java:/eis/" + def.getMcfDefs().get(num).getMcfClass() + "\")");
- writeEol(out);
- writeIndent(out, indent);
- if (def.getMcfDefs().get(num).isUseCciConnection())
- out.write("private javax.resource.cci.ConnectionFactory");
- else
- out.write("private " + def.getMcfDefs().get(num).getCfInterfaceClass());
- out.write(" connectionFactory" + (num + 1) + ";");
- writeEol(out);
- writeEol(out);
- }
- }
- /**
- * Output test basic method
- * @param def definition
- * @param out Writer
- * @param indent space number
- * @param num number of mcf
- * @throws IOException ioException
- */
- private void writeTestBasic(Definition def, Writer out, int indent, int num) throws IOException
- {
- writeIndent(out, indent);
- out.write("/**");
- writeEol(out);
- writeIndent(out, indent);
- out.write(" * Test getConnection");
- writeEol(out);
- writeIndent(out, indent);
- out.write(" *");
- writeEol(out);
- writeIndent(out, indent);
- out.write(" * @exception Throwable Thrown if case of an error");
- writeEol(out);
- writeIndent(out, indent);
- out.write(" */");
- writeEol(out);
-
- writeIndent(out, indent);
- out.write("@Test");
- writeEol(out);
- writeIndent(out, indent);
- out.write("public void testGetConnection" + num + "() throws Throwable");
- writeLeftCurlyBracket(out, indent);
-
- writeIndent(out, indent + 1);
- out.write("assertNotNull(connectionFactory" + num + ");");
- writeEol(out);
- writeIndent(out, indent + 1);
- if (def.getMcfDefs().get(num - 1).isUseCciConnection())
- out.write("javax.resource.cci.Connection");
- else
- out.write(def.getMcfDefs().get(num - 1).getConnInterfaceClass());
- out.write(" connection" + num + " = connectionFactory" + num + ".getConnection();");
- writeEol(out);
- writeIndent(out, indent + 1);
- out.write("assertNotNull(connection" + num + ");");
- writeEol(out);
- writeIndent(out, indent + 1);
- out.write("connection" + num + ".close();");
- writeRightCurlyBracket(out, indent);
- }
-
- /**
- * Output test generated method
- * @param def definition
- * @param out Writer
- * @param indent space number
- * @param num number of mcf
- * @throws IOException ioException
- */
- private void writeTestMethod(Definition def, Writer out, int indent, int num) throws IOException
- {
- for (MethodForConnection method : def.getMcfDefs().get(num - 1).getMethods())
- {
- writeIndent(out, indent);
- out.write("/**");
- writeEol(out);
- writeIndent(out, indent);
- out.write(" * Test " + method.getMethodName());
- writeEol(out);
- writeIndent(out, indent);
- out.write(" *");
- writeEol(out);
- writeIndent(out, indent);
- out.write(" * @exception Throwable Thrown if case of an error");
- writeEol(out);
- writeIndent(out, indent);
- out.write(" */");
- writeEol(out);
-
- writeIndent(out, indent);
- out.write("@Test");
- writeEol(out);
- writeIndent(out, indent);
- out.write("public void test" + upcaseFirst(method.getMethodName()));
- int paramSize = method.getParams().size();
-
- if (paramSize == 0)
- out.write("NoArg");
- else
- {
- for (int i = 0; i < paramSize; i++)
- {
- MethodParam param = method.getParams().get(i);
- out.write(upcaseFirst(param.getName()));
- out.write(param.getType());
- }
- }
- out.write("() throws Throwable");
- writeLeftCurlyBracket(out, indent);
-
- writeIndent(out, indent + 1);
- out.write("assertNotNull(connectionFactory" + num + ");");
- writeEol(out);
- writeIndent(out, indent + 1);
- if (def.getMcfDefs().get(num - 1).isUseCciConnection())
- out.write("javax.resource.cci.Connection");
- else
- out.write(def.getMcfDefs().get(num - 1).getConnInterfaceClass());
- out.write(" connection" + num + " = connectionFactory" + num + ".getConnection();");
- writeEol(out);
- writeIndent(out, indent + 1);
- out.write("assertNotNull(connection" + num + ");");
- writeEol(out);
-
- writeIndent(out, indent + 1);
- if (!method.getReturnType().equals("void"))
- {
- out.write(method.getReturnType() + " result = ");
- }
- out.write("connection" + num + "." + method.getMethodName() + "(");
- for (int i = 0; i < paramSize; i++)
- {
- MethodParam param = method.getParams().get(i);
- out.write(BasicType.defaultValue(param.getType()));
- if (i + 1 < paramSize)
- out.write(", ");
- }
- out.write(");");
- writeEol(out);
- writeIndent(out, indent + 1);
- out.write("connection" + num + ".close();");
- writeRightCurlyBracket(out, indent);
- writeEol(out);
- }
- }
-}
Copied: projects/jboss-jca/tags/IRONJACAMAR_1_0_8_FINAL/codegenerator/src/main/java/org/jboss/jca/codegenerator/code/TestCodeGen.java (from rev 112698, projects/jboss-jca/branches/Branch_1_0/codegenerator/src/main/java/org/jboss/jca/codegenerator/code/TestCodeGen.java)
===================================================================
--- projects/jboss-jca/tags/IRONJACAMAR_1_0_8_FINAL/codegenerator/src/main/java/org/jboss/jca/codegenerator/code/TestCodeGen.java (rev 0)
+++ projects/jboss-jca/tags/IRONJACAMAR_1_0_8_FINAL/codegenerator/src/main/java/org/jboss/jca/codegenerator/code/TestCodeGen.java 2012-03-02 13:22:21 UTC (rev 112723)
@@ -0,0 +1,405 @@
+/*
+ * 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.BasicType;
+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 Test CodeGen.
+ *
+ * @author Jeff Zhang
+ * @version $Revision: $
+ */
+public class TestCodeGen 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("@RunWith(Arquillian.class)");
+ writeEol(out);
+ out.write("public class " + getClassName(def));
+ writeLeftCurlyBracket(out, 0);
+ writeIndent(out, indent);
+ out.write("private static Logger log = Logger.getLogger(\"" + getClassName(def) + "\");");
+ writeEol(out);
+ writeEol(out);
+ writeIndent(out, indent);
+ out.write("private static String deploymentName = \"" + getClassName(def) + "\";");
+ writeEol(out);
+ writeEol(out);
+
+ writeDeployment(def, out, indent);
+ writeResource(def, out, indent);
+
+ for (int num = 0; num < def.getMcfDefs().size(); num++)
+ {
+ if (def.getMcfDefs().get(num).isDefineMethodInConnection())
+ {
+ writeTestMethod(def, out, indent, num + 1);
+ }
+ else
+ writeTestBasic(def, out, indent, num + 1);
+ }
+
+ 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.util.UUID;");
+ writeEol(out);
+ out.write("import java.util.logging.Logger;");
+ writeEol(out);
+ writeEol(out);
+ out.write("import javax.annotation.Resource;");
+ writeEol(out);
+ writeEol(out);
+ out.write("import org.jboss.arquillian.container.test.api.Deployment;");
+ writeEol(out);
+ out.write("import org.jboss.arquillian.junit.Arquillian;");
+ writeEol(out);
+ writeEol(out);
+ out.write("import org.jboss.shrinkwrap.api.ShrinkWrap;");
+ writeEol(out);
+ out.write("import org.jboss.shrinkwrap.api.spec.JavaArchive;");
+ writeEol(out);
+ out.write("import org.jboss.shrinkwrap.api.spec.ResourceAdapterArchive;");
+ writeEol(out);
+ writeEol(out);
+ out.write("import org.junit.Test;");
+ writeEol(out);
+ out.write("import org.junit.runner.RunWith;");
+ writeEol(out);
+ out.write("import static org.junit.Assert.*;");
+ writeEol(out);
+ writeEol(out);
+
+ out.write("import " + def.getRaPackage() + ".*;");
+ writeEol(out);
+ writeEol(out);
+ }
+
+ /**
+ * get this class name
+ * @param def definition
+ * @return String class name
+ */
+ @Override
+ public String getClassName(Definition def)
+ {
+ return "ConnectorTestCase";
+ }
+
+ /**
+ * Output create deployment method
+ * @param def definition
+ * @param out Writer
+ * @param indent space number
+ * @throws IOException ioException
+ */
+ private void writeDeployment(Definition def, Writer out, int indent) throws IOException
+ {
+ writeIndent(out, indent);
+ out.write("/**");
+ writeEol(out);
+ writeIndent(out, indent);
+ out.write(" * Define the deployment");
+ writeEol(out);
+ writeIndent(out, indent);
+ out.write(" *");
+ writeEol(out);
+ writeIndent(out, indent);
+ out.write(" * @return The deployment archive");
+ writeEol(out);
+ writeIndent(out, indent);
+ out.write(" */");
+ writeEol(out);
+
+ writeIndent(out, indent);
+ out.write("@Deployment");
+ writeEol(out);
+ writeIndent(out, indent);
+ out.write("public static ResourceAdapterArchive createDeployment()");
+ writeLeftCurlyBracket(out, indent);
+
+ writeIndent(out, indent + 1);
+ out.write("ResourceAdapterArchive raa =");
+ writeEol(out);
+ writeIndent(out, indent + 2);
+ out.write("ShrinkWrap.create(ResourceAdapterArchive.class, deploymentName + \".rar\");");
+ writeEol(out);
+ writeIndent(out, indent + 1);
+ out.write("JavaArchive ja = ShrinkWrap.create(JavaArchive.class, UUID.randomUUID().toString() + \".jar\");");
+ writeEol(out);
+ writeIndent(out, indent + 1);
+ out.write("ja.addClasses(");
+
+ if (def.isUseRa())
+ {
+ out.write(def.getRaClass() + ".class, ");
+ }
+ for (int num = 0; num < def.getMcfDefs().size(); num++)
+ {
+ out.write(def.getMcfDefs().get(num).getMcfClass() + ".class, " +
+ def.getMcfDefs().get(num).getMcClass() + ".class, ");
+ if (def.getMcfDefs().get(num).isUseCciConnection())
+ {
+ out.write(def.getMcfDefs().get(num).getCciConnFactoryClass() + ".class, " +
+ def.getMcfDefs().get(num).getCciConnFactoryClass() + ".class, " +
+ def.getMcfDefs().get(num).getConnMetaClass() + ".class, " +
+ def.getRaMetaClass() + ".class, " +
+ def.getMcfDefs().get(num).getConnSpecClass() + ".class");
+ }
+ else
+ {
+ out.write(def.getMcfDefs().get(num).getCfInterfaceClass() + ".class, " +
+ def.getMcfDefs().get(num).getCfClass() + ".class, " +
+ def.getMcfDefs().get(num).getConnInterfaceClass() + ".class, " +
+ def.getMcfDefs().get(num).getConnImplClass() + ".class");
+ }
+ if (num < def.getMcfDefs().size() - 1)
+ {
+ out.write(",");
+ writeEol(out);
+ writeIndent(out, indent + 2);
+ }
+ }
+
+ out.write(");");
+ writeEol(out);
+ writeIndent(out, indent + 1);
+ out.write("raa.addAsLibrary(ja);");
+ writeEol(out);
+ writeEol(out);
+ if (!def.isUseAnnotation())
+ {
+ writeIndent(out, indent + 1);
+ out.write("raa.addAsManifestResource(\"META-INF/ra.xml\", \"ra.xml\");");
+ writeEol(out);
+ writeEol(out);
+ }
+ writeIndent(out, indent + 1);
+ out.write("raa.addAsManifestResource(\"META-INF/ironjacamar.xml\", \"ironjacamar.xml\");");
+ writeEol(out);
+ writeEol(out);
+ writeIndent(out, indent + 1);
+ out.write("return raa;");
+
+ writeRightCurlyBracket(out, indent);
+ writeEol(out);
+ }
+
+ /**
+ * Output resource for conection factory
+ * @param def definition
+ * @param out Writer
+ * @param indent space number
+ * @throws IOException ioException
+ */
+ private void writeResource(Definition def, Writer out, int indent) throws IOException
+ {
+ for (int num = 0; num < def.getMcfDefs().size(); num++)
+ {
+ writeIndent(out, indent);
+ out.write("/** Resource */");
+ writeEol(out);
+ writeIndent(out, indent);
+ if (def.getMcfDefs().get(num).isUseCciConnection())
+ {
+ out.write("@Resource(mappedName = \"java:/eis/" +
+ def.getMcfDefs().get(num).getCciConnFactoryClass() + "\")");
+ }
+ else
+ {
+ out.write("@Resource(mappedName = \"java:/eis/" + def.getMcfDefs().get(num).getCfInterfaceClass() + "\")");
+ }
+ writeEol(out);
+ writeIndent(out, indent);
+ if (def.getMcfDefs().get(num).isUseCciConnection())
+ out.write("private javax.resource.cci.ConnectionFactory");
+ else
+ out.write("private " + def.getMcfDefs().get(num).getCfInterfaceClass());
+ out.write(" connectionFactory" + (num + 1) + ";");
+ writeEol(out);
+ writeEol(out);
+ }
+ }
+ /**
+ * Output test basic method
+ * @param def definition
+ * @param out Writer
+ * @param indent space number
+ * @param num number of mcf
+ * @throws IOException ioException
+ */
+ private void writeTestBasic(Definition def, Writer out, int indent, int num) throws IOException
+ {
+ writeIndent(out, indent);
+ out.write("/**");
+ writeEol(out);
+ writeIndent(out, indent);
+ out.write(" * Test getConnection");
+ writeEol(out);
+ writeIndent(out, indent);
+ out.write(" *");
+ writeEol(out);
+ writeIndent(out, indent);
+ out.write(" * @exception Throwable Thrown if case of an error");
+ writeEol(out);
+ writeIndent(out, indent);
+ out.write(" */");
+ writeEol(out);
+
+ writeIndent(out, indent);
+ out.write("@Test");
+ writeEol(out);
+ writeIndent(out, indent);
+ out.write("public void testGetConnection" + num + "() throws Throwable");
+ writeLeftCurlyBracket(out, indent);
+
+ writeIndent(out, indent + 1);
+ out.write("assertNotNull(connectionFactory" + num + ");");
+ writeEol(out);
+ writeIndent(out, indent + 1);
+ if (def.getMcfDefs().get(num - 1).isUseCciConnection())
+ out.write("javax.resource.cci.Connection");
+ else
+ out.write(def.getMcfDefs().get(num - 1).getConnInterfaceClass());
+ out.write(" connection" + num + " = connectionFactory" + num + ".getConnection();");
+ writeEol(out);
+ writeIndent(out, indent + 1);
+ out.write("assertNotNull(connection" + num + ");");
+ writeEol(out);
+ writeIndent(out, indent + 1);
+ out.write("connection" + num + ".close();");
+ writeRightCurlyBracket(out, indent);
+ }
+
+ /**
+ * Output test generated method
+ * @param def definition
+ * @param out Writer
+ * @param indent space number
+ * @param num number of mcf
+ * @throws IOException ioException
+ */
+ private void writeTestMethod(Definition def, Writer out, int indent, int num) throws IOException
+ {
+ for (MethodForConnection method : def.getMcfDefs().get(num - 1).getMethods())
+ {
+ writeIndent(out, indent);
+ out.write("/**");
+ writeEol(out);
+ writeIndent(out, indent);
+ out.write(" * Test " + method.getMethodName());
+ writeEol(out);
+ writeIndent(out, indent);
+ out.write(" *");
+ writeEol(out);
+ writeIndent(out, indent);
+ out.write(" * @exception Throwable Thrown if case of an error");
+ writeEol(out);
+ writeIndent(out, indent);
+ out.write(" */");
+ writeEol(out);
+
+ writeIndent(out, indent);
+ out.write("@Test");
+ writeEol(out);
+ writeIndent(out, indent);
+ out.write("public void test" + upcaseFirst(method.getMethodName()));
+ int paramSize = method.getParams().size();
+
+ if (paramSize == 0)
+ out.write("NoArg");
+ else
+ {
+ for (int i = 0; i < paramSize; i++)
+ {
+ MethodParam param = method.getParams().get(i);
+ out.write(upcaseFirst(param.getName()));
+ out.write(param.getType());
+ }
+ }
+ out.write("() throws Throwable");
+ writeLeftCurlyBracket(out, indent);
+
+ writeIndent(out, indent + 1);
+ out.write("assertNotNull(connectionFactory" + num + ");");
+ writeEol(out);
+ writeIndent(out, indent + 1);
+ if (def.getMcfDefs().get(num - 1).isUseCciConnection())
+ out.write("javax.resource.cci.Connection");
+ else
+ out.write(def.getMcfDefs().get(num - 1).getConnInterfaceClass());
+ out.write(" connection" + num + " = connectionFactory" + num + ".getConnection();");
+ writeEol(out);
+ writeIndent(out, indent + 1);
+ out.write("assertNotNull(connection" + num + ");");
+ writeEol(out);
+
+ writeIndent(out, indent + 1);
+ if (!method.getReturnType().equals("void"))
+ {
+ out.write(method.getReturnType() + " result = ");
+ }
+ out.write("connection" + num + "." + method.getMethodName() + "(");
+ for (int i = 0; i < paramSize; i++)
+ {
+ MethodParam param = method.getParams().get(i);
+ out.write(BasicType.defaultValue(param.getType()));
+ if (i + 1 < paramSize)
+ out.write(", ");
+ }
+ out.write(");");
+ writeEol(out);
+ writeIndent(out, indent + 1);
+ out.write("connection" + num + ".close();");
+ writeRightCurlyBracket(out, indent);
+ writeEol(out);
+ }
+ }
+}
Deleted: projects/jboss-jca/tags/IRONJACAMAR_1_0_8_FINAL/codegenerator/src/main/java/org/jboss/jca/codegenerator/xml/IronjacamarXmlGen.java
===================================================================
--- projects/jboss-jca/branches/Branch_1_0/codegenerator/src/main/java/org/jboss/jca/codegenerator/xml/IronjacamarXmlGen.java 2012-02-24 20:13:12 UTC (rev 112694)
+++ projects/jboss-jca/tags/IRONJACAMAR_1_0_8_FINAL/codegenerator/src/main/java/org/jboss/jca/codegenerator/xml/IronjacamarXmlGen.java 2012-03-02 13:22:21 UTC (rev 112723)
@@ -1,137 +0,0 @@
-/*
- * 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.xml;
-
-import org.jboss.jca.codegenerator.ConfigPropType;
-import org.jboss.jca.codegenerator.Definition;
-import org.jboss.jca.codegenerator.SimpleTemplate;
-import org.jboss.jca.codegenerator.Template;
-import org.jboss.jca.codegenerator.Utils;
-
-import java.io.IOException;
-import java.io.Writer;
-import java.net.URL;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-/**
- * A IvyXmlGen.
- *
- * @author Jeff Zhang
- * @version $Revision: $
- */
-public class IronjacamarXmlGen extends AbstractXmlGen
-{
- @Override
- public void writeXmlBody(Definition def, Writer out) throws IOException
- {
- out.write("<!--");
- writeEol(out);
- writeheader(def, out);
- out.write("-->");
- writeEol(out);
- writeEol(out);
-
- URL buildFile = IronjacamarXmlGen.class.getResource("/ironjacamar.xml.template");
- String buildString = Utils.readFileIntoString(buildFile);
-
- StringBuilder strRaProps = new StringBuilder();
- List<ConfigPropType> raPropsList = def.getRaConfigProps();
- if (def.isUseRa())
- getPropsString(strRaProps, raPropsList, 2);
-
- StringBuilder strMcf = new StringBuilder();
- strMcf.append(" <connection-definitions>\n");
- for (int num = 0; num < def.getMcfDefs().size(); num++)
- {
- strMcf.append(" <connection-definition class-name=\"");
- strMcf.append(def.getRaPackage());
- strMcf.append(".");
- strMcf.append(def.getMcfDefs().get(num).getMcfClass());
- strMcf.append("\" enabled=\"true\" ");
- strMcf.append("jndi-name=\"java:/eis/");
- strMcf.append(def.getMcfDefs().get(num).getMcfClass());
- strMcf.append("\" use-java-context=\"true\" ");
- strMcf.append("pool-name=\"" + def.getMcfDefs().get(num).getMcfClass());
- strMcf.append("\">\n");
-
- StringBuilder strMcfProps = new StringBuilder();
- List<ConfigPropType> mcfPropsList = def.getMcfDefs().get(num).getMcfConfigProps();
- getPropsString(strMcfProps, mcfPropsList, 6);
- strMcf.append(strMcfProps.toString());
-
- strMcf.append(" </connection-definition>\n");
- }
- strMcf.append(" </connection-definitions>\n");
-
- StringBuilder strAo = new StringBuilder();
- if (def.isGenAdminObject())
- {
- strAo.append(" <admin-objects>\n");
- for (int i = 0; i < def.getAdminObjects().size(); i++)
- {
- strAo.append(" <admin-object class-name=\"");
- strAo.append(def.getRaPackage());
- strAo.append(".");
- strAo.append(def.getAdminObjects().get(i).getAdminObjectClass());
- strAo.append("\" jndi-name=\"java:/");
- strAo.append(def.getAdminObjects().get(i).getAdminObjectClass());
- strAo.append("\">\n");
- getPropsString(strAo, def.getAdminObjects().get(i).getAoConfigProps(), 6);
- strAo.append(" </admin-object>\n");
- }
- strAo.append(" </admin-objects>\n");
- }
-
- Map<String, String> map = new HashMap<String, String>();
- map.put("ra.props", strRaProps.toString());
- map.put("transaction", def.getSupportTransaction());
-
- map.put("mcfs", strMcf.toString());
- map.put("adminobjects", strAo.toString());
- Template template = new SimpleTemplate(buildString);
- template.process(map, out);
- }
-
- /**
- * generate properties String
- *
- * @param strProps
- * @param propsList
- * @param indent
- */
- private void getPropsString(StringBuilder strProps, List<ConfigPropType> propsList, int indent)
- {
- for (ConfigPropType props : propsList)
- {
- for (int i = 0; i < indent; i++)
- strProps.append(" ");
- strProps.append("<config-property name=\"");
- strProps.append(props.getName());
- strProps.append("\">");
- strProps.append(props.getValue());
- strProps.append("</config-property>");
- strProps.append("\n");
- }
- }
-}
Copied: projects/jboss-jca/tags/IRONJACAMAR_1_0_8_FINAL/codegenerator/src/main/java/org/jboss/jca/codegenerator/xml/IronjacamarXmlGen.java (from rev 112698, projects/jboss-jca/branches/Branch_1_0/codegenerator/src/main/java/org/jboss/jca/codegenerator/xml/IronjacamarXmlGen.java)
===================================================================
--- projects/jboss-jca/tags/IRONJACAMAR_1_0_8_FINAL/codegenerator/src/main/java/org/jboss/jca/codegenerator/xml/IronjacamarXmlGen.java (rev 0)
+++ projects/jboss-jca/tags/IRONJACAMAR_1_0_8_FINAL/codegenerator/src/main/java/org/jboss/jca/codegenerator/xml/IronjacamarXmlGen.java 2012-03-02 13:22:21 UTC (rev 112723)
@@ -0,0 +1,148 @@
+/*
+ * 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.xml;
+
+import org.jboss.jca.codegenerator.ConfigPropType;
+import org.jboss.jca.codegenerator.Definition;
+import org.jboss.jca.codegenerator.SimpleTemplate;
+import org.jboss.jca.codegenerator.Template;
+import org.jboss.jca.codegenerator.Utils;
+
+import java.io.IOException;
+import java.io.Writer;
+import java.net.URL;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * A IvyXmlGen.
+ *
+ * @author Jeff Zhang
+ * @version $Revision: $
+ */
+public class IronjacamarXmlGen extends AbstractXmlGen
+{
+ @Override
+ public void writeXmlBody(Definition def, Writer out) throws IOException
+ {
+ out.write("<!--");
+ writeEol(out);
+ writeheader(def, out);
+ out.write("-->");
+ writeEol(out);
+ writeEol(out);
+
+ URL buildFile = IronjacamarXmlGen.class.getResource("/ironjacamar.xml.template");
+ String buildString = Utils.readFileIntoString(buildFile);
+
+ StringBuilder strRaProps = new StringBuilder();
+ List<ConfigPropType> raPropsList = def.getRaConfigProps();
+ if (def.isUseRa())
+ getPropsString(strRaProps, raPropsList, 2);
+
+ StringBuilder strMcf = new StringBuilder();
+ strMcf.append(" <connection-definitions>\n");
+ for (int num = 0; num < def.getMcfDefs().size(); num++)
+ {
+ strMcf.append(" <connection-definition class-name=\"");
+ strMcf.append(def.getRaPackage());
+ strMcf.append(".");
+ strMcf.append(def.getMcfDefs().get(num).getMcfClass());
+ strMcf.append("\" ");
+
+ if (def.getMcfDefs().get(num).isUseCciConnection())
+ {
+ strMcf.append("jndi-name=\"java:/eis/");
+ strMcf.append(def.getMcfDefs().get(num).getCciConnFactoryClass());
+ strMcf.append("\" ");
+ strMcf.append("pool-name=\"" + def.getMcfDefs().get(num).getCciConnFactoryClass());
+ }
+ else
+ {
+ strMcf.append("jndi-name=\"java:/eis/");
+ strMcf.append(def.getMcfDefs().get(num).getCfInterfaceClass());
+ strMcf.append("\" ");
+ strMcf.append("pool-name=\"" + def.getMcfDefs().get(num).getCfInterfaceClass());
+ }
+ strMcf.append("\">\n");
+
+ StringBuilder strMcfProps = new StringBuilder();
+ List<ConfigPropType> mcfPropsList = def.getMcfDefs().get(num).getMcfConfigProps();
+ getPropsString(strMcfProps, mcfPropsList, 6);
+ strMcf.append(strMcfProps.toString());
+
+ strMcf.append(" </connection-definition>\n");
+ }
+ strMcf.append(" </connection-definitions>\n");
+
+ StringBuilder strAo = new StringBuilder();
+ if (def.isGenAdminObject())
+ {
+ strAo.append(" <admin-objects>\n");
+ for (int i = 0; i < def.getAdminObjects().size(); i++)
+ {
+ strAo.append(" <admin-object class-name=\"");
+ strAo.append(def.getRaPackage());
+ strAo.append(".");
+ strAo.append(def.getAdminObjects().get(i).getAdminObjectClass());
+ strAo.append("\" jndi-name=\"java:/eis/ao/");
+ strAo.append(def.getAdminObjects().get(i).getAdminObjectInterface());
+ strAo.append("\">\n");
+ getPropsString(strAo, def.getAdminObjects().get(i).getAoConfigProps(), 6);
+ strAo.append(" </admin-object>\n");
+ }
+ strAo.append(" </admin-objects>\n");
+ }
+
+ Map<String, String> map = new HashMap<String, String>();
+ map.put("ra.props", strRaProps.toString());
+ map.put("transaction", def.getSupportTransaction());
+
+ map.put("mcfs", strMcf.toString());
+ map.put("adminobjects", strAo.toString());
+ Template template = new SimpleTemplate(buildString);
+ template.process(map, out);
+ }
+
+ /**
+ * generate properties String
+ *
+ * @param strProps
+ * @param propsList
+ * @param indent
+ */
+ private void getPropsString(StringBuilder strProps, List<ConfigPropType> propsList, int indent)
+ {
+ for (ConfigPropType props : propsList)
+ {
+ for (int i = 0; i < indent; i++)
+ strProps.append(" ");
+ strProps.append("<config-property name=\"");
+ strProps.append(props.getName());
+ strProps.append("\">");
+ strProps.append(props.getValue());
+ strProps.append("</config-property>");
+ strProps.append("\n");
+ }
+ }
+}
Deleted: projects/jboss-jca/tags/IRONJACAMAR_1_0_8_FINAL/codegenerator/src/main/resources/header.template
===================================================================
--- projects/jboss-jca/branches/Branch_1_0/codegenerator/src/main/resources/header.template 2012-02-24 20:13:12 UTC (rev 112694)
+++ projects/jboss-jca/tags/IRONJACAMAR_1_0_8_FINAL/codegenerator/src/main/resources/header.template 2012-03-02 13:22:21 UTC (rev 112723)
@@ -1,21 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2011, 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
Copied: projects/jboss-jca/tags/IRONJACAMAR_1_0_8_FINAL/codegenerator/src/main/resources/header.template (from rev 112698, projects/jboss-jca/branches/Branch_1_0/codegenerator/src/main/resources/header.template)
===================================================================
--- projects/jboss-jca/tags/IRONJACAMAR_1_0_8_FINAL/codegenerator/src/main/resources/header.template (rev 0)
+++ projects/jboss-jca/tags/IRONJACAMAR_1_0_8_FINAL/codegenerator/src/main/resources/header.template 2012-03-02 13:22:21 UTC (rev 112723)
@@ -0,0 +1,21 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2012, 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
Deleted: projects/jboss-jca/tags/IRONJACAMAR_1_0_8_FINAL/codegenerator/src/main/resources/pom.xml.template
===================================================================
--- projects/jboss-jca/branches/Branch_1_0/codegenerator/src/main/resources/pom.xml.template 2012-02-24 20:13:12 UTC (rev 112694)
+++ projects/jboss-jca/tags/IRONJACAMAR_1_0_8_FINAL/codegenerator/src/main/resources/pom.xml.template 2012-03-02 13:22:21 UTC (rev 112723)
@@ -1,139 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
-
- <modelVersion>4.0.0</modelVersion>
- <groupId>${pom.package.name}</groupId>
- <artifactId>${pom.module.name}</artifactId>
- <packaging>jar</packaging>
- <version>0.1</version>
- <url>http://repository.jboss.org</url>
- <properties>
- <version.org.jboss.ironjacamar>@VERSION.IRONJACAMAR@</version.org.jboss.ironjacamar>
- </properties>
-
- <dependencies>
- <dependency>
- <groupId>org.jboss.ironjacamar</groupId>
- <artifactId>ironjacamar-spec-api</artifactId>
- <version>${version.org.jboss.ironjacamar}</version>
- </dependency>
- <dependency>
- <groupId>org.jboss.ironjacamar</groupId>
- <artifactId>ironjacamar-common-api</artifactId>
- <version>${version.org.jboss.ironjacamar}</version>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.jboss.ironjacamar</groupId>
- <artifactId>ironjacamar-common-spi</artifactId>
- <version>${version.org.jboss.ironjacamar}</version>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.jboss.ironjacamar</groupId>
- <artifactId>ironjacamar-common-impl</artifactId>
- <version>${version.org.jboss.ironjacamar}</version>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.jboss.ironjacamar</groupId>
- <artifactId>ironjacamar-common-impl-papaki</artifactId>
- <version>${version.org.jboss.ironjacamar}</version>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.jboss.ironjacamar</groupId>
- <artifactId>ironjacamar-core-api</artifactId>
- <version>${version.org.jboss.ironjacamar}</version>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.jboss.ironjacamar</groupId>
- <artifactId>ironjacamar-core-impl</artifactId>
- <version>${version.org.jboss.ironjacamar}</version>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.jboss.ironjacamar</groupId>
- <artifactId>ironjacamar-depchain</artifactId>
- <version>${version.org.jboss.ironjacamar}</version>
- <scope>test</scope>
- <type>pom</type>
- </dependency>
- <dependency>
- <groupId>org.jboss.ironjacamar</groupId>
- <artifactId>ironjacamar-deployers-common</artifactId>
- <version>${version.org.jboss.ironjacamar}</version>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.jboss.ironjacamar</groupId>
- <artifactId>ironjacamar-deployers-fungal</artifactId>
- <version>${version.org.jboss.ironjacamar}</version>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.jboss.ironjacamar</groupId>
- <artifactId>ironjacamar-embedded-arquillian</artifactId>
- <version>${version.org.jboss.ironjacamar}</version>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.jboss.ironjacamar</groupId>
- <artifactId>ironjacamar-embedded</artifactId>
- <version>${version.org.jboss.ironjacamar}</version>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.jboss.ironjacamar</groupId>
- <artifactId>ironjacamar-validator</artifactId>
- <version>${version.org.jboss.ironjacamar}</version>
- <scope>test</scope>
- </dependency>
-
- <dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <version>4.8.1</version>
- <scope>test</scope>
- </dependency>
- </dependencies>
-
- <dependencyManagement>
- <dependencies>
- <dependency>
- <groupId>org.jboss.ironjacamar</groupId>
- <artifactId>ironjacamar-depchain</artifactId>
- <version>${version.org.jboss.ironjacamar}</version>
- <type>pom</type>
- <scope>import</scope>
- </dependency>
- </dependencies>
- </dependencyManagement>
-
- <build>
- <sourceDirectory>src/main</sourceDirectory>
- <testSourceDirectory>src/test</testSourceDirectory>
- <plugins>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-compiler-plugin</artifactId>
- <configuration>
- <source>1.5</source>
- <target>1.5</target>
- </configuration>
- </plugin>
- </plugins>
- </build>
- <repositories>
- <repository>
- <id>jboss</id>
- <url>http://repository.jboss.org/nexus/content/groups/public</url>
- </repository>
- <repository>
- <id>fungal</id>
- <url>http://jesperpedersen.github.com/fungal/maven2</url>
- </repository>
- </repositories>
-</project>
Copied: projects/jboss-jca/tags/IRONJACAMAR_1_0_8_FINAL/codegenerator/src/main/resources/pom.xml.template (from rev 112698, projects/jboss-jca/branches/Branch_1_0/codegenerator/src/main/resources/pom.xml.template)
===================================================================
--- projects/jboss-jca/tags/IRONJACAMAR_1_0_8_FINAL/codegenerator/src/main/resources/pom.xml.template (rev 0)
+++ projects/jboss-jca/tags/IRONJACAMAR_1_0_8_FINAL/codegenerator/src/main/resources/pom.xml.template 2012-03-02 13:22:21 UTC (rev 112723)
@@ -0,0 +1,169 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>${pom.package.name}</groupId>
+ <artifactId>${pom.module.name}</artifactId>
+ <packaging>jar</packaging>
+ <version>0.1</version>
+ <url>http://repository.jboss.org</url>
+ <properties>
+ <version.org.jboss.ironjacamar>@VERSION.IRONJACAMAR@</version.org.jboss.ironjacamar>
+ </properties>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.jboss.ironjacamar</groupId>
+ <artifactId>ironjacamar-spec-api</artifactId>
+ <version>${version.org.jboss.ironjacamar}</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.ironjacamar</groupId>
+ <artifactId>ironjacamar-common-api</artifactId>
+ <version>${version.org.jboss.ironjacamar}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.ironjacamar</groupId>
+ <artifactId>ironjacamar-common-spi</artifactId>
+ <version>${version.org.jboss.ironjacamar}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.ironjacamar</groupId>
+ <artifactId>ironjacamar-common-impl</artifactId>
+ <version>${version.org.jboss.ironjacamar}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.ironjacamar</groupId>
+ <artifactId>ironjacamar-common-impl-papaki</artifactId>
+ <version>${version.org.jboss.ironjacamar}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.ironjacamar</groupId>
+ <artifactId>ironjacamar-core-api</artifactId>
+ <version>${version.org.jboss.ironjacamar}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.ironjacamar</groupId>
+ <artifactId>ironjacamar-core-impl</artifactId>
+ <version>${version.org.jboss.ironjacamar}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.ironjacamar</groupId>
+ <artifactId>ironjacamar-depchain</artifactId>
+ <version>${version.org.jboss.ironjacamar}</version>
+ <scope>test</scope>
+ <type>pom</type>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.ironjacamar</groupId>
+ <artifactId>ironjacamar-deployers-common</artifactId>
+ <version>${version.org.jboss.ironjacamar}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.ironjacamar</groupId>
+ <artifactId>ironjacamar-deployers-fungal</artifactId>
+ <version>${version.org.jboss.ironjacamar}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.ironjacamar</groupId>
+ <artifactId>ironjacamar-embedded-arquillian</artifactId>
+ <version>${version.org.jboss.ironjacamar}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.ironjacamar</groupId>
+ <artifactId>ironjacamar-embedded</artifactId>
+ <version>${version.org.jboss.ironjacamar}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.ironjacamar</groupId>
+ <artifactId>ironjacamar-validator</artifactId>
+ <version>${version.org.jboss.ironjacamar}</version>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>4.8.1</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <dependencyManagement>
+ <dependencies>
+ <dependency>
+ <groupId>org.jboss.ironjacamar</groupId>
+ <artifactId>ironjacamar-depchain</artifactId>
+ <version>${version.org.jboss.ironjacamar}</version>
+ <type>pom</type>
+ <scope>import</scope>
+ </dependency>
+ </dependencies>
+ </dependencyManagement>
+
+ <build>
+ <sourceDirectory>src/main</sourceDirectory>
+ <testSourceDirectory>src/test</testSourceDirectory>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <version>2.3.2</version>
+ <configuration>
+ <source>1.5</source>
+ <target>1.5</target>
+ </configuration>
+ </plugin>
+
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-jar-plugin</artifactId>
+ <version>2.4</version>
+ <configuration>
+ <excludes>
+ <exclude>**/META-INF/*</exclude>
+ </excludes>
+ </configuration>
+ </plugin>
+
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-rar-plugin</artifactId>
+ <version>2.2</version>
+ <executions>
+ <execution>
+ <id>test</id>
+ <goals>
+ <goal>rar</goal>
+ </goals>
+ <configuration>
+ <raXmlFile>src/main/resources/META-INF/ra.xml</raXmlFile>
+ </configuration>
+ </execution></executions>
+ </plugin>
+
+ </plugins>
+ </build>
+ <repositories>
+ <repository>
+ <id>jboss</id>
+ <url>http://repository.jboss.org/nexus/content/groups/public</url>
+ </repository>
+ <repository>
+ <id>fungal</id>
+ <url>http://jesperpedersen.github.com/fungal/maven2</url>
+ </repository>
+ </repositories>
+</project>
Deleted: projects/jboss-jca/tags/IRONJACAMAR_1_0_8_FINAL/core/src/main/java/org/jboss/jca/core/rar/EndpointImpl.java
===================================================================
--- projects/jboss-jca/branches/Branch_1_0/core/src/main/java/org/jboss/jca/core/rar/EndpointImpl.java 2012-02-24 20:13:12 UTC (rev 112694)
+++ projects/jboss-jca/tags/IRONJACAMAR_1_0_8_FINAL/core/src/main/java/org/jboss/jca/core/rar/EndpointImpl.java 2012-03-02 13:22:21 UTC (rev 112723)
@@ -1,171 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2011, 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.core.rar;
-
-import org.jboss.jca.core.CoreBundle;
-import org.jboss.jca.core.CoreLogger;
-import org.jboss.jca.core.bv.BeanValidationUtil;
-import org.jboss.jca.core.spi.rar.Endpoint;
-
-import java.lang.ref.WeakReference;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Set;
-
-import javax.resource.ResourceException;
-import javax.resource.spi.ActivationSpec;
-import javax.resource.spi.ResourceAdapter;
-import javax.resource.spi.endpoint.MessageEndpointFactory;
-import javax.validation.ConstraintViolationException;
-import javax.validation.Validator;
-import javax.validation.groups.Default;
-
-import org.jboss.logging.Messages;
-import org.jboss.logging.Logger;
-
-/**
- * An endpoint representation
- *
- * @author <a href="mailto:jesper.pedersen at jboss.org">Jesper Pedersen</a>
- */
-public class EndpointImpl implements Endpoint
-{
- /** The reference to the resource adapter instance */
- private WeakReference<ResourceAdapter> ra;
-
- /** Is the resource adapter a 1.6 archive */
- private boolean is16;
-
- /** Bean validation groups */
- private Set<String> beanValidationGroups;
-
- /** The bundle */
- private static CoreBundle bundle = Messages.getBundle(CoreBundle.class);
-
- /** The logger */
- private static CoreLogger log = Logger.getMessageLogger(CoreLogger.class, Endpoint.class.getName());
-
- /**
- * Constructor
- * @param ra The resource adapter reference
- * @param is26 Is the resource adapter a 1.6 archive
- * @param bvg The bean validation groups
- */
- EndpointImpl(WeakReference<ResourceAdapter> ra, boolean is16, Set<String> bvg)
- {
- this.ra = ra;
- this.is16 = is16;
- this.beanValidationGroups = bvg;
- }
-
- /**
- * {@inheritDoc}
- */
- @SuppressWarnings("unchecked")
- public void activate(MessageEndpointFactory endpointFactory,
- ActivationSpec spec) throws ResourceException
- {
- if (endpointFactory == null)
- throw new IllegalArgumentException("MessageEndpointFactory is null");
-
- if (spec == null)
- throw new IllegalArgumentException("ActivationSpec is null");
-
- ResourceAdapter rar = ra.get();
-
- if (rar == null)
- throw new ResourceException(bundle.resourceAdapterInstanceNotActive());
-
- spec.validate();
-
- if (is16)
- {
- ClassLoader oldTCCL = SecurityActions.getThreadContextClassLoader();
- try
- {
- SecurityActions.setThreadContextClassLoader(rar.getClass().getClassLoader());
-
- List<Class<?>> groups = new ArrayList<Class<?>>(1);
-
- if (beanValidationGroups != null)
- {
- for (String group : beanValidationGroups)
- {
- try
- {
- Class<?> clz = Class.forName(group, true, rar.getClass().getClassLoader());
- groups.add(clz);
- }
- catch (Throwable t)
- {
- log.debug("Unable to load bean validation group: " + group, t);
- }
- }
- }
-
- if (groups.isEmpty())
- groups.add(Default.class);
-
- Validator validator = BeanValidationUtil.createValidator();
- Class[] vargs = groups.toArray(new Class[groups.size()]);
-
- Set errors = validator.validate(spec, vargs);
-
- if (errors != null && errors.size() > 0)
- {
- throw new ResourceException(bundle.validationException(), new ConstraintViolationException(errors));
- }
- }
- catch (RuntimeException re)
- {
- throw new ResourceException(bundle.validationException(), re);
- }
- finally
- {
- SecurityActions.setThreadContextClassLoader(oldTCCL);
- }
- }
-
- rar.endpointActivation(endpointFactory, spec);
- }
-
- /**
- * {@inheritDoc}
- */
- public void deactivate(MessageEndpointFactory endpointFactory,
- ActivationSpec spec) throws ResourceException
- {
- if (endpointFactory == null)
- throw new IllegalArgumentException("MessageEndpointFactory is null");
-
- if (spec == null)
- throw new IllegalArgumentException("ActivationSpec is null");
-
- ResourceAdapter rar = ra.get();
-
- if (rar == null)
- throw new ResourceException(bundle.resourceAdapterInstanceNotActive());
-
- rar.endpointDeactivation(endpointFactory, spec);
- }
-}
Copied: projects/jboss-jca/tags/IRONJACAMAR_1_0_8_FINAL/core/src/main/java/org/jboss/jca/core/rar/EndpointImpl.java (from rev 112697, projects/jboss-jca/branches/Branch_1_0/core/src/main/java/org/jboss/jca/core/rar/EndpointImpl.java)
===================================================================
--- projects/jboss-jca/tags/IRONJACAMAR_1_0_8_FINAL/core/src/main/java/org/jboss/jca/core/rar/EndpointImpl.java (rev 0)
+++ projects/jboss-jca/tags/IRONJACAMAR_1_0_8_FINAL/core/src/main/java/org/jboss/jca/core/rar/EndpointImpl.java 2012-03-02 13:22:21 UTC (rev 112723)
@@ -0,0 +1,179 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2011, 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.core.rar;
+
+import org.jboss.jca.core.CoreBundle;
+import org.jboss.jca.core.CoreLogger;
+import org.jboss.jca.core.bv.BeanValidationUtil;
+import org.jboss.jca.core.spi.rar.Endpoint;
+
+import java.lang.ref.WeakReference;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Set;
+
+import javax.resource.ResourceException;
+import javax.resource.spi.ActivationSpec;
+import javax.resource.spi.ResourceAdapter;
+import javax.resource.spi.endpoint.MessageEndpointFactory;
+import javax.validation.ConstraintViolationException;
+import javax.validation.Validator;
+import javax.validation.groups.Default;
+
+import org.jboss.logging.Messages;
+import org.jboss.logging.Logger;
+
+/**
+ * An endpoint representation
+ *
+ * @author <a href="mailto:jesper.pedersen at jboss.org">Jesper Pedersen</a>
+ */
+public class EndpointImpl implements Endpoint
+{
+ /** The reference to the resource adapter instance */
+ private WeakReference<ResourceAdapter> ra;
+
+ /** Is the resource adapter a 1.6 archive */
+ private boolean is16;
+
+ /** Bean validation groups */
+ private Set<String> beanValidationGroups;
+
+ /** The bundle */
+ private static CoreBundle bundle = Messages.getBundle(CoreBundle.class);
+
+ /** The logger */
+ private static CoreLogger log = Logger.getMessageLogger(CoreLogger.class, Endpoint.class.getName());
+
+ /** Is bean validation for inflow enabled */
+ private static boolean bvEnabled;
+
+ static
+ {
+ bvEnabled = Boolean.valueOf(SecurityActions.getSystemProperty("ironjacamar.bv.inflow", "true"));
+ }
+
+ /**
+ * Constructor
+ * @param ra The resource adapter reference
+ * @param is26 Is the resource adapter a 1.6 archive
+ * @param bvg The bean validation groups
+ */
+ EndpointImpl(WeakReference<ResourceAdapter> ra, boolean is16, Set<String> bvg)
+ {
+ this.ra = ra;
+ this.is16 = is16;
+ this.beanValidationGroups = bvg;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @SuppressWarnings("unchecked")
+ public void activate(MessageEndpointFactory endpointFactory,
+ ActivationSpec spec) throws ResourceException
+ {
+ if (endpointFactory == null)
+ throw new IllegalArgumentException("MessageEndpointFactory is null");
+
+ if (spec == null)
+ throw new IllegalArgumentException("ActivationSpec is null");
+
+ ResourceAdapter rar = ra.get();
+
+ if (rar == null)
+ throw new ResourceException(bundle.resourceAdapterInstanceNotActive());
+
+ spec.validate();
+
+ if (is16 && bvEnabled)
+ {
+ ClassLoader oldTCCL = SecurityActions.getThreadContextClassLoader();
+ try
+ {
+ SecurityActions.setThreadContextClassLoader(rar.getClass().getClassLoader());
+
+ List<Class<?>> groups = new ArrayList<Class<?>>(1);
+
+ if (beanValidationGroups != null)
+ {
+ for (String group : beanValidationGroups)
+ {
+ try
+ {
+ Class<?> clz = Class.forName(group, true, rar.getClass().getClassLoader());
+ groups.add(clz);
+ }
+ catch (Throwable t)
+ {
+ log.debug("Unable to load bean validation group: " + group, t);
+ }
+ }
+ }
+
+ if (groups.isEmpty())
+ groups.add(Default.class);
+
+ Validator validator = BeanValidationUtil.createValidator();
+ Class[] vargs = groups.toArray(new Class[groups.size()]);
+
+ Set errors = validator.validate(spec, vargs);
+
+ if (errors != null && errors.size() > 0)
+ {
+ throw new ResourceException(bundle.validationException(), new ConstraintViolationException(errors));
+ }
+ }
+ catch (RuntimeException re)
+ {
+ throw new ResourceException(bundle.validationException(), re);
+ }
+ finally
+ {
+ SecurityActions.setThreadContextClassLoader(oldTCCL);
+ }
+ }
+
+ rar.endpointActivation(endpointFactory, spec);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void deactivate(MessageEndpointFactory endpointFactory,
+ ActivationSpec spec) throws ResourceException
+ {
+ if (endpointFactory == null)
+ throw new IllegalArgumentException("MessageEndpointFactory is null");
+
+ if (spec == null)
+ throw new IllegalArgumentException("ActivationSpec is null");
+
+ ResourceAdapter rar = ra.get();
+
+ if (rar == null)
+ throw new ResourceException(bundle.resourceAdapterInstanceNotActive());
+
+ rar.endpointDeactivation(endpointFactory, spec);
+ }
+}
Deleted: projects/jboss-jca/tags/IRONJACAMAR_1_0_8_FINAL/core/src/main/java/org/jboss/jca/core/rar/SecurityActions.java
===================================================================
--- projects/jboss-jca/branches/Branch_1_0/core/src/main/java/org/jboss/jca/core/rar/SecurityActions.java 2012-02-24 20:13:12 UTC (rev 112694)
+++ projects/jboss-jca/tags/IRONJACAMAR_1_0_8_FINAL/core/src/main/java/org/jboss/jca/core/rar/SecurityActions.java 2012-03-02 13:22:21 UTC (rev 112723)
@@ -1,80 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2012, 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.core.rar;
-
-import java.security.AccessController;
-import java.security.PrivilegedAction;
-
-/**
- * Privileged Blocks
- *
- * @author <a href="mailto:jesper.pedersen at jboss.org">Jesper Pedersen</a>
- */
-class SecurityActions
-{
- /**
- * Set the context classloader.
- * @param cl classloader
- */
- public static void setThreadContextClassLoader(final ClassLoader cl)
- {
- if (System.getSecurityManager() == null)
- {
- Thread.currentThread().setContextClassLoader(cl);
- }
- else
- {
- AccessController.doPrivileged(new PrivilegedAction<Object>()
- {
- public Object run()
- {
- Thread.currentThread().setContextClassLoader(cl);
-
- return null;
- }
- });
- }
- }
-
- /**
- * Get the context classloader.
- * @return The classloader
- */
- public static ClassLoader getThreadContextClassLoader()
- {
- if (System.getSecurityManager() == null)
- {
- return Thread.currentThread().getContextClassLoader();
- }
- else
- {
- return AccessController.doPrivileged(new PrivilegedAction<ClassLoader>()
- {
- public ClassLoader run()
- {
- return Thread.currentThread().getContextClassLoader();
- }
- });
- }
- }
-}
Copied: projects/jboss-jca/tags/IRONJACAMAR_1_0_8_FINAL/core/src/main/java/org/jboss/jca/core/rar/SecurityActions.java (from rev 112697, projects/jboss-jca/branches/Branch_1_0/core/src/main/java/org/jboss/jca/core/rar/SecurityActions.java)
===================================================================
--- projects/jboss-jca/tags/IRONJACAMAR_1_0_8_FINAL/core/src/main/java/org/jboss/jca/core/rar/SecurityActions.java (rev 0)
+++ projects/jboss-jca/tags/IRONJACAMAR_1_0_8_FINAL/core/src/main/java/org/jboss/jca/core/rar/SecurityActions.java 2012-03-02 13:22:21 UTC (rev 112723)
@@ -0,0 +1,97 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2012, 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.core.rar;
+
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+
+/**
+ * Privileged Blocks
+ *
+ * @author <a href="mailto:jesper.pedersen at jboss.org">Jesper Pedersen</a>
+ */
+class SecurityActions
+{
+ /**
+ * Set the context classloader.
+ * @param cl classloader
+ */
+ public static void setThreadContextClassLoader(final ClassLoader cl)
+ {
+ if (System.getSecurityManager() == null)
+ {
+ Thread.currentThread().setContextClassLoader(cl);
+ }
+ else
+ {
+ AccessController.doPrivileged(new PrivilegedAction<Object>()
+ {
+ public Object run()
+ {
+ Thread.currentThread().setContextClassLoader(cl);
+
+ return null;
+ }
+ });
+ }
+ }
+
+ /**
+ * Get the context classloader.
+ * @return The classloader
+ */
+ public static ClassLoader getThreadContextClassLoader()
+ {
+ if (System.getSecurityManager() == null)
+ {
+ return Thread.currentThread().getContextClassLoader();
+ }
+ else
+ {
+ return AccessController.doPrivileged(new PrivilegedAction<ClassLoader>()
+ {
+ public ClassLoader run()
+ {
+ return Thread.currentThread().getContextClassLoader();
+ }
+ });
+ }
+ }
+
+ /**
+ * Get a system property
+ * @param name The property name
+ * @param value The default property value
+ * @return The property value
+ */
+ static String getSystemProperty(final String name, final String value)
+ {
+ return AccessController.doPrivileged(new PrivilegedAction<String>()
+ {
+ public String run()
+ {
+ return System.getProperty(name, value);
+ }
+ });
+ }
+}
More information about the jboss-cvs-commits
mailing list