Create UserVO

This page provides directions to create the UserVO.

Let's take a look at the initial content of the freshly generated model.

  1. Start MagicDraw 16.5.
  2. Select File > Open Project... and traverse to C:/timetracker/mda/src/main/uml/timetracker.xml. Click Open to open this model.

On the left of the window, there is the containment tree. It displays the objects that make, together, the model. AndroMDA sees the model like it is displayed here (and not through the several diagrams). By making sure that the content of your model is matching the pictures shown during this tutorial, you'll avoid a lot of errors.

As you can see, the model is not empty. Some of work has already be done for you. Let's review the initial content of the model.

  • UML standard profile: This module contains (as its name says) the standard profile from UML2. In previous AndroMDApp generated models, this module was removed. For UML2 models, it is necessary because it define the metaclasses where stereotypes are applied.
  • datatype: This package contains some platform independent datatypes that have be used in your UML model. AndroMDA will map then to platform specific datatypes. Important: A common source of errors is to use UML's datatypes instead of these. When specifying datatypes, make sure that they come from this package. Example: use datatype::String instead of String.
  • org.andromda.profile: This collection of profiles define all the stereotypes and tag values that will be used by AndroMDA for generating code.

Note: all this content is not included in the xml file. It's only references to files located into your maven 2 repository.

MagicDraw has the concept of a hierarchy of models. Each model in the hierarchy can be broken out and stored as a separate file. This allows multiple developers to work on different parts of a master model. Let's create a new model for TimeTracker.

  1. In the Containment Tree on the left, right-click on the root element called Data and select New Element > Model. A new model will be created under the root element with an edit box to its side. Type in timetracker as the name of this model.

As said previously, AndroMDA can't read MagicDraw MagicDraw 16.5 models directly. You have to export it to another file format: EMF-UML2.

  1. Save your timetracker model by selecting File > Save Project.
  2. Select File > Export > EMF UML2 (v2.x) XMI File. Choose C:/timetracker/mda/src/main/uml as export directory and click Export.

If you want to see the result of this export, open the folder C:/timetracker/mda/src/main/uml in explorer. Let's look closer at its content.

  • timetracker.xml: the MagicDraw 16.5 model file.
  • timetracker.uml: the timetracker model in EMF/UML2 format. It's the file that will be processed by AndroMDA.
  • 10 files ending with .profile.uml: the different profiles used by timetracker.uml

As you can see, all modules on which your model depends are present in this directory. This explained why the moduleSearchPath section in andromda.xml is empty.

If you have installed the uml2 plugin for Eclipse, you can open timetracker.uml to look at its content. You'll see almost the same objects than those in containment tree.

Important: Always use the timetracker.xml file for editing. After edition, don't forget to export the model to EMF/UML2 (v2.x). AndroMDA won't take your changes into account if you don't export your model.
  1. Now right-click on the timetracker model you just created and select New Element > Package. A new package will be created under the timetracker model element with an edit box to its side. Type in org.andromda.timetracker as the name of the package. AndroMDA will map this package to a Java package with the same name. Note: Make sure the package name is exactly org.andromda.timetracker, with no leading or trailing spaces. We have found that some browsers introduce a leading space in the package name if you copy it from this page!
  2. Now create a package called vo under org.andromda.timetracker. We will create our value objects in this package. Note that AndroMDA does not require this package structure. We are doing it simply to separate our value objects from other type of objects such as business entities, services etc.
  3. In the Containment Tree on the left, right-click on the vo package and select New Diagram > Class Diagram. The diagram is created and opened in a new window. You can see that the diagram's name is being edited. Type in Value Objects as the name of this diagram and press Enter.
  4. In the toolbar on the left of the class diagram click on the Class icon (1st icon from the class diagram group). Now click anywhere inside the diagram. A new class will be created. The class will be automatically selected as indicated by the 4 knobs around it. (If you somehow deselected the class, then select it again by clicking on it.) Now type the word UserVO. This word will be entered as the name of the class.
  5. Let's add some documentation for the UserVO class. It is always a good idea to document your model. Documentation added to model elements such as classes, attributes and methods is carried over to the code as comments. Double-click on the UserVO class to bring up the Class Specification dialog. Add the following sentence in the Documentation field and click Close: This class represents a value object that carries information about a TimeTracker user.
  6. Now add the stereotype ValueObject to class UserVO. To do this, right-click on the class and select Stereotype. In the next level menu, check ValueObject and click Apply. The UserVO class will now have the ValueObject stereotype.
  7. Tips & Tricks: AndroMDA profiles define a lot of profiles. On the widget displaying all available stereotypes, start to type the name of the searched Stereotype. By typing Va, only ValueObject is displayed.
  8. Let's add id as an attribute of UserVO. Right-click on the UserVO class and select New Element > Property. A new attribute is inserted with the specification -unnamed1. Change the attribute specification with this new one: +id : Long [datatype]. The visibilities of the associated getter and setter are determined by the visibility of the attribute specification. In this case we have specified public visibility and hence the getter and setter for the id attribute will be public.
  9. Now add three more public attributes called username, firstName and lastName to the UserVO class. Make them String type. In your model two different types called String are available (see above). Use the one displayed String [datatype].
  10. Make sure your class diagram matches the one shown on the right exactly. (It is okay if your class shows an empty operation compartment. This can be hidden very easily).
  11. Make sure that the MagicDraw containment tree matches the screen shot shown below.
  12. Tips & Tricks: MagicDraw 16.5 displays objects that have changed since the last save in blue.
  13. Save your timetracker model by selecting File > Save Project.
  14. Export it in EMF/UML2 format by selectingFile > Export > EMF UML2 (v2.x) XMI File. Choose C:/timetracker/mda/src/main/uml as export directory and click Export.

Congratulations! You have now specified the UserVO value object of the TimeTracker application. We are now ready to generate some code. Please go back to the main tutorial page and continue from where you left off.