AndroMDA Mappings

When modeling applications in UML for AndroMDA you will never use language or technology specific types directly. Instead you will use platform independent datatypes which will be mapped onto the ones you need during the code generation process. This allows you to target different platforms without having to edit your model.

Mappings are configured using properties, an example can be found in the mda/conf/andromda.xml file, generated by the andromdapp:generate Maven plugin. Here's a fragment taken from this file (notice how the sql mappings are controlled by a runtime property defined in /project.properties):

    <namespace name="default">
        <properties>
            ...
            <!--
                here we configure the mappings to be used,
                we specify the logical names for each mapping
            -->
            <property name="languageMappingsUri">Java</property>
            <property name="wrapperMappingsUri">JavaWrapper</property>
            <property name="sqlMappingsUri">${sql.mappings}</property>
            <property name="jdbcMappingsUri">JDBC</property>
            ...
        </properties>
    </namespace>

The logical names can be found in the mapping file itself, at the top of the file, as shown here:

    <mappings name="Java">
        ..
        <mapping>
            <from>datatype::String</from>
            <to>java.lang.String</to>
        </mapping>
        ...
    </mappings>

Different types of mappings exist, the ones that ship with the AndroMDA distribution are listed here:

Wrapper Mappings

Customizing the default mappings

Submitting new default mappings

Not all possible mappings are known by AndroMDA, if you are using a database or language for which no mappings exist, then you're welcome to create your own mappings file and submit it to us, we'll make sure it will be integrated into the project.

If you are subscribed to the AndroMDA Developer mailing list you can send an email to andromda-devel@lists.sourceforge.net, or better yet: file an issue in JIRA, that way it's easier to keep track of: http://jira.andromda.org/.

Extending and Overriding

It might happen you want to have a mapping that is slightly different than the default one known by AndroMDA. Well, in that case you can either extend or override the default mapping by specifying your own mapping file.

This is done by simply using a URI for the value of a mapping namespace property instead of the logical name, here are a few examples for several types of mappings, you can find them in the default namespace definition within mda/conf/andromda.xml (which means these apply to all namespaces/cartridges):

    <property name="languageMappingsUri">file:${project.basedir}/src/mappings/MyJavaMappings.xml</property>
    
    <property name="wrapperMappingsUri">file:${project.basedir}/src/mappings/MyJavaWrapperMappings.xml</property>
    
    <property name="jdbcMappingsUri">file:${project.basedir}/src/mappings/MyJdbcMappings.xml</property>
    
    <property name="sqlMappingsUri">file:${project.basedir}/src/mappings/MySqlMappings.xml</property>

If you were overriding a mapping file, all you'd do is customize an existing file and give AndroMDA the URI to your new mapping file (like you see above). If, on the other hand, you want to extend a mapping (this is much better in most cases because then you only need to add or customize the specific <mapping/> entry(s) you need, and inherit the default ones), you'll need to add the extends element to your mapping file. Note this example is saying to extend the mappings found with the logical name Hibernate:

    <mappings name="HibernateExtension">
        <extends>Hibernate</extends>
        ...
        <mapping>
            <from>datatype::boolean</from>
            <from>datatype::Boolean</from>
            <to>yes_no</to>
        </mapping>
        ...
    </mappings>
You can also extend a mapping using a relative path (relative to the location of the mapping you're defining it within). Notice how this time we have the relative path ../../mappings/HibernateTypeMappings.xml to the mappings file we're extending (assuming it exists within that location):
    <mappings name="HibernateExtension">
        <extends>../../mappings/HibernateTypeMappings.xml</extends>
        ...
        <mapping>
            <from>datatype::boolean</from>
            <from>datatype::Boolean</from>
            <to>yes_no</to>
        </mapping>
        ...
    </mappings>

All mappings can be found in the andromda-maven-plugin.jar, just unzip it and go into /META-INF/andromda/mappings, you can unzip them into your own location, edit them, and use them to override the defaults as explained above.