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".

Identifying transformation rules

Now, the next question is: If I know my PIM (platform independent model) and my PSM (platform specific model), then how do I transform PIM elements to PSM elements and to code? Think of this in two steps:

  • Ask yourself
    1. Which PIM elements will be translated to which PSM elements?
    2. How is the relationship? 1:1, 1:n, n:m?
    3. How can I formalize a rule that translates PIM metaobjects into PSM metaobjects?
  • And now the final question:
    1. What would a PIM metaobject need to transform itself into PSM metaobjects?
    2. The answer will tell you which metafacades you need in your cartridge!

When you find the transformation rules for your cartridge, record them as a table on a piece of paper. In the case of our deployment sample, you might want to record the following transformation rules:

Source element in PIM Target elements in PSM Transformation
Node Project one project for each node in the system
Node Target one "compile" and one "deploy" target per node which contain all tasks for all artifacts and packages of this node
Artifact Task one <jar> task for each artifact
Package Task one <javac> task for each package

Now, think of a transformation rule as an operation inside a PIM metafacade. Let those operations return PSM metaobjects. The algorithm inside the operation implements the PIM-to-PSM transformation.

Design the transformation rules you have found as methods of one or more metafacade classes. Then apply the three-step process:

  1. Model metafacades using UML
  2. Generate code for them using AndroMDA's cartridge andromda-meta
  3. Implement them in Java