Search in sources :

Example 1 with Document

use of org.mybatis.generator.api.dom.xml.Document in project generator by mybatis.

the class IntrospectedTableMyBatis3Impl method getGeneratedXmlFiles.

/* (non-Javadoc)
     * @see org.mybatis.generator.api.IntrospectedTable#getGeneratedXmlFiles()
     */
@Override
public List<GeneratedXmlFile> getGeneratedXmlFiles() {
    List<GeneratedXmlFile> answer = new ArrayList<GeneratedXmlFile>();
    if (xmlMapperGenerator != null) {
        Document document = xmlMapperGenerator.getDocument();
        GeneratedXmlFile gxf = new GeneratedXmlFile(document, getMyBatis3XmlMapperFileName(), getMyBatis3XmlMapperPackage(), context.getSqlMapGeneratorConfiguration().getTargetProject(), true, context.getXmlFormatter());
        if (context.getPlugins().sqlMapGenerated(gxf, this)) {
            answer.add(gxf);
        }
    }
    return answer;
}
Also used : ArrayList(java.util.ArrayList) Document(org.mybatis.generator.api.dom.xml.Document) GeneratedXmlFile(org.mybatis.generator.api.GeneratedXmlFile)

Example 2 with Document

use of org.mybatis.generator.api.dom.xml.Document in project generator by mybatis.

the class SimpleXMLMapperGenerator method getDocument.

@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;
}
Also used : Document(org.mybatis.generator.api.dom.xml.Document)

Example 3 with Document

use of org.mybatis.generator.api.dom.xml.Document in project generator by mybatis.

the class AntFileGenerator method getAntFileContent.

public String getAntFileContent() {
    Document document = new Document();
    document.setRootElement(getProjectElement());
    return document.getFormattedContent();
}
Also used : Document(org.mybatis.generator.api.dom.xml.Document)

Example 4 with Document

use of org.mybatis.generator.api.dom.xml.Document in project generator by mybatis.

the class NewConfigFileWizard method openContentStream.

/**
     * We will initialize file contents with a sample text.
     */
private InputStream openContentStream() {
    Document document = new Document(XmlConstants.MYBATIS_GENERATOR_CONFIG_PUBLIC_ID, XmlConstants.MYBATIS_GENERATOR_CONFIG_SYSTEM_ID);
    //$NON-NLS-1$
    XmlElement generatorConfiguration = new XmlElement("generatorConfiguration");
    document.setRootElement(generatorConfiguration);
    //$NON-NLS-1$
    XmlElement context = new XmlElement("context");
    //$NON-NLS-1$ //$NON-NLS-2$
    context.addAttribute(new Attribute("id", "context1"));
    generatorConfiguration.addElement(context);
    //$NON-NLS-1$
    XmlElement jdbcConnection = new XmlElement("jdbcConnection");
    //$NON-NLS-1$ //$NON-NLS-2$
    jdbcConnection.addAttribute(new Attribute("driverClass", "???"));
    //$NON-NLS-1$ //$NON-NLS-2$
    jdbcConnection.addAttribute(new Attribute("connectionURL", "???"));
    //$NON-NLS-1$ //$NON-NLS-2$
    jdbcConnection.addAttribute(new Attribute("userId", "???"));
    //$NON-NLS-1$ //$NON-NLS-2$
    jdbcConnection.addAttribute(new Attribute("password", "???"));
    context.addElement(jdbcConnection);
    //$NON-NLS-1$
    XmlElement javaModelGenerator = new XmlElement("javaModelGenerator");
    //$NON-NLS-1$ //$NON-NLS-2$
    javaModelGenerator.addAttribute(new Attribute("targetPackage", "???"));
    //$NON-NLS-1$ //$NON-NLS-2$
    javaModelGenerator.addAttribute(new Attribute("targetProject", "???"));
    context.addElement(javaModelGenerator);
    //$NON-NLS-1$
    XmlElement sqlMapGenerator = new XmlElement("sqlMapGenerator");
    //$NON-NLS-1$ //$NON-NLS-2$
    sqlMapGenerator.addAttribute(new Attribute("targetPackage", "???"));
    //$NON-NLS-1$ //$NON-NLS-2$
    sqlMapGenerator.addAttribute(new Attribute("targetProject", "???"));
    context.addElement(sqlMapGenerator);
    //$NON-NLS-1$
    XmlElement javaClientGenerator = new XmlElement("javaClientGenerator");
    //$NON-NLS-1$ //$NON-NLS-2$
    javaClientGenerator.addAttribute(new Attribute("targetPackage", "???"));
    //$NON-NLS-1$ //$NON-NLS-2$
    javaClientGenerator.addAttribute(new Attribute("targetProject", "???"));
    //$NON-NLS-1$ //$NON-NLS-2$
    javaClientGenerator.addAttribute(new Attribute("type", "XMLMAPPER"));
    context.addElement(javaClientGenerator);
    //$NON-NLS-1$
    XmlElement table = new XmlElement("table");
    //$NON-NLS-1$ //$NON-NLS-2$
    table.addAttribute(new Attribute("schema", "???"));
    //$NON-NLS-1$ //$NON-NLS-2$
    table.addAttribute(new Attribute("tableName", "???"));
    //$NON-NLS-1$
    XmlElement columnOverride = new XmlElement("columnOverride");
    //$NON-NLS-1$ //$NON-NLS-2$
    columnOverride.addAttribute(new Attribute("column", "???"));
    //$NON-NLS-1$ //$NON-NLS-2$
    columnOverride.addAttribute(new Attribute("property", "???"));
    table.addElement(columnOverride);
    context.addElement(table);
    return new ByteArrayInputStream(document.getFormattedContent().getBytes());
}
Also used : Attribute(org.mybatis.generator.api.dom.xml.Attribute) ByteArrayInputStream(java.io.ByteArrayInputStream) XmlElement(org.mybatis.generator.api.dom.xml.XmlElement) Document(org.mybatis.generator.api.dom.xml.Document)

Example 5 with Document

use of org.mybatis.generator.api.dom.xml.Document in project generator by mybatis.

the class XmlFileMergerTest method testThatFilesAreTheSameAfterMerge.

@Test
public void testThatFilesAreTheSameAfterMerge() throws Exception {
    DefaultXmlFormatter xmlFormatter = new DefaultXmlFormatter();
    Properties p = new Properties();
    p.setProperty(PropertyRegistry.COMMENT_GENERATOR_SUPPRESS_DATE, "true");
    CommentGenerator commentGenerator = new DefaultCommentGenerator();
    commentGenerator.addConfigurationProperties(p);
    Document document = new Document(XmlConstants.MYBATIS3_MAPPER_PUBLIC_ID, XmlConstants.MYBATIS3_MAPPER_SYSTEM_ID);
    document.setRootElement(getSqlMapElement(commentGenerator));
    GeneratedXmlFile generatedFile1 = new GeneratedXmlFile(document, "TestMapper.xml", "org.mybatis.test", "src", true, xmlFormatter);
    InputSource is1 = new InputSource(new StringReader(generatedFile1.getFormattedContent()));
    GeneratedXmlFile generatedFile2 = new GeneratedXmlFile(document, "TestMapper.xml", "org.mybatis.test", "src", true, xmlFormatter);
    InputSource is2 = new InputSource(new StringReader(generatedFile2.getFormattedContent()));
    String mergedSource = XmlFileMergerJaxp.getMergedSource(is1, is2, "TestMapper.xml");
    assertEquals(generatedFile1.getFormattedContent(), mergedSource);
}
Also used : DefaultXmlFormatter(org.mybatis.generator.api.dom.DefaultXmlFormatter) InputSource(org.xml.sax.InputSource) CommentGenerator(org.mybatis.generator.api.CommentGenerator) StringReader(java.io.StringReader) Properties(java.util.Properties) Document(org.mybatis.generator.api.dom.xml.Document) GeneratedXmlFile(org.mybatis.generator.api.GeneratedXmlFile) Test(org.junit.Test)

Aggregations

Document (org.mybatis.generator.api.dom.xml.Document)11 GeneratedXmlFile (org.mybatis.generator.api.GeneratedXmlFile)5 ArrayList (java.util.ArrayList)4 Attribute (org.mybatis.generator.api.dom.xml.Attribute)4 XmlElement (org.mybatis.generator.api.dom.xml.XmlElement)4 Messages.getString (org.mybatis.generator.internal.util.messages.Messages.getString)3 Date (java.util.Date)2 TextElement (org.mybatis.generator.api.dom.xml.TextElement)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 StringReader (java.io.StringReader)1 Properties (java.util.Properties)1 Test (org.junit.Test)1 CommentGenerator (org.mybatis.generator.api.CommentGenerator)1 DefaultXmlFormatter (org.mybatis.generator.api.dom.DefaultXmlFormatter)1 InputSource (org.xml.sax.InputSource)1