To add scripting rules to Model Expert, you will need knowledge of the EA Scripting languages, as well as some knowledge of the EA programming model.Â We have provided some example scripts, so you may choose to copy and modify these.
Note: all code examples are written in VBScript, but you may use any scripting language which is supported by EA.
For details on creating an EA Script, see the EA help here.
Model Expert Validation scripts must be created in the ‘Normal’ group.
Writing a Model Expert Validation Script
Validation scripts have just three requirements:
They must declare what kind of element type and stereotype they should be used for
Some code which does the checking.
Your script will be passed a reference to the current Repository, and the ElementID of the instance of the EA element which your code will examine.
They must output an XML string of the form:
<violation note=(sometext) severity=(a positive integer) />
Type / Stereotype Declaration
This must be in the form of a code comment. In VBScript, this is a single inverted comma: ‘
This script will be run for All examples of all meta-types.
Use this for checks which are needed for everything in your model, for example, you might decide that all elements must have a name, or some notes or alias.
This script will run for all examples of this meta-type, regardless of their stereotype
This script will only run for <<Special>>Use Cases
The code to do the validation can be quite simple, because the script has been passed the EA Object_ID of the element being validated, as well as a reference to the current EA Repository.
So the first task for a script is usually to get the EA.Element which corresponds to the Object_ID passed
dim e as EA.Element
set e= Repository.GetElementByID(ElementID.toString)
We usually declare the output string at this point, to add violations to it as we progress through the script
dim outputHTML ‘ a string which will contain the results from the script
Now we can start to do some validation. This checks how many scenarios the use case has
‘look in more detail at the insides of the Use Case
if e.Scenarios.count = 0 then
outputHTML = outputHTML &“<violation note=’Missing scenarios for use case’ severity=’4′ />”
and some more, to make sure we are not using Internal Requirements, as this is against our local standards
if e.Requirements.count > 0 then
outputHTML = outputHTML &“<violation note=’Use Case has Internal Requirements’ severity=’3′ />”
Finally, complete the XML which is output, and assign it to the name of the script. This is how values are returned from EA Scripts. Our script was called “Use_Case”:
outputHTML = outputHTML &“</results>”
‘put the HTML string into the return
Use_Case = outputHTML
Note: EA Scripts seem to need to have the name of the script as the last item in the script e.g.
We don’t know why this has to be there….
Notes for writing Scripted Validation
We suggest keeping the validation scripts simple. Remember, they will be run once for each instance of the meta-class. If this is 100s, then a script which does lots of look-ups into the EA model each time will be very slow.