Java Code Examples for org.mybatis.generator.api.dom.xml.Document#setRootElement()

The following examples show how to use org.mybatis.generator.api.dom.xml.Document#setRootElement() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Configuration.java    From mybatis-generator-core-fix with Apache License 2.0 6 votes vote down vote up
/**
 * Builds an XML representation of this configuration. This can be used to
 * persist a programmatically generated configuration.
 * 
 * @return the XML representation of this configuration
 */
public Document toDocument() {
    // note that this method will not reconstruct a properties
    // element - that element is only used in XML parsing

    Document document = new Document(
            XmlConstants.MYBATIS_GENERATOR_CONFIG_PUBLIC_ID,
            XmlConstants.MYBATIS_GENERATOR_CONFIG_SYSTEM_ID);
    XmlElement rootElement = new XmlElement("generatorConfiguration"); //$NON-NLS-1$
    document.setRootElement(rootElement);

    for (String classPathEntry : classPathEntries) {
        XmlElement cpeElement = new XmlElement("classPathEntry"); //$NON-NLS-1$
        cpeElement.addAttribute(new Attribute("location", classPathEntry)); //$NON-NLS-1$
        rootElement.addElement(cpeElement);
    }

    for (Context context : contexts) {
        rootElement.addElement(context.toXmlElement());
    }

    return document;
}
 
Example 2
Source File: Configuration.java    From mybatis-generator-plus with Apache License 2.0 6 votes vote down vote up
/**
 * Builds an XML representation of this configuration. This can be used to
 * persist a programtically generated configuration.
 * 
 * @return the XML representation of this configuration
 */
public Document toDocument() {
    // note that this method will not reconstruct a properties
    // element - that element is only used in XML parsing

    Document document = new Document(
            XmlConstants.MYBATIS_GENERATOR_CONFIG_PUBLIC_ID,
            XmlConstants.MYBATIS_GENERATOR_CONFIG_SYSTEM_ID);
    XmlElement rootElement = new XmlElement("generatorConfiguration"); //$NON-NLS-1$
    document.setRootElement(rootElement);

    for (String classPathEntry : classPathEntries) {
        XmlElement cpeElement = new XmlElement("classPathEntry"); //$NON-NLS-1$
        cpeElement.addAttribute(new Attribute("location", classPathEntry)); //$NON-NLS-1$
        rootElement.addElement(cpeElement);
    }

    for (Context context : contexts) {
        rootElement.addElement(context.toXmlElement());
    }

    return document;
}
 
Example 3
Source File: SimpleXMLMapperGenerator.java    From mapper-generator-javafx with Apache License 2.0 5 votes vote down vote up
@Override
public Document getDocument() {
    Document document = new Document(
            XmlConstants.MYBATIS3_MAPPER_PUBLIC_ID,
            XmlConstants.MYBATIS3_MAPPER_SYSTEM_ID);
    document.setRootElement(getSqlMapElement());

    if (!context.getPlugins().sqlMapDocumentGenerated(document,
            introspectedTable)) {
        document = null;
    }

    return document;
}
 
Example 4
Source File: XMLMapperGenerator.java    From mapper-generator-javafx with Apache License 2.0 5 votes vote down vote up
@Override
public Document getDocument() {
    Document document = new Document(
            XmlConstants.MYBATIS3_MAPPER_PUBLIC_ID,
            XmlConstants.MYBATIS3_MAPPER_SYSTEM_ID);
    document.setRootElement(getSqlMapElement());

    if (!context.getPlugins().sqlMapDocumentGenerated(document,
            introspectedTable)) {
        document = null;
    }

    return document;
}
 
Example 5
Source File: SqlMapGenerator.java    From mybatis-generator-core-fix with Apache License 2.0 5 votes vote down vote up
@Override
public Document getDocument() {
    Document document = new Document(
            XmlConstants.IBATIS2_SQL_MAP_PUBLIC_ID,
            XmlConstants.IBATIS2_SQL_MAP_SYSTEM_ID);
    document.setRootElement(getSqlMapElement());

    if (!context.getPlugins().sqlMapDocumentGenerated(document,
            introspectedTable)) {
        document = null;
    }

    return document;
}
 
Example 6
Source File: SimpleXMLMapperGenerator.java    From mybatis-generator-core-fix with Apache License 2.0 5 votes vote down vote up
@Override
public Document getDocument() {
    Document document = new Document(
            XmlConstants.MYBATIS3_MAPPER_PUBLIC_ID,
            XmlConstants.MYBATIS3_MAPPER_SYSTEM_ID);
    document.setRootElement(getSqlMapElement());

    if (!context.getPlugins().sqlMapDocumentGenerated(document,
            introspectedTable)) {
        document = null;
    }

    return document;
}
 
Example 7
Source File: XMLMapperGenerator.java    From mybatis-generator-core-fix with Apache License 2.0 5 votes vote down vote up
@Override
public Document getDocument() {
    Document document = new Document(
            XmlConstants.MYBATIS3_MAPPER_PUBLIC_ID,
            XmlConstants.MYBATIS3_MAPPER_SYSTEM_ID);
    document.setRootElement(getSqlMapElement());

    if (!context.getPlugins().sqlMapDocumentGenerated(document,
            introspectedTable)) {
        document = null;
    }

    return document;
}
 
Example 8
Source File: SqlMapGenerator.java    From mybatis-generator-plus with Apache License 2.0 5 votes vote down vote up
@Override
public Document getDocument() {
    Document document = new Document(
            XmlConstants.IBATIS2_SQL_MAP_PUBLIC_ID,
            XmlConstants.IBATIS2_SQL_MAP_SYSTEM_ID);
    document.setRootElement(getSqlMapElement());

    if (!context.getPlugins().sqlMapDocumentGenerated(document,
            introspectedTable)) {
        document = null;
    }

    return document;
}
 
Example 9
Source File: SimpleXMLMapperGenerator.java    From mybatis-generator-plus with Apache License 2.0 5 votes vote down vote up
@Override
public Document getDocument() {
    Document document = new Document(
            XmlConstants.MYBATIS3_MAPPER_PUBLIC_ID,
            XmlConstants.MYBATIS3_MAPPER_SYSTEM_ID);
    document.setRootElement(getSqlMapElement());

    if (!context.getPlugins().sqlMapDocumentGenerated(document,
            introspectedTable)) {
        document = null;
    }

    return document;
}
 
Example 10
Source File: XMLMapperGenerator.java    From mybatis-generator-plus with Apache License 2.0 5 votes vote down vote up
@Override
public Document getDocument() {
    Document document = new Document(
            XmlConstants.MYBATIS3_MAPPER_PUBLIC_ID,
            XmlConstants.MYBATIS3_MAPPER_SYSTEM_ID);
    document.setRootElement(getSqlMapElement());

    if (!context.getPlugins().sqlMapDocumentGenerated(document,
            introspectedTable)) {
        document = null;
    }

    return document;
}
 
Example 11
Source File: DAOPlugin.java    From maven-archetype with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * contextGenerateAdditionalXmlFiles:. <br/>
 *
 * @author Hongbin Yuan
 * @param introspectedTable
 * @return
 * @see PluginAdapter#contextGenerateAdditionalXmlFiles(IntrospectedTable)
 */
@Override
public List<GeneratedXmlFile> contextGenerateAdditionalXmlFiles(
		IntrospectedTable introspectedTable) {
	// 设置文件类型,DAO 的xml文件, 原命名空间,用设置的值替换
	String  xmlMapperNamespace = introspectedTable.getMyBatis3SqlMapNamespace();
	String typeNameProp = this.getProperties().getProperty("typeName");
	if(typeNameProp == null || "".equals(typeNameProp.trim())){
		typeNameProp = typeName;
	}
	xmlMapperNamespace = xmlMapperNamespace.replaceAll("Mapper$",typeNameProp);
	
	// 创建mapper文件,
	Document document = new Document(
                XmlConstants.MYBATIS3_MAPPER_PUBLIC_ID,
                XmlConstants.MYBATIS3_MAPPER_SYSTEM_ID);
	// 创建根 root元素
	XmlElement root = new XmlElement("mapper"); //$NON-NLS-1$
       root.addAttribute(new Attribute("namespace", //$NON-NLS-1$
       		xmlMapperNamespace));
       
       context.getCommentGenerator().addRootComment(root);
       document.setRootElement(root);

       // 像root添加一个空元素
       root.addElement(new TextElement("\n"));
       
       String xmlMapperName = introspectedTable.getMyBatis3XmlMapperFileName();
       xmlMapperName = xmlMapperName.replaceAll("Mapper.xml$",typeNameProp+".xml");
	GeneratedXmlFile gxf = new GeneratedXmlFile(document,
			xmlMapperName, introspectedTable.getMyBatis3XmlMapperPackage(),
               context.getSqlMapGeneratorConfiguration().getTargetProject(),
               true, context.getXmlFormatter());
	List<GeneratedXmlFile>  gxfList = new ArrayList<GeneratedXmlFile>();
       
	gxfList.add(gxf);
       
	return gxfList;
}