Create UserVO
This page provides directions to create the
UserVO
using RSM.
Let's take a look at the initial content of the freshly generated model.
- Start RSM.
- The AndroMDApp generated emx model can be edited directly. We have to import the mda project into RSM.
On the left of the window, there is the model explorer. 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.
-
AndroMDADatatypes: This package contains some platform independent datatypes
that have be used in your UML model. AndroMDA will map then to platform specific datatypes.
-
JavaPrimitive Types: This module contains the standard primitive datatypes for UML2.
-
UMLPrimitive Types: This module contains the standard java wrapped datatypes for UML2.
Both UMLPrimitive and JavaPrimitive Types are mapped to the standard Java output types in AndroMDA.
Important: A common source of errors is to use wrapped datatypes instead of primitive datatypes.
When specifying datatypes, make sure that the type matches the multiplicity lowerBound. Example: use
datatype::Integer with multiplicity 0..1 instead of datetype:int. -OR- use
datatype::int with multiplicity 1..1 instead of datetype:Integer.
-
Basic, Intermediate, Complete, Default, Deployement: These modules are the standard profiles applied to a UML2 model.
-
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 .emx files. They're only
references to .uml files located into your maven 2 repository.
Let's start the 'real' work. We will create UserVO and
UserVO[] in a package named
org.andromda.timetracker.vo. When finished, the model explorer in
RSM will look like the screen shot on the bottom of this page.
- Now right-click on the
timetracker
model and selectAdd UML Entity
> 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,
lowercase 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!
- 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.
- In the model explorer on the left, right-click on the vo package
and selectAdd 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.
-
Note: Depending on your configuration, RSM automatically adds a diagram
to the created package. Simply delete them or use them. It is up to you.
- In the toolbar on the left of the class diagram click on the
Class icon (2nd icon
from the class diagram group). Now click anywhere inside the diagram. A new class will be created.
Click on Class1
to make RSM display an editing box for the name of the class. Now
type the word UserVO and press Enter.
- 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. Select
the UserVO class. In the Properties
tab, click onDocumentation. Enter the following words in the field:
This class represents
a value object that carries information about a TimeTracker user.
- Now add the stereotype
ValueObject to class UserVO. To
do this, select the class and in the Properties
tab, click onStereotype.
In this sub-panel, click onAdd Stereotypes....
A popup dialog will appear, check ValueObject
and clickOK. The UserVO class will now have the
ValueObject stereotype.
Tips & Tricks: AndroMDA profiles define a lot of stereotypes and tag values.
Some of them are not needed during this tutorial: Meta, Process,
Webservice
and Xml. You may remove them: it will make the selection of
stereotypes easier (since a lot of them won't be displayed anymore).
-
Select the timetracker model. On the Properties
tab, activate the Profiles sub-panel.
-
Select the Meta
profile and click onDelete Profile. Do the same
for Process, Webservice and Xml
profiles.
-
Profiles can also be added to your existing models, so that they can be used by AndroMDA.
Under the model > Properties > Profiles, browse to the m2repo directory org/andromda/profiles/emf/uml22. Add the
3.5-SNAPSHOT versions of andromda-common.profile.uml plus the other profiles required by the cartridges
(frameworks) you have selected to generate. Add the andromda-datatype-3.5-SNAPSHOT.uml model library
under model > Import Model Library...
- Let's add
id
as an attribute of UserVO. Place your mouse on the UserVO
class and wait until a 'tooltip' appears above it. Click
on the little red square. A new attribute is inserted with the
specification <<>>Attribute1.
Write over this specification with this new one: +id
and press Enter. The red square become a green circle, meaning the attribute is 'public'.
Note that attributes are always
generated as private members of a class. However 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 (by using the plus sign) and hence
the getter and setter for the id
attribute will be public.
-
Select the attributeid, and in the Properties
tab, click onGeneral.
In this sub-panel, click onSelect Type....
A popup dialog will appear, select
AndroMDA Datatypes::datatype::Long and clickOK.
- 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 from AndroMDA Datatypes::datatype.
- Add a new class to the diagram and name it UserVO[].
- 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).
- Make sure that the RSM model explorer the screen shot shown below.
- Save your timetracker model by double-clicking on timetracker.emx
and clicking on File > Save (Ctrl + S).
-
SelectFile > Export.... Choose UML2 Model
and then click onNext. As source select
/TimeTracker/timetracker.emx and as destination
browse to C:\timetracker\mda\src\main\uml.
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.