10 steps to write a cartridge

This article shows you how to write an AndroMDA cartridge in 10 distinct steps, using a sample cartridge which generates an Ant-like build script from a UML deployment model. This is why the tutorial cartridge is called "andromda-deployment".

Analyzing the target technology (PSM)

Hint: PSM means "platform specific model".

First of all, analyze the target technology for which you want to generate the code. Ask yourself some questions:

  • What are the core concepts in my target technology?

    • Java: classes, interfaces, methods, …
    • MS Excel: sheets, cells and their contents
    • Database: tables, rows, columns, keys
  • What are the formats in which the target technology expresses itself?

    • Java: source code
    • MS Excel: proprietary binary or readable XML
    • Database: DDL scripts, SQL scripts with test data
    • currently, it's not possible to generate binaries!

The answers to these questions are the results of target technology analysis. The results are twofold:

  • PSM core concepts -- they will be candidates for PSM metaclasses
  • File formats -- they will determine the format of your templates

In the case of our deployment cartridge, the platform that we describe in our PSM is the Ant platform. So, the PSM core concepts are:

  • Project: description of something that can be built
  • Target: a certain goal which should be reached during the build process, e.g. "compile", "jar" or "deploy"
  • Task: some distinct algorithm that is run during the build, e.g. the Java compiler or the Jar utility

The file format involved is a simple XML format that can contain projects, targets and tasks. I am lazy in this tutorial, so I will not generate fully functional Ant scripts but only something conceptually similar so that you can see the intention.