Using MDA

Some things are just not easy to familiarize. One of them is using the AndroMda tool to design and build applications. This is a set of notes I made for my own purposes so that I can remember what I did that worked. And I hope you will find something useful in it too.

I am using MagicDraw as my uml tool because it the one highly supported by AndroMDA. The steps that I am following is in the excellent Getting Started Guide on java. When doing these notes, I am doing an Out of Office tracker tool. So the name of my project is ooo. After generating the project using maven, I need to change the model.uri to file:${project.basedir}/src/main/uml/ooo.uml2 because the default does not work.
After opening the model at mda/src/main/uml/ooo.xml I created the model named “ooo model”. In this model I created the root package of my project “”. The first thing to do is to create the business objects. So I create a package under “” called model and created a new class diagram. Here is the screenshot of my model class diagram.

The mistake I commonly make is forgetting to put the stereotypes in my business objects. In the diagram above, the User class will end up as an entity bean because of the stereotype “Entity”. The class UserVO is a value object and is the object being shared between presentation layer and the business layer. This should also be labeled with a stereotype or else you will not find this generated by AndroMDA. The dependency from User and UserVO object means that in the code that is generated there will be a method to convert from the User entity to UserVO.
Under the package “” i created another package called “service”. This will contain the service objects that will have access to the User entity through the UserDao. The UserService is the service pojo that will have access to the User entity using the dependency from it to the User class. When AndroMDA generates the code, it will give the UserService access to the UserDao where you can manipulate the User entity.

My UserService class has two methods namely addUser() and listUsers(). When AndroMDA generates the code, it will create a class called UserServiceImpl under the folder core/src/main/java. See the screenshot below:


You need to open this class and provide implementation to the methods handleAddUser() and handleListUsers().

Now it’s time to put an interface to our new ejb. I added a new package under “” called “web”. This will contain the use cases of the web interface. For each use case, i’m going to put it under a new package under “web”. Now i’ll create the use case called “Add User” and a state machine diagram that will contain the state machine for this use case. I have to put this under a new package called “adduser”. Here is the state machine diagram:


Never forget to put the initial state. The stereotype “FrontEndView” that labels a task means that AndroMDA will render this as a view in struts. Imagine the user entry page as containing two text fields named “First Name” and “Last Name”. The page will submit this two parameters to the server. We can model this using the transition from User Entry to Add User. Right click on that transition and open the specification. Click on the behaviour type of “Entry” and specify Activity. In the containment tree, click on this behaviour and add parameters “firstName” and “lastName” with datatype as String. Add the tag @andromda.presentation.web.view.field.type = text to these parameters. See the screenshot below to get a hint on how this is done.

The screenshot below shows how to set the tag @andromda.presentation.web.view.field.type to “text”.
Setting tags to render it in correct html input objects.

By specifying the tag @andromda.presentation.web.view.field.type as “text” , this will be rendered as an html text field.

Now that we already have our input page, the next thing to do is to create a controller that will accept these parameters and save them to the database. Let us create a new class under the “Add User State Machine” and call it UserController. To do this, just right-click on “Add User State Machine”->New element->Class. Name this class as UserController.


On the containment tree, right-click on UserController and open its specification. Create a new operation on it with signature addUser(String firstName, String lastName).


Now that we have our controller ready, click on the “Services” class diagram and from the containment tree, click on the UserController class and drag it to the “Services” diagram. Create a dependency from UserController to UserService class. This will allow UserController to access the UserService.


Now, let’s go back to the “Add User State Machine Diagram” and model the interaction of our state machine with the UserController class. Click on the Add User task and open the specification. Specify the behaviour type of Entry as Activity. In the containment tree, click on this activity and open it’s specification. Click on Node and click “Call Operation Action”. This will take you to the “Call Operation Action” specification. Click on “Operation” and choose addUser() operation from UserController. As you might have guessed, this will invoke the operation UserController.addUser() which we should implement.


Generate first the classes using the command “mvn install”. Then find the class UserControllerImpl and implement the “addUser()” method. Notice that method signature of addUser is different from what we specified above. Instead it’s method signature is:

public final void addUser(ActionMapping mapping, form, HttpServletRequest request, HttpServletResponse response) throws Exception;

The parameters firstName and lastName can actually be found in the AddUserForm. Here is a simple implementation of this method:


Now it’s time to generate the tables in mysql using the command “mvn -f core/pom.xml andromdapp:schema -Dtasks=create”. You can verify that the table is created using mysql client:

To deploy the application, we issue the command:mvn -f app/pom.xml -Ddeploy

This will deploy to jboss directory. It will be a good idea to start jboss before deploying so you can see the deployment in action. After deployment, you can access the application by launching your browser and pointing to http://localhost:8080/ooo. Here is the screenshot of the page:


Finally, put some values into the two fields and submit them. Check that the values indeed end up in the database.


Published by

Bobby Corpus

Loves to Compute!

One thought on “Using MDA”

  1. Pass this on:

    There will be two seminars in Bobby’s province:
    Open source Workshop on June 23-24, 2008 in Bobby’s Cebu province. URL is

    SMACS 2008 will be held on August 4 to 6 August 2
    Venue: University of the Philippines-Cebu Colleges, Cebu City

    I still recall vividly SMACS was where our paper on face recognition was adjudged fit for poster presentation, not for pulblication.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s