Hi guys,

I have an Ibator plugin that creates a spring config file per table, it works 
fine but I wanted to know if there was a way a could modify it to create a 
single file for all tables instead.

Thanks,
Amar!

import java.util.ArrayList;
import java.util.List;

import org.apache.ibatis.ibator.api.GeneratedXmlFile;
import org.apache.ibatis.ibator.api.IbatorPluginAdapter;
import org.apache.ibatis.ibator.api.IntrospectedTable;
import org.apache.ibatis.ibator.api.dom.java.TopLevelClass;
import org.apache.ibatis.ibator.api.dom.xml.Attribute;
import org.apache.ibatis.ibator.api.dom.xml.Document;
import org.apache.ibatis.ibator.api.dom.xml.XmlElement;

public class SpringTableConfigPlugin extends IbatorPluginAdapter {

                TopLevelClass topLevelClass;
                String fileName;
                String targetPackage = "config.spring";
                String targetProject = "C:/workspace/ibatisproj";
                boolean isMergeable = false;

                public boolean validate(List<String> arg0) {
                                return true;
                }

                public List<GeneratedXmlFile> 
contextGenerateAdditionalXmlFiles(IntrospectedTable introspectedTable) {

                                String domainObjectName = 
introspectedTable.getFullyQualifiedTable().getDomainObjectName();

                                fileName = 
"Spring"+domainObjectName+"Config.xml";

                                Document document = new Document();

                                XmlElement rootElement = new 
XmlElement("beans");

                                rootElement.addAttribute(new Attribute("xmlns", 
"http://www.springframework.org/schema/beans";));
                                rootElement.addAttribute(new 
Attribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance";));
                                rootElement.addAttribute(new 
Attribute("xmlns:aop", "http://www.springframework.org/schema/aop";));
                                rootElement.addAttribute(new 
Attribute("xmlns:tx", "http://www.springframework.org/schema/tx";));
                                rootElement.addAttribute(new 
Attribute("xmlns:context", "http://www.springframework.org/schema/context";));
                                rootElement.addAttribute(new 
Attribute("xsi:schemaLocation", "http://www.springframework.org/schema/beans 
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd\nhttp://www.springframework.org/schema/tx
 
http://www.springframework.org/schema/tx/spring-tx-2.0.xsd\nhttp://www.springframework.org/schema/aop
 
http://www.springframework.org/schema/aop/spring-aop-2.0.xsd\nhttp://www.springframework.org/schema/context
 http://www.springframework.org/schema/context/spring-context-2.5.xsd";));

                                document.setRootElement(rootElement);

                                XmlElement beanElement = new XmlElement("bean");
                                beanElement.addAttribute(new Attribute("id", 
domainObjectName));
                                beanElement.addAttribute(new Attribute("class", 
"com.test.ibatisproj.daoImpl."+domainObjectName+"DAOImpl"));

                                XmlElement propertyElement = new 
XmlElement("property");
                                propertyElement.addAttribute(new 
Attribute("name", "sqlMapClient"));
                                propertyElement.addAttribute(new 
Attribute("ref", "sqlMapClient"));

                                beanElement.addElement(propertyElement);

                                rootElement.addElement(beanElement);

                                List<GeneratedXmlFile> generatedXmlFileList = 
new ArrayList<GeneratedXmlFile>();

                                GeneratedXmlFile springTableConfigXml = new 
GeneratedXmlFile(document, fileName, targetPackage, targetProject, isMergeable 
);

                                generatedXmlFileList.add(springTableConfigXml);

                                return generatedXmlFileList;

                }

}


This email is confidential and subject to important disclaimers and
conditions including on offers for the purchase or sale of
securities, accuracy and completeness of information, viruses,
confidentiality, legal privilege, and legal entity disclaimers,
available at http://www.jpmorgan.com/pages/disclosures/email.  

Reply via email to