How to develop MDG’s for Enterprise Architect 9.x, part 3

How to develop MDG’s for Enterprise Architect 9.x, part 3

Introduction

In the first tutorial, we looked at how to develop the TrimmWS Profile containing the Web Service modeling elements for use by the TigerTeam Trimm Model Generator and how to save it as a Profile that can be imported into EA. In the second tutorial we looked into how to make the Profile and its content more usable by combining it with a Toolbox and a Diagram into an MDG.

This tutorial describes how to add our own Datatypes to the TigerTeam TrimmWS MDG and how to automatically make them available to our modeling elements.

This tutorial

Before we start, lets recap what we have achieved so far. We have gotten the 5 major components in an MDG together combined into an MDG File that can be distributed and installed on any EA version 8 and above. So far we have defined:

  1. The Elements for modeling Web Services, aka. the Profile. Did that in Part 1
  2. A Toolbox, that organizes the elements from the Profile. Did that in Part 2
  3. A Diagram for modeling Web Services, that defaults to our Toolbox and Profile elements. Did that in Part 2
  4. The MDG control file. Keeps all the elements together when generation the MDG. Did that in Part 2
  5. The generated TrimmWS Web Service MDG file itself. Did that in Part 2

Now we will add our own Datatypes to the TigerTeam TrimmWS MDG, which makes our big picture a little bigger than before, as you can see on the picture below:

Now that we have recapped, lets start defining our Datatypes.

Creating a Product

Creating our own datatypes is actually a subset of creating Code Generation Templates for your MDG, but you do not have to implement a fully fledged language template. Since we will use the MDG for our own TigerTeam Trim Model Generator, we do not need the Code Generation Templates, but only the Datatypes

To define data types we first need to create a Product. A Product is how EA define Datatypes and Code Generation Templates for a certain purpose.

  1. To create a Product, select “Settings” -> “Code Datatypes..”. EA will present you with this dialog:

    I have cheated bit and already pressed the “Add Product” button and entered the name of the Product I want to add. Here I have used the same name and ID as my MDG, “TrimmWS”, but it can be any name you like.

  2. Press “OK” and we have created a Product and can start adding Datatypes.

Note: There is a UI glitch in EA so you can actually  add the same Product a number of times. Even if it shows up more than once on the Product list, it is only there once. Close the “Programming Languages Datatypes” dialog, and there will only be one “TrimmWS” Product the next time you open it.

Creating Datatypes

Creating datatypes are really easy. Here is what you have to do

  1. To create a Product, select “Settings” -> “Code Datatypes..”.
  2. Select “TrimmWS” from the “Product Name:” list, and you can start adding your Datatypes. EA will present you with this dialog:

    Now we can start adding our Datatypes. Here is what we have to add:

    DataTypeThe Name of our  datatype
    SizeThe fields in the “Size” are only used if your Product has datatypes supports min/max length and/or Precision and Scale, e.g. SQL and Cobol. Since we do not need that, all the TrimmWS datatypes are set to Size None
    Common TypeFrom what i can gather from the documentation, Common Type is used for telling that a certain Datatype is actually derived from a more common or generic datatype. It is used for model generation and transformation, and since we do not need that, I have left it blank.
  3. Press “Save” and you have created a Datatype.

To add more , press “New” and repeat the steps outlined here again.

Make your Datatypes default on our Diagram

After having created our own datatypes for our TrimmmWS MDG, it would be nice if they were selected by default when modeling WebServices. Doing so is fairly easy.

As you can see on the figure below, we add a new Attribute, “styleex” to our Diagram metaclass to tell EA which Language to use as default on our TrimmWS Diagrams. The “styleex” attribute is a semicolon separated list that is used for controlling all sorts of Diagram behavior. By adding “DefaultLang=TrimmWS” we tell EA to default to use the TrimmWS Datatypes when adding elements, WebServices, WS Attributes and the like, to our TrimmWS Diagram.

Note: The “styleex” syntax for default lanuguage is “DefaultLang=<MyProduct>;” where “<MyProduct>” is the name of the Product, in our case “TrimmWS”, that will be used as default on the TrimmWSdiagram.

Default Datatype when creating an Attribute

It is also possible to control which Datatype that should be used as default when adding Attributes to Elements on a Diagram. We have defined 2 custom attribute types, “WSAttribute” and “WSElement” and we would like for them to default to the Datatype “integer” when added.

To do so, we add an attribute named “_defaultAttributeType” to out Attribute StereoType elements and in the “Initial Value:” field we enter the name of the Datatype from our TrimmWS Product we want to use as default. Here we have chosen “integer” as the default datatype., as you can see below:

Generating the MDG

Generating the MDG to include our newly defined Datatypes follows the same workflow as described in Part 2, with the following additions.

In step 5, we also select “Code Modules” from the “Code” group. This will, in a later step, give us the possibility to select the Products we want to include in our MDG.

After step 9, we will be presented with a dialog box, where we can choose which Products and which of their elements to include. The dialog looks like this:

We choose to include the “TrimmWS” Product and since we only need the Datatypes, we only select “Data Types” and leave “Code Templates” unselected.

The rest of the steps are exactly the same as described in Part 2 of our tutorials.

Deploying the MDG Technology

To deploy the MDG now that it contains Datatypes, is exactly the same procedure as the one described in Part 2 of our tutorials. Just follow the steps and you will be fine.

Closing remarks

I hope you have found the tutorials on how to build an MDG for EA useful and helpful enough to start developing your own MDG’s. I am sure that there are other ways to do it easier or simpler, but what I have described here is what I have managed to get to work.

Next steps

I have not yet planned a next tutorial so if you have any ideas please let me know.

Download the MDG files

You can download the complete “TrimmWS” MDG model and files from our Downloads page.

 
Comments

No comments yet.