The <Gen-it> Manual

 

 

 

 

 

<Previous Next >

2. How do I get a XML file describing my database?

Now we've seen the <Gen-it> process in a simple example, it's time to provide some more detail for each of the steps. We'll start with the process of getting the XML file describing your database or classes, but first we need to say al little bit more about the format of this XML file.

To generate code you can use different kinds of XML formats, but when you create a XSL template you have to create it specifically for this kind of XML format. For this reason all XSL templates on this site are based on a "standard" XML format: the <Gen-it> XML Format. We will refer to this format as GXF from now on.

GXF files look something like this:

<Gen-it>
    <Class> 
        <Class.name>Orderline</Class.name> 
        <Class.stereotype></Class.stereotype> 
        <Class.documentation>Orderlines of a order.</Class.documentation>            
        <Attribute> 
            <Attribute.name>orderlineid</Attribute.name> 
            <Attribute.datatype>NUMERIC(10,0)</Attribute.datatype> 
            <Attribute.stereotype>PK</Attribute.stereotype> 
            <Attribute.documentation>Unique identifier, not visible for users.</Attribute.documentation>            
        </Attribute> 
        <Attribute> 
            <Attribute.name>amount</Attribute.name> 
            <Attribute.datatype>NUMERIC(5,0)</Attribute.datatype> 
            <Attribute.stereotype>NOT NULL</Attribute.stereotype> 
            <Attribute.documentation> </Attribute.documentation> 
        </Attribute> 
        <Attribute> 
            <Attribute.name>productid</Attribute.name> 
            <Attribute.datatype>NUMERIC(10,0)</Attribute.datatype> 
            <Attribute.stereotype>FK</Attribute.stereotype> 
            <Attribute.documentation/> 
            <Reference> 
                <Reference.name>productid</Reference.name> 
                <Reference.documentation/> 
                <Reference.class>Product</Reference.class> 
                <Reference.mulitplicity>1..1</Reference.mulitplicity> 
                <Reference.optional>False</Reference.optional> 
                <Reference.attribute>productid</Reference.attribute> 
            </Reference> 
        </Attribute> 
    </Class> 
</Gen-it>

You can see it's a bit more elaborate then the one used in our previous example. Most of the format is pretty straightforward, but some tags need a bit more explaining:
· The <Attribute.datatype> element describes the datatype of the corresponding field in the database.
· The <Attribute.stereotype> element describes whether the field is allowed null by a value of "NULL" or "NOT NULL" or has a value of "PK" or "FK" for primary and foreign key fields. The <Attribute.stereotype> element isn't needed for all code generation purposes.
· The <Reference> element and its children describe what a Foreign key field is referencing or by which fields a Primary key field is referenced. The <Reference> element isn't needed for all code generation purposes.

OK, now you know how a GXF file looks like, but "How do I get a XML file describing my database?" Well, there are three ways:
1. Write it yourself using notepad, XML Spy or any other ASCII or XML editing tool.
2. Create a XMI file and convert it using the XMI.xsl template provided on this site.
3. Use the <Gen-it> Transformation manager to convert SQL Create Table statements into GXF

Write your own GXF file
Of course you can write the GXF file yourself. You can specify which tables and fields are in your database using any ASCII or XML editor. This seems like doing double work because you do the same thing when you create your tables. Naturally that's not entirely true: when you have created the GXF file you can use the CreateSQL.xsl template in the <Gen-it> library to generate the Create Table statements that you can use to create your database.
When you can't use one of the two other options because you don't work on a Windows platform or don't have a CASE tool that supports XMI this is the only option for you. Maybe it's more work compared to the other options but it is also the most flexible option. You can control what you put in the GXF file, adding information when you need it for specific templates.

Use XMI
XMI stands for XML Metadata Interchange. XMI is a standard format published by the Object Management Group (OMG) and is used to exchange UML models between CASE tools. XMI is supported by IBM, Unisys and Oracle. At the moment there are three different modeling tools (that we know of) that export XMI: Rational Rose, ArgoUML and Oracle Developer 6i. In addition, IBM has a free tool that supports XMI to Java and Java to XMI conversions.
The XMI file that is produced by these tools contains information about classes, attributes, operations, associations and much more. The XMI format is however rather complex and using it for <Gen-it> templates is next to impossible. <Gen-it> provides a XSL template that converts the XMI file into GXF, which is more readable and easier to use. Because UML models aren't designed for creating database tables, the transformation places some restrictions or modeling standards that you must use when modeling your database in on of the mentioned tools. See the XMI example page for more information about these restrictions.

Use the <Gen-it> Transformation Manager
On this site you can download the <Gen-it> Transformation Manager in the Download section. The Transformation Manager helps you in generating code by supporting multiple output documents and XMI transformation. An other feature of the Transformation Manager is the possibility to transform SQL Create Table statements to GXF files.

 

<Previous Next >