Home
Tutorial - Mia
Contents
1. UMLClass 3 T String accessori public typeName get Name i T return this name 7 Documentation Error rror in Text Template Tutoriallaccessor j i 7 nknowm referenced action public void set Name typeName value iT ame with O parameter s this mame value 7 HM Figure 41 Template for the declaration of the accessors This template generates the methods get and set for an attribute The script uses a macro Name putting the first letter of the attribute name as a capital letter and a macro typeName which returns the attribute tyoe name The Name script puts the first letter of the attribute name as a capital letter Types Categories Scripts UNILASSociation l default 4 Scripts s UMLASssociationClass replies de UMLAssociationEnd RS ae T accessor ei UML Attribute 4 E declaration de UML AttributeLink File Templates A UMLBinding Fl Macros Es UMLCall ction o e UniLcallEvent lt M typename UML ChangeEvent gt Services String Mamet String name current getNamel return Character toUpperlase name charAt o name subatringil Figure 42 Macro Name This Name macro could have been defined on the type UMLModelElement parent of all UML types where the method name is defined because it s a function that is very general and can be used for attributes classes associations etc MIA Generation Tutorial e 30
2. F JavaGeneration UMLClass Add Edit Remove Objects ce Enumeration Rank UMLClass e Address UNLClass et Edit Remove Figure 82 JavaGeneration UMLClass Generation Unit Use the Trace mode to see how stereotypes are used to make generation choices in the selectJavaGenerationkind and attributesDeclaration macros MIA Generation Tutorial e 56 This document is the property of Mia Software It cannot be reproduced even partially by any means without prior written permission For the class Rank Edition Generation Generated text reloaded from Rank java class Rank at Tutorial mal ublic static final int DEVELOPER 0 erica ublic static final int CONSULTANT 1 E SRy Parameters ublic static final int MANAGER 2 B Results 2 E 1 REE fil Address java lg Trace E en davaceneration l E davaGenerationii lt lt Enumeration gt Rank I d JavaGeneration Filename Enumeration Rank Elm selectlavaGenerationkind lt Enumeration gt Rank E A izEnumeration Enumeration gt Rank Bm fiavaEnumerationBodyo lt Enumeration gt Rank E i namei Enumeratior gt Rank El attributesDeclarations 1 lt Enumeration Rank E aa isEnumeration lt lt Enumeration gt Rank aie attributes Enumeration gt Rank E E enumeratediCon tantDeciaration l DEWELOPER El Y enumeratedConstartDeciaration l CONSUL
3. If you select the object Director of type UMLClass you can see a link generalizations which relates this class to an object UML Generalization Meta objects e UMLAssociation 11 e UMLASsociationEnd 221 e UML Attribute 161 a UhiLClaz 8 e UMLGeneralization 1 e UNiLModlel 13 e UMLOperation 1 e UMLPackage 7 e UMLParameter 1 e UldLPrimitive 2 e UMLSterectype 1 e UMLTagqged Value 52 If you go into this object you superclass UML Tutorial mdl Director UMLClass Instances Le Enumeratior Rank UMLClas Le Address UMLClas Ls Building UMLCas cu Company UMLCass Director UMLClass Ly azsociationEnds 1 Ly generalizations 11 EH Employee Director UML Generalization il child 1 by parent 1 A Employee UMLClass Ly package 11 Ly taggedwalues 1 Le Division UMLClas Pan Employee UMLClass Le Office UMLClas Attributes Director 2280556801 93 name objectld documentation visibility is Specification Figure 27 UML Generalization will see a link child to the subclass and a link parent to the This links generalizations child parent are those defined in the UML metamodel UML Generalization discriminator String MIA Generation UML GeneralizableElement generalizations shild 5 1 Abstrait isAoot Boolean i 1 isLeat Boolean specializations parent ic 4bstract Boolean Figure 28
4. detautt Scripts To s UMLModelElermernt Text Templates PS CEMArOs i a G Pakage a UMLMode File Templates E System 328 de UMLModelnstance Macros a Services m Ee e UMLObject e UMLObjectFlow State de UMLOperation hd Profile Documentation Errar Package Tutorial Figure 5 Project Navigator MIA Generation Tutorial e 4 This document is the property of Mia Software It cannot be reproduced even partially by any means without prior written permission Creating a file template We are going to write a simple generation template to create a Java file for each class in the model A template is text which describes in a visual manner the way in which the code must be generated for an object type of the model The text of a template is composed of textual elements which will be reproduced just as they are in the generated text and scripts names which at the time of evaluation will be inserted in the generated text It is possible to specify the filename where the result of a template must be saved To do that it is necessary to create a File template of it It is a template to which another template Filename is systematically connected Once evaluated this template Filename gives the name of the file in which the text of the file template will be saved To create a File Template 1 Select the package the type and the category where you want to create the script 2 Click the New File T
5. 2 Create a public scenario by clicking on the New Scenario button Gi from the toolbar Ae New Scenario x Mame Tutorial Visibility E public cancel Figure 63 Creation of a scenario 3 To create a Generation Description you can click the New Generation Description button d from the toolbar Mew Generation Description x Mame of the new Generation Description da classes Annuler Figure 64 Creation of a Generation Description MIA Generation Tutorial e 45 This document is the property of Mia Software It cannot be reproduced even partially by any means without prior written permission A generation description is like a persistant generation unit Generation description breaks down into two steps objects selection and file templates choice Initially it is necessary to select the objects to which the generation will apply Then the scripts that you want to apply to these objects must be chosen cenario elements Add Edit Remove Objects Selection Type E UML lass with Subtypes objects Service E current gt UMLClass File Templates F JayaGeneration UMiLClazs Add Edit Remove Figure 65 Generation Description Objects selection To select the objects to which the generation will apply we use a service to filter objects from the model There is two levels into this objects selection 1 In the Type combo box c
6. Generation Result C Program Files Mil4 Generationgenerationyesutt txt Figure 21 Results of the generation All the classes are therefore generated in the same file named result txt We are going to see how to change the filename property of a file template MIA Generation Tutorial e 17 This document is the property of Mia Software It cannot be reproduced even partially by any means without prior written permission Filename property In the previous example the text generated is automatically put into a file named result txt All the classes are therefore generated in the same file We are going to change the script Filename of the File Template a property that determines the name of the file where we want to generate the text This script Filename is itself a template Therefore we can make a call to the macro name so the filename depends on the name of the class Edition Generation Types Categories Scripts e UMLCallEvent a default 1 Scripts i ae s UMLChangeEvert di lexi Templates Elpeeleges e Uli Class 1 E File Templates i ne ip System 328 es UML Classifier Si JavaGeneration 3 339 Tutorial 1 e s UniLClassifierimport B i ls HW Filename Profile te UbiLClazsifierinState p acros A hi Colloberstion m Set vices 4 Documentation Error A String Javaleneration Filename name aval Figure 22 Filename property After saving JavaGeneration Filename template click t
7. J publie String tostringi A return this id public static int size return upperBound protected static AbstractEnumeration basicFirst return first protected static AbstractEnumeration basicLast return last protected AbstractEnumeration basicPrev return this prev protected AbstractEnumeration basicNext return this next MIA Generation This document is the property of Mia Software It cannot be reproduced even partially by any means without prior written permission Tutorial e 71 Enumeration classes should extend this abstract class public class Rank extends AbstractEnumeration public static final Rank DEVELOPER new Rank DEVELOPER public static final Rank CONSULTANT new Rank CONSULTANT public static final Rank MANAGER new Rank MANAGER private Rank String id super id j public static Rank first return Rank basicFirst public static Rank last return Rank basicLast public Rank next return Rank basicNext public Rank prev return Rank basicPrev Frameworks and generators can add significant value to your project You can be sure that your framework will grow over time If your code generator contains only elements depending model you ll be able to add functionnalities to your generated classes without changing your generator and regenerating but using the extension mechanism of the frame
8. MIA Generation Tutorial e 46 This document is the property of Mia Software It cannot be reproduced even partially by any means without prior written permission This scenario gives us the possibility to execute the Java generation on all the classes in the loaded model To start the generation go to the Generation tab and select the Scenario panel Start the generation by clicking on the button Generate Edition Generation Parameters ode Scenarios Tutorial mel eneration E Scenario E Tutorial sr E Se Parameters ii Results Generation Units Trace OM JavaGeneration UMLClass Type A UML Class r scripts E Javateneration UMLClass Sadd Documentation Error Edit 10 documentation Objects Add Edit Generate Figure 66 Generation by scenario Edition Generation Generated text reloaded tram Address java public class Address extends Object Y A Tutorial tric Pe eee Generation public String street Parameters public String zip code E Results 8 public String city MeaeSes dress java public String country a el Building java El Company java public int getNumher ia Director java return this number ia Division java E Employee java pan Office java public void setMumber int value E Rank java this mmber value Figure 67 Results A scenario can have different units of generation and can have child scenarios Therefore we ca
9. The getList method will format the returned objects from a service into an instance of java util List If the service only returns one object getList returns a list containing this object If the service returns an iterator or array they will be converted to a List Using this method it is possible to call all services in the same manner without having to know how they were implemented Difference between returned type of a service and returned objects kind The declared Return Type is java lang Object but the real service return type can be of several kinds amodel object subtype of MIAObject an object array Java type Object a collection of objects Java type java util Collection aseries of objects Java type java util lteraton MIA Generation does not automatically determine the kind of the returned objects So at the time of the creation of a service it is necessary to define which kind of model object it returns If the service returns a collection of UMLClass instances the Returned Objects Kind will be UML Class even if the returned object is an instance of Collection MIA Generation provides a method collect to make it easier to write this type of service This method collect permits you to call a script on each object returned by a service and to retain the results from each execution of the script So a call to collect generalizations parent returns the list of parents from each generalization
10. Generalization links Tutorial e 21 This document is the property of Mia Software It cannot be reproduced even partially by any means without prior written permission You can find this diagram ant others using the menu Help gt Metamodel APIs You can display it by selecting it from the Window gt MetaModel Browser menu He MetaModel browser O x UML Meta objects Links cs UML Atribute l l arents a cl L UMLClassifier e UMLBinding hildren e UML CallAction ee UML CallEvent p aie Ls UMLAssaciation lass e UMLCallState e UML ChangeEvent e UMLClass e UMLClassitier e UMLClassifierlmport e UMLClassifierlnState e UML Collaboration e UML Comment ek UML Cormponert ek UML Componenthnstance ek UML Composte tate e UML Constraint Ly associationEnds UMLAssaciationEnd Ly attributes gt UML Attribute Ly behaviors gt UMLStateMachine by clientDependencies gt UniLDependency Ley comments gt UMLCormment Ly constrainingElements gt UlviLCollaboration Ly constraints gt UL Constraint documentation gt String by documents gt UniLDocurment generalizations gt UMLGeneralization Ly implementationLocations gt UhMLComponent Ly importedihPackagez gt UMLClassifierlmport de UMLCresteAction of O isAbstract gt Boolean LL bAi MataTuna jective gt Boolean bal Figure 29 Browse
11. MIA Generation User Guide Tutorial M od SIMA dl a Mia Software EEE model driven agility Table of contents TUTOR ao a ae oo 1 PRESENTATION at A a AS 1 FIRST OENERA HONOF JAVA CODE sus dai 2 Crediin g aA LeEnerahorn PrOJECI A A E A E N tdesesatenss 5 E NACO adios 4 CT CAI DA TUE AAA AAA A Ta nea 5 SOV UNS SCIP MONG US PAI indi e TO AUN A cacy a E ae caus wi ne eeee aie eee eonee teva sew eeesnmuerateeoteien 9 Imporins a model Homie CASE TOOL es ates eat wa wba pita sates wav AI AA AA IS Rea ced AR 9 VENTA LETONIA AS AAA Ai 12 Creatine AsO e Me raton der dd dida den cdo dad cin 12 Generatimora le demplate aaa OA TELAS 16 Ss AA A O O 18 IMPROVING THE AMA GENERATION alar dd 19 MENC OGETA O on a e a e 19 Creaton ora super LASSE SIS CIVIC as 19 Creatine asuper lass Name MATO A a A A i 24 Call the macro supere lass Namie esanen N e A N 25 CEUTA OC EE ate O i EE E O AE 26 Abite Genera A O 5 act eld E ce cha eels aa teats ee 28 Adde a template tor attribute declara isis A A RS A AA 28 Addins a template to senerate Me accessors iii 30 Generation ol the attributes Tom A ClASS isc a EEEE A A AAA E NES NEE 31 Creatina a macro wilh paranee Sean a dia 34 Parameters Namie A AAA 34 Paramete A ade saoniesatdons ania tad Sete adleb aia A E Senda anit cudimeiia mest E N N 34 Calling a seript with parameters m Java CPES ii A A A A A Rd 36 Calling ascript with parameters ima template ekara idad a aa 37 User Code Mnao CITC aa le o
12. This document is the property of Mia Software It cannot be reproduced even partially by any means without prior written permission Generation of the attributes from a class 1 Add a macro attributesDeclarations on the type UMLClass Types Categories Scripts e UMLAttribute 4 detaut 5 Scripts e UMLClass 5 Text Templates e UMLModelElement 17 El File Templates El JayvaGeneration Fl Macros D attributesAccessors e eae HEsttributesDeclarations e superClassName E Services 3 superClasses UlLClaz String attributesDeclarations return current apply attributes declaration Figure 43 attributesDeclarations macro This macro uses the method apply to call the template declaration in each UMLAttribute object returned by the service attributes defined in the package System and concatenates the results in the form of a string The result is then returned Note It is possible to mask the types for which no script is defined context menu View gt Mask empty types excluding System package Types Categories scripts e UbiL attribute 4 default 4 Scripts ee UMLClass 5 A v Alphabetic e UMLModelElemert 1 Templates iT accessor Y declaration emplate El Macras nn G Name typearre Services Inheritance w Mask empty types Figure 44 Display of types defining at least one script MIA Generation Tutorial e 31 This document is the p
13. e UML Attribute 4 default 6 Scripts ee UMLClass 6 E Text Templates Es UNLModelElement 1 Y toString El File Templates eee ER Macros E Services F String JavaGeneration public class nane extends superClassName attributesDeclarations attributesiccessors T tostring 7 HI Figure 54 Appel de toString dans JavaGeneration At this point the implementation of the method toString generated is fixed and all manual modifications will be lost during the next generation MIA Generation Tutorial e 38 This document is the property of Mia Software It cannot be reproduced even partially by any means without prior written permission Use the contextual menu Add tags on the toString template to add the BeginTag and EndTag scripts E Text Templates Y toString E File Templates H E JavaGene Properties l Macros Rename o pe attributes lt Q attributesL Pe d Generate Refactor Remove Cut Copy Faste Tt ae Declarations of p References Eo b aatas Become File Template Add precondition YJE ir Figure 55 Adding tags The scripts BeginTag and EndTag are templates themselves We can therefore call other templates or macros in these scripts The BeginTag script will allow you to delimit the beginning of the text zone that will be manually inserted and the EndTag will mark the end of this zone During generation if the file d
14. 4 Save the profile and the project using the Save button l from the toolbar Project will reference your profile and it can be restored at a later time MIA Generation Tutorial e 59 This document is the property of Mia Software It cannot be reproduced even partially by any means without prior written permission Creating scripts on the profile types The types defined in the profile appear in the Types tree You can then define scripts on these types exactly the same way as those for the base types of the meta model and benefit from the same functionality inheritance polymorphism etc Types e s UNL Callction e s UML CallEvert e UML Changer ye UMLClass 97 UMLClass Enumeration a s E eT ie UMLClassitierlnport e UMLClassitierlnstate e UML Collaboration e UMLComponent Categories default 3 l Scripts Scripts al Text Templates g le Templates HF JavaClassGeneration EE JavaGeneration El Macroz o attributesAccezsorz D attributesDeclarations Ga selectJavaGenerationkind e superClassName Services a Figure 88 Profile type in the Types tree Reorganizing scripts This tutorial provides a step by step walkthrough of the scripts reorganizing to manage profile 1 Delete the macro selectJavaGenerationKind You can use DEL key or Remove context menu from the Scripts list 2 Copy the content of template javaGenerationBody into the file template JavaGeneration
15. It cannot be reproduced even partially by any means without prior written permission Creation of a profile We are going to create a profile to manage our stereotype lt lt Enumeration gt gt 1 Create a new profile using the New Profile button from the toolbar Specify the name of our profile Tutorial x 2 Profile name E Tutorial Figure 85 Creation of a profile 2 The function Add from Profile Editor context menu adds a subtype to the selected type either a base type of the meta model or a type of the profile Add a type named Enumeration to UMLClass Profile elements Tutorial s UMLCallAction Add es UML CallE vent E Scenarios E m Tutorial 11 poe A UML ChangeEvert Edit E Packages o L T UML Class ie Gi System 328 i e UMLClassitierlnport Remove E Tutorial ae 7 New type x a New pepe name e k 77 Tutorial Ran pT ee Enumeration e Annuler og UNLDatal ype Figure 86 Creation of a type Edition Generation lt is possible to only show the types of the meta model that are extended by the profile context menu View gt Mask types without profile Profile elements Edition Generation HES Add Tutorial nannies El UMLClass ae 2 Enumeration Edit Tutorial 1 Rename Packages eee e Add n 1 i 1 System 329 13 Tutorial 18 Move Profile gS Tutorial 1 Figure 87 Enumeration type
16. into the tools lib directory 2 Use your classes in the scripts For this it is necessary to use the complete name including the name of the package MIA Generation Tutorial e 74 This document is the property of Mia Software It cannot be reproduced even partially by any means without prior written permission Context variable The macro generateAccessors uses a variable context The variable context allows the definition of variables that can be used in other scripts This interface provides some helpful services to build generators e services giving access to the generation environment like the generation directory or the project name e services allowing to read and write some values into a global variable map e services to handle the generation report if it exists Create a new macro generateAllAccessors using the context to save the information Generate Accessors between two calls This macro uses cancelGeneration method to cancel the generation process Types Categories Scripts e UML Attribute 5 defaut a Scripts e UML Class 9 E Text Templates e UMLClass Enumeration 2 File Templates e UMLModelElemert 1 Macros attributesAccessors i attributesDeclarations o e superClassName Services Boolean generateAllaccessorst String name current getName ij Boolean gqeneratedAccessorsUption Boolean context getVYalue qenerateAccessors if qenerateAccessorsO0pti
17. Deployment view UMLPackage e UMLModel 1 Logical View UMLPackage e UMLOperation 1 Ly ownedAssociations 6 e UMLPackage 7 H b ownedPackages 3 e UMLParameter 1 s Building UMLPackage e UMLPrimitive 2 e UMLSterectype 1 e UMLTagqgedalue 52 Ly ownedAesociations 4 H ownedClassifiers 3 Address UMLClass ds Building ULCla e Office UMLClass L package 1 on Company UMLPackage e Employee UMLPackage Attributes name Address object 3880584801 4c documentation visibility pubic A isSpecitication Figure 13 Model browser You can continue this process and traverse through all the objects in the model the packages contain classes which contain attributes etc Browsing through the model allows you to see how the model is loaded in the application including the links between the different objects which will make it easier to write the generation scripts MIA Generation Tutorial e 11 This document is the property of Mia Software It cannot be reproduced even partially by any means without prior written permission Testing a file template We are going to create a generation unit to test the JavaGeneration file template Generation breaks down into three steps Initially it is necessary to select scripts you want to test Then the objects to which the generation will apply must be chosen Then you just have to launch the generation C
18. MIA Generation Tutorial e 13 This document is the property of Mia Software It cannot be reproduced even partially by any means without prior written permission Objects Selection To select objects 1 Select the tyoe UMLClass from the Type combo box you will test scripts defined for this type 2 Click the Add button from the Objects list A Selection of UMLClass instances E x Type of objects lA UML horde with subtypes objects Available objects Dervices Deduced objects selected objects A Tutorial A Tutorial clientDependenciez constrainingElemerr constraints gt LIL E current UMiLMoc documents gt UML generalizations L amp implementationLoca importtedClassifiers Ok Cancel Figure 16 Objects Selection You can see required objects type in the dialog title We want to test a script defined on UMLClass type we must select UMLClass instances In the Type of objects combo box choose the type of objects that you wish to select All objects of the selected type will then appear in the Available objects list If you also wish to view the objects of the subtypes select the with subtypes objects checkbox Selection of UMLClass instances a x Type of objects Paani Ea eE F with Subtypes objects Available objects DErvices Deduced objects selected objects di Enumeration Rank behaviors gt UMILS Address A Building
19. UML AttriputeLink l E File Templates e UMLBinding E htacros Es UhiLCall ction O ME e UhiLCallEvent je typellame s UML ChangeEvert x Services String Hamet String name current getNamel return current getatring new Call identifier name Boolean TRUE 1 Figure 50 Calling identifer String Boolean macro from a Jave script Create a script name on UMLAttribute You can press CTRL C and CTRL V to get a copy named Name1 from the macro Name Rename it using Rename or Properties context menus from the Scripts list Types Categories Scripts ee UNLASSOcCaton A l default 5 Scripts s UMLAssociationClass E Text Templates e UMLAssociationEnd A File Templates S UL attribute 5 El Macros a UML AttributeLink po Name A UML Binding o e Es UMLCallAction en typeName al ce E arcas oe El s String name String name current getName ti return current getastring new Call identifier name Boolean FALSE 1 Figure 51 Macro name MIA Generation Tutorial e 36 This document is the property of Mia Software It cannot be reproduced even partially by any means without prior written permission Calling a script with parameters in a template To call a script with parameters from a template you must respect following notation e Scripts can only be called on the current object e To use script with parameters it must be framed by special characters and by default
20. a scenario To use allClasses service you must call it from a package The model is an instance of UMLModel wich is a subtype of UMLPackage and contains all other packages To explore all packages you just have to call allClasses service on the UMLModel instance cenario elements 55 classes Add Edit Remove i Objects Selection Type E UNLMocdel with subtypes objects Service REA gt UNMLClass File Templates Fl JavaGeneration UMLClass Add Edit Remove Figure 71 Tutrial Scenario modified to call allClasses service MIA Generation Tutorial e 50 This document is the property of Mia Software It cannot be reproduced even partially by any means without prior written permission Advanced concepts Using stereotypes Using stereotypes is a way to customize a model defining in fact new types The stereotypes defined on types are available with MIA Generation because this kind of object is part of the model and different generation choices could be based on the usage of stereotypes We are going to use a stereotype lt lt Enumeration gt gt in our generator to customize generation of enumerable constants Languages like Pascal and C let you define a set of enumerable constants like Color Red Green Blue which amounts to adding a new data type to the language These constants can be used for a typesafe index in an array or used in a loop Using enumerated constants can m
21. be reproduced even partially by any means without prior written permission This service will use ownedClassifiers and ownedPackage links defined in UML metamodel for the tyoe UMLPackage oppned Packages UML Package UML Classifier visibility Enumer ation Abstract owned Classitiers package 1 Figure 69 UMLPackage UML Classifier relationships Note UMLClass is a subtype of UMLClassifier Modify the text of the allClasses service Types Categories e UbiL attribute 4 defaut 1 de UMLClass 6 e UMLModelElement 17 File Templates E UMLPackage 1 Macros Services A MallClasses UmLClas Object allClasses UMLClass List allClasses new ArrayList List classifiers current getlist ownedClassifiers for Iterator i classifiers iterator i hasNextti UMLClassifier classifier UMLClassifierj i nexti if classifier instanceof UMLClass allClasses add classifier allClasse3 add ll current coll ect ommedPackages allClasses truej return allClasses Figure 70 Service allClasses With this kind of service you ll be able to filter model elements In the allClasses service there is only one filter applied the test of the type UML Class MIA Generation Tutorial e 49 This document is the property of Mia Software It cannot be reproduced even partially by any means without prior written permission Calling allClasses service into
22. cl Company Ay Director Le Division ce Employee Ay Office A lt sEnumeration gt Rank A Address A Building ate Company Le Director Ay Division z a Employee A Office cientDependencies constrainingElemerr constraints gt UML current UMLClas documents gt UMLI generalizations L El implementationLoca _ OK Cancel Figure 17 UMLClass objects Mae Tutorial 14 This document is the property of Mia Software It cannot be reproduced even partially by any means without prior written permission Then select a service from the ones available for the selected type Applied to the objects selected in the Available objects list the service may allow you to derive other objects By default the current service available in the standard version is selected which makes it possible to deduce exactly the same objects as those selected in Available objects This mechanism is very useful when you wish to launch a generation on a precise subset of objects Rather than selecting them by hand you can write a service that returns them automatically In this way for example you can easily and without any risk of omission launch a generation on all persistent classes of a model or on all subclasses of a particular class The selected service is automatically applied to each object selected in Available objects and the derived objects are placed in the Deducted objects list If
23. e 65 This document is the property of Mia Software It cannot be reproduced even partially by any means without prior written permission First of all you need to find the variable part of the generated script import javasuril public final class Color private String id public final int ord private Color prev private Color next private static int upperBound 0 private static Color first null private static Color last null private MN string anID this id anID this ord upperBound 4 if first null first this if last null this prev last last next this last this i public static Iterator elements return new Iterator private Color cure o inst public boolean hasNext return curr null public Object next CUE curr curr next 0 return c public void remove throw new UnsupportedOperationException bi publico tring To teo return this id public static int size return upperBound i public static Color first return first public static Color last return last public Color ide return this prev public Color next return this next MIA Generation This document is the property of Mia Software It cannot be reproduced even partially by any means without prior written permission Tutorial e 66 The script editor is WYSIWYG What You See Is What Yo
24. or Properties context menus from the Scripts list Types Categories Scripts e UML Attribute 5 defaut 5 Scripts e UMLClass 10 E Text Templates e UhiLiModelElement 13 cl accessor e UMLPackage 1 saa IT declaration Zw nunerstedConstantDeclaration A a File Templates El Macras oe G Name HON G typename SB VICES T String enumeratedConstantDeclaration public static final int name initialValue Figure 80 Enumerated Constant Declaration MIA Generation Tutorial e 55 This document is the property of Mia Software It cannot be reproduced even partially by any means without prior written permission 6 Test your modification on a new Generation Unit JavaGeneration UMLClass Select Rank and Adress objects using the service allClasses on UMLModel ae Selection of UMLClass instances 7 x Type of objects A UML hoch with subtypes objects Available objects A Tutorial Services Deduced objects allClasses UMLC JE behaviors gt UMLSt Address Le Building e Company e Director Selected objects clientDependenciez constrainingElement constraints gt UMLC S current gt UhMLMode e Division documents UMLD de Employee Office generalizations UY H DRK Cancel Figure 81 Rank and Address selection Generation Units JavaGeneration UMLClass Type s UMLClass Scripts
25. recent P Profile 9 Package Properties es Profile Rename Model Reload Close Save Save 45 Export p Figure 2 New gt Project menu Specify the name of the new project de New Project E Metamodel E UNL Marne Tutorial cancel Figure 3 Creation of a Project The project navigator now shows you the Tutorial project that you created MIA Generation Tutorial e 3 This document is the property of Mia Software It cannot be reproduced even partially by any means without prior written permission Creating a package Each generation script must be attached to a package The purpose is to be able to organize in different entities the scripts written for different requirements However the only one present when MIA Generation is started is the package System which cannot be modified This package System contains all the base scripts for accessing the loaded model To create a package named Tutorial click the New Package button 5 from the toolbar and specify the name for the new package New Package x 2 Mame of the new Package E Tutorial Figure 4 Creation of a package The project navigator now shows two packages the package System and your newly created package MIA Generation Project Tutorial l 10 x File Edit Window Help 3 Ale AP gt aA AA AM AAA Edition Generation Types Categories Scripts Tutorial A UMiLModel
26. tab Variables age current Director odel name Director He Tutorial moll eneration object 2580555801 399 E a documentation E i Results 2 Edition Generation Director UMLClass aa Address java isRoot E Cyl i e cial da E e dayaGeneration izbbetract To E E davaGeneration Address E E davaGeneration Director visibility pubic El El HA JJavaGeneration Filename Director is Active _ lt lt name Director B superClas Name Director dicas cti H a fsuperClasses Director o namety Employee Object superClasses UMLClass attributesDeclarations Director attributes 4 ccessors i Director A T toString Director return current collect Generalizations parent Result Yector n Employee UMLClass Figure 37 Generation trace of JavaGeneration Each nodes contains e The object of the model on which the script has been called e The called script e The text generated by the call of the script on the object e The nodes created by the call the call can launch other scripts calls MIA Generation Tutorial e 27 This document is the property of Mia Software It cannot be reproduced even partially by any means without prior written permission Attribute Generation We are going to improve our Java generation to add the declaration of attributes and some attribute accessors Adding a template for attribute declarati
27. use File gt Save lt Package gt from the main menu bar Note For each saving of a package a backup file is created from the old file renamed by adding the extension bak Remember to save your package by using the Save button l from the toolbar e MIA Generation Project Tutorial g O x File Edit Window Help MEERI TEI ELEL Ar EL Eaton Renee ation e __ Categories Scripts Es UMLChangeEvent SEE po Scenarios ee UMLClass 1 dei as e i El File Templates E Packages e UL Claszifier a eee no System 328 e UMLClassifierlmport haere E Tutorial 1 e UMLClassitierInState es Profile e Uhl Collaboration E Ez ES Documentation po Enregistrer dans Ej E Mom de fichier Tutorial pkg Enregistrer Tous les fichiers Annuler File Template JavaGeneration package Tutorial category default modified 19 05 03 Figure 9 Saving a package MIA Generation Tutorial e 8 This document is the property of Mia Software It cannot be reproduced even partially by any means without prior written permission Loading a model The models used for generation are managed from the Generation panel MIA Generation only manages one model at a time This model can be imported from a CASE tool Importing a model from a CASE tool You can import a model created with a CASE tool using the Load button 3 7 and the Model item e Model from the toolbar MIA Generation is c
28. NL Tutorial mol y UMLASzociation 11 Instances 4 UMLAssociationEnd 22 ons Tutorial UMLModel ee UMLAttribute 16 EL ownedPackages 4 e UMLClass 8 e UMLGeneralization 1 e UNMLModel 1 e UMLOperation 1 ee UMLPackage 7 e UMLParameter 1 e UMLPrimitive 2 e UMLStereotype 1 e UMILTagged alue 52 s Component views UMLPackage rt Deployment View UMLPackage e Logical View UMLPackage Ay Use Case View UMLPackage Attributes name Tutorial objectld 3280589601 De Documentation Error documentation o documentation visibility pubiic E Isspecitication m isko D El Model gt Tutorial rel Figure 12 Model browser MIA Generation Tutorial e 10 This document is the property of Mia Software It cannot be reproduced even partially by any means without prior written permission Once the model is loaded MIA Generation opens the model browser on the principle element the object UMLModel While expanding the instance tree you can view that this model contains four packages that the Logical View package contains a Building sub package that this package contains an Address class etc UML Tutorial mdl Meta objects Address UMLClass ey UMLAssociation 11 Instances ri e UMLAssociationEnd 22 EH Tutorial UMLModel e UNLAttribute 16 E L ownedPackages 4 e UMLClazs 3 e Component View UMLPackage e UMLGeneralization 1 e
29. TANT E Cel E enumeratedCon tantDeciaration MANAGER JE davaGeneration Address Figure 83 lt lt Enumeration gt gt Rank For the class Address ee eo Generated text reloaded from Address java del i Class Address extends OB e ct a int number LA Tutorial mall is Steing SCree ct i eneration Sy Parameters hair ci a T Results 2 String city String country int getNumber leu JaveGeneration return this number A F davaGenerationg lt Enumeration gt Rank E F Jlavabeneration Address ES HW JavaGeneration Filenamec Address public void setNumber int value selectlavaGenerationKind Address this number value fisEnumeration Address y HIT iaveClassBodyQ Address ublic String getStreec E turn this street Figure 84 Address MIA Generation Tutorial e 57 This document is the property of Mia Software It cannot be reproduced even partially by any means without prior written permission Using profile With stereotypes many scripts will have to check the stereotype of the model elements to foward the generation using another script more appropriate to this stereotype For example a class could be stereotyped Table Enumeration or Business to denote a mapping to database concepts an enumeration definition or a business entity and scripts would look like this if stereotypeName equals Table E Tels les else if
30. Templates ee UbiLiModelElemernt 13 El El JavaGeneration Macros 3 attributesDeclarations Services String attributezDeclaration return current apply attributes enumeratedConstantDeclaration Figure 93 Macro attributesDeclaration on UMLClass Enumeration 7 Update Filename properties for the two file tempates JavaGeneration HA String Javatreneration Filename name Java Figure 94 Filename of file templates JavaGeneration We have finished scripts modification We are now going to test it on Rank and Address objects MIA Generation Tutorial e 63 This document is the property of Mia Software It cannot be reproduced even partially by any means without prior written permission You can see that new scripts defined on UMLClass Enumeration are correctly used to generated enumerated constants declaration o K E MIA Generation Project Tutorial with profide File Edt Window Help AA E SEMEN A current c Epumerstions Rank Ection Generalin lt lt Enumeratlon gt gt Rank UML Class Enumeration fede sama fa 23 4 COMPA mal Caneralion obert etarsen Ay Por ameters me Results 2 documentation E Rsnkjar isRoot E Address pwa yf Trace skeat I lec JdaveGeneration r String JavaGeneradion 1 Cs public class mame T Jove Gernerscont Address ateriburszDeclarations 1 MI Generated bei public c
31. WYG without programming the text that must be produced We are going to see how to modifiy this template to generate Java class body for each UML class from the model MIA Generation Tutorial e 6 This document is the property of Mia Software It cannot be reproduced even partially by any means without prior written permission Modify the text of this template Validate your modifications with the context sensitive menu Save in this textbox or by using the keyboard shortcut CTRL S Types Categories Scripts E UML ChangeEvent E AAA o 7 lat Text Templates UMLClass 1 vt acs Al E File Templates a eli oF JavaGeneration k UMLClassitierlmport Ms e UhiLClassifierinState ae Serie e UbiLCollaboration A Uhl C aomannnent gt F String JavaGeneration a lt k public class name T Undo Ctrl z HI Redo Ctrl cub Ctr Copy Ctre Faste Ctrl Select all Cher O Savetext Ctrs Restore kext Ctrl F Find Replace Ctrl F Frink Ctrl P VIEW Figure 8 Changing the generated text Scripts describe how text can be generated from a model There is two types of scripts Generation models or templates a template is text which describes in a visual manner the way in which the code must be generated for an object type of the model The script editor is WYSIWYG What You See Is What You Get Java scripts Because everything cannot be expressed as WYSIWYG scripts written in Java are used Ther
32. ake code more readable A frequently proposed alternative is the use of Java s static finals In Java such objects are most often known as enumerated constants For example you might want to define a new data type named Rank with constants DEVELOPER CONSULTANT and MANAGER as its possible values lt lt Enumeration gt gt Rank DEVELOPER 0 CONSULTANT 1 MANAGER 2 public class Rank public static final int DEVELOPER 0 public static final int CONSULTANT 1 public static final int MANAGER 2z I Figure 72 lt lt Enumeration gt gt class MIA Generation Tutorial e 51 This document is the property of Mia Software It cannot be reproduced even partially by any means without prior written permission 1 Create a new template named JavaEnumerationBody Types Categories Eo UML Attribute 4 detautt 7 oy UMLClass 7 e UMLModelElement 1 ee UMLPackage 1 T String javaEnumerationBody public class name iT attributesDeclarations A Scripts Scripta Text Templates e T AM ET toString El File Templates IF JavaGeneration El Macras o attributesAccessorz lt lt attriputesDeclarations o superClassName E Services 8 superClasses UML Class Figure 73 javaEnumerationBody Template 2 Copy the content of file template JavaGeneration to a JavaClassBody template on the UMLClass type T String javaClaseBody ublic class name ex
33. ame macro MIA Generation Tutorial e 25 This document is the property of Mia Software It cannot be reproduced even partially by any means without prior written permission Generating trace If we now regenerate the files with the classes Address and Director the Java class Address extends the Object class and the Java class Director extends the class Employee You can activate trace at the time of generation Generation options JavaGeneration l x i General El File Ge Trace Report r Generate trace Cancel Figure 35 Traces options If we now regenerate the files with the classes Address and Director the Java class Address extends the Object class and the Java class Director extends the class Employee Generated text ublic class Director extends Employee Edition Generation adel e Tutorial rdl eneration El Aa Parameters Er Results 2 wl Address java eee irector E wa aot Trace Figure 36 Generation of the superclass MIA Generation Tutorial e 26 This document is the property of Mia Software It cannot be reproduced even partially by any means without prior written permission A trace contains a list of generation nodes Each node describes the call of a script on an object of the model If the generation has been traced Generate trace option was enabled at the time of generation you can browse the trace in the Navigator tree from the Generation
34. apable of importing models from many tools Therefore you must choose the type of model to import e Open Model Select the format of the file Rational Rose MBL hl Chal AM Rational DE Poseidon 4rqoUhL Cancel Figure 10 Model formats Once you have chosen the format you can select the file to analyze Choose Rational Rose for the import format and open the Tutorial md1 file Open Model Rechercher dans _ models T Company well H Tutorial mal Ea eee S Bureau Norn de fichier Tutorial mal Ouveit Mes docume a Fichiers du type Models mal Annuler Figure 11 Selection of the model to import This file is located in the directory lt MIA Generation gt metamodels UML examples models The imported model then replaces the current model in MIA Generation MIA Generation Tutorial e 9 This document is the property of Mia Software It cannot be reproduced even partially by any means without prior written permission The model can be viewed using the browser integrated into MIA Generation This browser allows navigating through all the objects of the model And for each object its properties and attached objects can be viewed He Mia Generation Project Tutorial 5 x File Edit Window Help ose HFS a E A yy Sd Edition Generation UML Tutorial mdl B25 Db eS gt odel Meta objects Tutorial UlvdLidocie U
35. ars lt lt isEnumeration hd Boolean generate 4ccessorst String name current getNamel int n javax swing JUptionPane showlonftirnbialog context qetFrameli Do you want to generate accessors for name class Java Generation UMLClass name javax swing J0ptionPane YES NO OPTION return new Boolean n Javax sawing JOptionPane YES OPTION Figure 104 Macro generateAccessors String attributes 4ccessors if current getboolean generateaccessors return current apply i attributes accessor else return rrrr a F Figure 105 Macro attributesAccessors MIA Generation Tutorial e 73 This document is the property of Mia Software It cannot be reproduced even partially by any means without prior written permission A dialog box allow you to generate or not accessors Java Generation UMLClass Employee x C 7 Do you want to generate accessors For Employee class Figure 106 generateAccessors Dialog Box Note In Java scripts you can use any external Java component from MIA Generation The tools lib directory in MIA Generation install directory contains all the user Java components files used by MIA Generation All of JAR or CLASS files in this directory are added to MIA Generation classpath at runtime Access to external Java components is done in two steps 1 Copy your components JAR file or the directory containing your compiled classes
36. cation date Attributes P Read only Single evaluation Signature Documentation Returned objects kind BE LUMLClass Parameters Add Edit Remove Remove Figure 24 Service properties MIA Generation Tutorial e 19 This document is the property of Mia Software It cannot be reproduced even partially by any means without prior written permission Types e UMLCallEvent e UMLEhangeEvent S UNLClass 2 e UMLClassitier e UML Classifierlmport e UMLClassifierlnState e UML Collaboration re UML Component El Object superclasses gt UMLClass ERC CUECREE Categories Scripts defaut 2 Scripts A ae Text Templates El File Templates FFI esllacros davaceneration Services Figure 25 Cr ation d un service This service must return the superclasses of the current class euperClasses UMLClass In order to see how an inheritance link is instantiated in UML go to the Model browser We are going to look at Employee relationships Office from Building toccupants employees Company from Company 4 ton Address from Building head 1 ln Hellows MIA Generation Figure 26 Employee relationships This document is the property of Mia Software managed divisions On Division 1 ifrom Company Tutorial e 20 It cannot be reproduced even partially by any means without prior written permission
37. cripts S UMLAttribute 5 defautt 1 Scripts e UMLClass 7 Text Templates e UML Class Enumeration 1 El File Templates 4 UMLModelElemert 1 El EPA hMacroz Set Vices F String JavaGeneration public class name iT attributesDeclarations 7 HM Figure 91 File Template JavaGeneration on UMLClass Enumeration 5 Delete the stereotype test into the macro attributesDeclaration Types Categories Le UML Attribute 5 default 7 1 e UMLClass 7 E Text Templates e UMLClass Enumeration 1 Ed File Templates e UliLiModelElement 1 El Macros se attributesA4ccezsorz did MisttributesDeclarations a isEnumeration ee superClasshlame E Services String attributesDeclarations return current apply attributes declaration Figure 92 Macro attributesDeclaration on UMLClass MIA Generation Tutorial e 62 This document is the property of Mia Software It cannot be reproduced even partially by any means without prior written permission 6 Copy this macro attributesDeclarations on the UMLClass Enumeration using Refactor gt Copy from the Scripts list context menu or Copy Paste functionnality Modify the content of the copied script to call the template enumeratedConstantDeclaration on each attribute of the enumeration Types Categories Scripts e UMLAttribute 5 defaut 2 Scripts ee UMLClass 7 me Text Templates i UML Class Enumeration 2 E File
38. e As a script can be itself a parameter evaluated on the current object of the model it is necessary to have access to parameters with a special keyword args You must use the keyword args to reference a parameter in a template ex args myParameter e f you put directly a parameter into a template ex args myParameter parameter is converted to a String using the java lang String valueOf Object method e Parameters must be called between brackets ex myScript args myFirstParameter args mySecondParameter e A script without parameters can be called with or without brackets ex myScript or myScript Primitive types and String used as parameters You can use primitive types in a template int boolean etc or strings as parameters They will be convert into Java objects because a parameter must be an instance of Object Expression Java Object true java lang Boolean TRUE false java lang Boolean FALSE 1 java lang Integer 1 2 java lang Float a Java lances Claiede tem text Java lang String null null For example we are going to use a call to Name macro for the getter and a call to identifer String Boolean inside the template for the setter YT String accessor public typeNane get Name 41 return this name 7 HI T public void set identifier inane true i typeNane value this name value HI T Figure 52 Calling identifie
39. e are two kinds of JAVA M scripts macros which are evaluated for a model object and whose result is text or JAVA objects and services wich are special macros that enable you to return objects from your model The name script is a Java script a macro which returns a String that represents the name of the current class This macro is defined in the System package which contains all the base scripts for accessing the loaded model To distinguish scripts names they are framed by special characters and by default which can be modified according to generation requirements see the user manual Preferences chapter This template will now generate the text public class followed by the name of the class of the loaded model within which this script will be evaluated call of the script name defined in the System package followed by two curly braces MIA Generation Tutorial e 7 This document is the property of Mia Software It cannot be reproduced even partially by any means without prior written permission Saving a script and its package When you modify the text of a script you can validate it using with CTRL S shorcut or Save Text context menu from edition area Text is compiled but not saved into file saving a script is carried out by means of saving the package in which it is contained To save a package and scripts it contains a package must be selected click the Save button lal from the toolbar or
40. em using the method getString which returns the name of the class With the method getString it is possible to call a template or macro and to get the string that results from its evaluation Types Categories e UMLCallEvent a default 3 e UMLChangeEvert e UMLClass 3 i s UMLClassitier e UMLClassitierlmport da UML Clazsitierlnstate e UMLCollaboration e UML Component String superClassHame scripts Scripta E an Text Templates El File Templates E E JavaGeneration El Macras ri uperClas Mame E Services oe sliperllasses UMLClass List superllasses current gethList superClasses if superClasses isEnmpty 1 return Object else UMLClass first uperClass UMLClass superClasses get 0D return firstSuperClass qecstring Javalame Figure 33 Creation of a macro superClassName Call the macro superClassName This macro still needs to be called from the Java Generation File Template Types Categories e UMLCalEvent a default 3 e UMLChangeEvent s UMLClass 3 y e UMLClassitier e UMLClassitierlmport e UML ClassitierInState e UML Collaboration e UML Component F String JavaGeneration E ae Text Templates El File Templates E El JavaGeneration El Macras gt superClassMame E Services i superClasses UMLClass public class name extends superClassName HM Figure 34 Call to the superClassN
41. emplate EY button from the toolbar or use New gt File Template from the Scripts list context menu 3 Specify the name of the new file template javaGeneration e Add File Template x F File Template JawaGeneratior e Type UNLMocdel 3 Package Tutorial Category detant Creation date Modification date Attributes Read only single evaluation Documentation Figure 6 File Template properties MIA Generation Tutorial e 5 This document is the property of Mia Software It cannot be reproduced even partially by any means without prior written permission The Scripts list now shows you the File Template that you created with the text generated text created by default 32 MIA Generation Project Tutorial AS File Edit Window Help y hk a i ene ar a le A a oO a Vagatla fi FFF FS 6 E Edition pees ation Types pue ear Scripts A W Tutorial l UML ChangeEvert ee Templates Scenarios ee UMLClass 1 eae Sl File Templates Fl Packages de UML Classifier a eee a W System 3207 e UlhiLClassifierlmpor l g RER E Tutorial 1 e UMLClassitierInState eee Profile e UMLCollaboration e ees s UMLComponent main ner F String JavaGeneration generated text File Template JavaGeneration package Tutorial category default modified 19 05 03 Figure 7 Scripts list and Script edition area A template allows you to specify in a manner WYSI
42. ers know that such tasks can and should be pulled into a core framework built and tested once and reused across multiple projects In its simplest form a framework is simply a body of tried and tested code that is reused in multiple software development projects Using generators and frameworks reduce development time while improving delivered software quality which means that developers can spend more time concentrating on the business specific problem at hand rather than on the plumbing code behind it For example the Safe Type Enumeration pattern can be pulled into a framework class AbstractEnumeration IMpOrG Java ucal public abstract class AbstractEnumeration private String id public final int ord private AbstractEnumeration prev private AbstractEnumeration next private static int upperBound 0 private static AbstractEnumeration first null private static AbstractEnumeration last null protected AbstractEnumeration String anID this id anID Ghis c0rd gt UPpperBounas gt if first null first this 1f last null this prev last last next this last this public static Iterator elements return new Iterator private AbstractEnumeration curr first public boolean hasNext return curr null public Object next Abstractinumeration C Curr Curr curr basicNext p return c public void remove throw new UnsupportedOperationException
43. es 38 Filename TES OUR doi 42 GENERATION BY CENAR IO os 45 CTC ONIN OSCENO O EEEE E A eS i PRESTR see G5 GSR ERC tale Ciao aan Eh 45 USING Servi CES TIO SCONOTIOS A A adds 48 Gettinesalliola SSCS scars aco O etait te ORs Ab mae Unas 48 Cathie alii lasses Service MO AC T A ETE ia 50 ADVANCED CONCEPTS sE res iia caos 51 OSME DOE IAS EAS AA AA AE A AS 38 Crea 00 ters O a a ess 59 Ercatine Sch pts On the Probe PES A A eacandaesons 60 Ur va A E R Lads 60 Coding CONVENTIONS patterns and frameworKks cooooooooonncnnnnnnnnnncnnnnnnnannnonnnnnnnnnnnnnnnnnnnrn nono nn eee No SEEVE KEEA EEA Sa niis 65 Eddie son ventions and Palle ENS a A A A E keine 65 CAE WO Sestao 71 Using d ZS COMPONCTILS INTO S CEPIS a A AS 73 MEA TAS Mes esc as sa slates eaee nana e ccc acta tyes scenensheses sts seneiAsthoass a A es cates tayaaaasaete eeeescnct yas 7 MIA Genera non A O eset iinse cnetslaesanoaaraend oc clnaehytcs IF MIA Generation Tutorial Table of contents e i Tutorial Presentation The goal of this tutorial is not to present all of the functions available MIA Generation but to introduce you to this working environment and to have you discover with the aid of a simple example of Java code generation the fundamental principles of generation with MIA Generation The example presented in this tutorial utilizes MIA Generation for UML All scripts defined in this tutorial can be found in Tutorial projects in the directory lt MIA Generati
44. files Coding conventions and patterns Coding conventions can be translated into generation scripts If the code is generated it is possible to ensure a single presentation format which allows the code to be more readable and thus easier to maintain For example getters and setters are coding conventions you can used to write your generator In the previous examples you have used a simple pattern the use of Java s static finals known as enumerated constants Still there are a couple of drawbacks to using static final integers The major drawback is the lack of type safety Any integer that is calculated or read in can be used as a Rank regardless of whether it makes sense to do so We are going to see step by step how to build a generator from a prototype implementing a pattern Safety Enumeration for Java s enumerable constants The process used could be applied for any other kind of files you need to generate The goal is to define a variable of tyoe Rank so that you get a compilation error rather than a runtime error whenever an invalid value is assigned to that variable An elegant solution is to use a static final Class with private constructor This implementation is a variation of the Singleton pattern that limits the class to a predefined number of instances Load the project saved into the file Tutorial_Pattern_Start pr3 This project contains an initial generator we are going to upgrade MIA Generation Tutorial
45. he Launch Generation button IF from the toolbar We produce the correct filenames taking into account the name of each class Generated text Edition Generation ublic class Address adel lt lt Tutorial mel eneration El Sa Parameters Results 2 dress java a Building java Flee Trace Figure 23 Results of the generation with the correct filenames MIA Generation Tutorial e 18 This document is the property of Mia Software It cannot be reproduced even partially by any means without prior written permission Improving the Java Generation Inheritance Generation We are now going to improve our Java generation to include class inheritance We must insert the name of the superclass in the generated text for the current class or Object if there is no superclass Creation of a superClasses service To generate name of the superclass in the generated text we have to get parents from a class in the loaded model Services are special macros that enables you to return objects from your model Create a service named superClasses on the type UMLClass using the button A service is a script written with in Java that does not return a string but one or more objects from the model You must specify the type of return object for the service select UML Class de Add Service x Service superClasses oe Type UMLClass 3 Package Tutorial g Category detant Creation date Modifi
46. hods for converting objects to values of the primitive type getBoolean invokes a script matching the specified call a script whose evaluation result represents a boolean value It returns true if the evaluation result is Boolean TRUE or it is equal ignoring case to the String true using Boolean valueOf String MIA Generation Tutorial e 54 This document is the property of Mia Software It cannot be reproduced even partially by any means without prior written permission Attributes of an lt lt Enumeration gt gt class must be not generated like those of standard Java class Modify the attributesDeclarations macro on UMLClass to branch attributes generation Types Categories Scripts ce UNMLAttribute 5 default 10 Scripts e UNILClass 105 oy UMLModelElement 13 Text Templates File Templates El hMacros co attributesAccessors attributesDeclarations isEnumeration selectlavaGeneratlionkind e superClassNarme Services String attributesDeclarations if current getBboolean isEnumeration return current apply attributes enumeratedlonstantleclaration else return current apply attributes declaration Figure 79 attributesDeclaration Macro 5 Create a new template named enumeratedConstantDeclaration to declare Java s static finals You can press CTRL C and CTRL V to get a copy named declaration from the template named declaration Rename it using Rename
47. hoose the type of first level objects that you wish to select During generation all objects of the selected type will be selected If you also wish to view the objects of the subtypes select the with subtypes objects checkbox 2 A service must be selected from the ones available for the selected type Applied to the objects selected with the Type combo box the service may allow you to derive other objects By default the Y current service available in the standard version is selected which makes it possible to deduce exactly the same objects as those selected with the Type combo box This mechanism is very useful when you wish to launch a generation on a precise subset of objects Rather than selecting them by hand you can write a service that returns them automatically In this way for example you can easily and without any risk of omission launch a generation on all persistent classes of a model or on all subclasses of a particular class Select UMLClass type and current service to get all classes without filter File Templates selection The selected service is automatically applied to each object of the selected type and the derived objects are used to evaluate file templates In the File Templates list there will appear every Files template defined and loaded for the Returned Objects Kind of the previously selected service Select JavaGeneration file template and save your scenario using the save button lel from the toolbar
48. ier String Boolean macro In Java scripts parameters can be used as any other variable MIA Generation It cannot be reproduced even partially by any means without prior written permission This document is the property of Mia Software Tutorial e 35 Calling a script with parameters in Java scripts There are two ways to reference scripts in constructs that handle scripts calls action apply etc You can reference a script using e a String object this can be used to reference a script by its name assuming this script does not expect any parameter e a Call object this is to be used to call a script that expects parameters Also to call a script with parameters from another Java script you must use a Call object instance of mia gen openapi Call This class is aimed to create Script calls to be used in MlAObject contructs like action apply etc Note that creating a Call instance does not directly invoke the referenced Script The evaluation is done using a MIAObject construct like the action method Althought a Call instance can refer to a Script that does not expect any parameter using the Call String constructor this class is mainly aimed to call script which expects evaluation parameters A typical use may be Types Categories Scripts EAN ARREN a 18 detautta Ecripts e s UMLAssociationClass El Text Templates e UMLAssociationEnd y 3 a F accessor e UML Attribute 4 ef declaration de
49. lass Fent public geacic Final ine DEVELOPER 0 public static final inc CONSULTANT 1 public static final int MANAGER E Documentation Ens 9 Cu en E 102 0d Figure 95 JavaGeneration Trace Profile enables to use polymorphism rather than if statements Polymorphism is used to call the file template JavaGeneration defined for the real type of the evaluated object UML Class or UML Class Enumeration If you want to generate Enumeration and UML Class in the same scenario without using the service allClasses you will need to check with subtypes objects because Enumeration is a subtype of UML Class Scenario elements E Classes dd Edit Remowe Objects Selection Type E UMLClass Service 8 current UMLClass File Templates Fl JavaGeneration UMLClass Add Edit Remove Figure 96 Modified Scenario MIA Generation Tutorial e 64 This document is the property of Mia Software It cannot be reproduced even partially by any means without prior written permission Coding conventions patterns and frameworks The design choices can be translated into coding conventions patterns and frameworks The architecture of MIA Generation is completely open It is entirely centered on one need to connect the model resulting from the analysis phase to the generation scripts that reflect the design choices By means of this connection MIA Generation generates the
50. ls Enumeration return Boolean TRUE else return Boolean FALSE Figure 76 isEnumeration macro MIA Generation Tutorial e 53 This document is the property of Mia Software It cannot be reproduced even partially by any means without prior written permission 4 Create a new macro named selectJavaGenerationkind to make generation choices based on the usage of stereotypes Modify JavaGeneration text to call it Types Categories Scripts Ss UMLAttribute 5 detaut 10 Scripts e UMLClass 10 E Text Templates e UMLModelElement 1 E File Templates e UMLPackage 1 Fe El aya ceneration Macros Services F String JavaGeneration selectJavaGenerationEkind Figure 77 JavaGeneration file template The selectJavaGenerationKind is the following Types Categories Scripts e UML Attribute 5 defaut 10 Scripts e UMLClass 10 E Text Templates e UMLModelElement 1 E Pile Templates e UMLPackage 1 Macros attributesAccessors ae attributesDeclarations isEnumeration Selectlavalene rationkind fe GD superClassName Services String selectlavaGenerationkindi if current getboolean 1lesEnumeration return current getatring Javaknumerationbody else return current getstring javallassBody Figure 78 selectJavaGenerationKind Macro Note In MIA Generation scripts return Object MIAObject provides several useful met
51. me value File name public Rank getRank return this rank Relative path Failed preconditions public void setRank Rank value this rank value Figure 60 Sorting generation results MIA Generation Tutorial e 42 This document is the property of Mia Software It cannot be reproduced even partially by any means without prior written permission Edit the generated file with a text editor e g Notepad and modify the implementation of the method toString of course without modifying the BeginTag and EndTag Employee java Bloc notes l Ioj x Fichier Edition Format 7 class Employee extends Object String name string first name Rank rank String getName f return this name void setName String value this name value string getFirst name return this first name Wold setFirst name string value this first name value Rank getRank return this rank void setRank Rank value this rank value public String tostring i ff Start of user code toString method body return this getName if f End of user code I I Figure 61 Manual modification of the generated code MIA Generation Tutorial e 43 This document is the property of Mia Software It cannot be reproduced even partially by any means without prior written permission Regenerate the file using the Regenerate item from the Results context menu y Parameters Results 1 E
52. mission The macro typeName returns the attribute type name using the link named type between an attribute MIA Generation and its owner UML Attribute multiplicity String changeability Enumeratio UML Classifier largetScope Enumeration Ab tract HinitialWalue String PENE persistence Enumeration derjved Boolean Figure 39 type link Types Categories Scripts a detant 4 Scripts E Text Templates Y declaration a File Templates da UMLAssociationClass e UMLAssociationEnd Loy e UNL Attribute 4 e UML AttributeLink e s UMLBinding e UMLCallAction Services de UL CallEvent ait 4 String typeNlame LClassifier type UMLClassifier current action type l if type null ESLUEM Seeing else return type getName Figure 40 Macro tyoeName Tutorial e 29 This document is the property of Mia Software It cannot be reproduced even partially by any means without prior written permission Adding a template to generate the accessors Create a second template named accessors to generate accessors for this attribute Edition Generation Types Categories a AscacistinFr RQ Defaut e UMLASsociationEnd ajj detautt 2 ip eee e UML Attribute 2 E Text Templates GPa e UMLAttributeLink a pvt accessor i aie MM System 328 e UMLBinding elena ee Pina e UMLCallAction File Templates Profile e UMLCallEvert EJ Macros Services e UMLChangeEvent
53. n Method summary Repomtlomparisonstatus Reponflement veld pancelGeneration ReponGeneratedAle Cancels he generation process ReportcenerationSatus void ol ear i Repornihiodei ile Clears the entire context map Ey removing all its variables ReponPackage Hopon rons Henorneroject jawa lang ttring get java lang 5tring key Reads a value trom the context map Repone canario Javan swing PES ect Frame Caves an access to a frame if the generator runs inte a sraphical ermarentnent Termin m La Poste de travail Z Figure 110 MIA Generation Javadoc MIA Generation e 77 This document is the property of Mia Software It cannot be reproduced even partially by any means without prior written permission
54. n easily without knowing how the generator was implemented generate an entire collection of files These scenarios will be used in MIA Generation Developer by endusers MIA Generation Tutorial e 47 This document is the property of Mia Software It cannot be reproduced even partially by any means without prior written permission Using services into scenarios Services are special macros that enable you to return not text but objects from the loaded model For example you can write services to recover all abstract classes of a model or recover all persistent attributes of a class With a service you are able to recover objects into scenarios like you do manually from a generation unit We are going to create a new service named allClasses to get all UMLClass instances Getting all classes Create a new service named allClasses on the UMLPackage type Returned objects kind is UMLClass He Properties of allClasses xX B Service lalClasses gk Type UMLPackage 3 Package Tutorial vvithout stereotype g Category default Creation date mercredi 26 mai 2003 09 30 35 Modification date mercredi 26 mai 2003 09 30 56 Attributes P Fead only Single evaluation signature Documentation Returned objects kind lA UMLClass im Parameters Add Edit Remove cs Figure 68 Creation of a service allClasses MIA Generation Tutorial e 48 This document is the property of Mia Software It cannot
55. nature Documentation Java Return type String P et arameters TEREN id String firstLetterToUpperCase Boolean Edit Remove Cancel Figure 48 Creation of a macro with identifiers Parameters naming The name of a script or a parameter must be a valid Java identifier current and context keywords are reserved Parameters type Parameters must be Java objects instances of java lang Object To call a script with parameters from a template MIA Generation convert primitive types to wrappers ex int to Integer boolean to Boolean MIA Generation Tutorial e 34 This document is the property of Mia Software It cannot be reproduced even partially by any means without prior written permission The identifier String Boolean macro is the following String identitier String id Boolean firstLetterToUppercase if id null retur if id lengthij else rrr F return id 1d 1d replace a a replace le replace e replace le Pre lace eo E replace 1 i teplace o 0 replace 0 o0 Teplacel ro replace i i u replacei 1 replace u u Eeplare 274 PEEPIAGe oe PEeP eee ty eee fLeplace EEplace eo he if firstLetterToUpperCase booleanvValue id Character tolpperfase id char4t 0 id substring l return id Figure 49 Identif
56. nd Replace context menu from the text area Call the macro attributesDeclaration to generate attributes declaration Types Categories Le UNL Attribute 5 defaut 2 eis UMLClass 7 e UMLClaes Enumeration 2 F String JavaGeneration import java util public final class name attributesDeclaration private String id public final int ord private name prev private name next Find wha Scripts Text Templates Erie Templates E El JavaGeneration HHitacros AD attributesDeciaration Find Replace on JavaGeneration Bj lc olor Find Mext Replace wih firemen Replace Whole word C Up Replace Next Iv Matchcase f Down Werte Se Replace All Close private static int upperBound O private static name first mull private static name last mull private name String anid f this id anTD this ord upperBbound if first mull Figure 101 File Template JavaGeneration String attributesDeclarationat List 30rtedAttributes current s0rt attributes initialValue return current apply soarted ttributes enumeratedlonstantbeclaration Figure 102 Macro attributesDeclaration Note The method sort enables you to sort a list of objects This method handles as parameters a list of objects and a script which will be applied to every object in the list The result is an instance of java u
57. niplovee java et Trace Mew b kai Open Open recent Properties Browse Save Save as I public void setFirst_ name atring value this first name value public Rank getRank return this rank m public void setRank Rank value this tank value public String toStringi i cf ae ostring method body Figure 62 Generation of a manually modified file At the time of generation MIA Generation detects if the file already exists lt then finds the manually changed portions and inserts this code during the writing of the newly generated contents MIA Generation Tutorial e 44 This document is the property of Mia Software It cannot be reproduced even partially by any means without prior written permission Generation by Scenario We are going to make the generation a little more robust In the preceding example each time a model is loaded we will have to select the classes to generate and the File Template to evaluate This means that in order for a user to use the generator he would have to know which objects to choose in the model as well as knowledge of the way the generator has been built he has to know that the generation is done with the Java Generation File Template and the objects of tyoe UMLClass We are going to use the notion of a generation scenario to make it easier to launch a generation Creating a scenario 1 Go to the Edition panel
58. oes not exist the code is generated with the tags and between the tags the text that is defined in the script between the calls to BeginTag and to EndTag On the other hand if the file exists the BeginTag script is evaluated and if the tag is present in the file the text which is between the two tags of the file is recovered and replaced between the two generated tags The result of the evaluation of a BeginTag and of an EndTag must be unique in a generation you cannot for example generate a tag Start of user code two times In addition BeginTag and EndTag should not contain carriage returns Types Categories Scripts e UMLAttribute 4 default 6 Scripts e UNMLClass 6 E Text Templates Es UNLModelElement 1 El toString ma Me citi acy en EndTaqy El File Templates E El JavaGeneration El acros EH Services String to tring BecginTad l f f Start of user code r tostring method body Figure 56 Unique BeginTag MIA Generation Tutorial e 39 This document is the property of Mia Software It cannot be reproduced even partially by any means without prior written permission Call the BeginTag and EndTag templates in the body of the toString template Types Categories Scripts ey UMLAttribute 4 default 6 Scripts ev UMLClass 6 E Text Templates e UMLModelElement 1 oo AO BeginTay Le EndTag E File Templates H E JavaGeneration El acros EH Services T S
59. of the current class Object superClasses gt UMLClass tetur CuUrEent collecti generalizations parent Figure 31 Service using the method collect MIA Generation Tutorial e 23 This document is the property of Mia Software It cannot be reproduced even partially by any means without prior written permission Creating a superClassName macro We now have to write a script calling this service which will return the name of the first superclass or Object if no superclass exists Therefore we are going to create a macro which will allow us to write some Java code that returns a string This can then be inserted into a template Create a macro named superClassName on the type UMLClass using the button Gi from the toolbar Specify the return type String for the macro Add Macro x Macro superclassName S Type UMLClass LD Package Tutorial Category default Creation date Modification date Attributes Read only E Single evaluation Signature Documentation Return type String a Parameters a Script return type e Primitive String E Model his acidedElements C Java Cancel Figure 32 Creation ofa superClassName macro MIA Generation Tutorial e 24 This document is the property of Mia Software It cannot be reproduced even partially by any means without prior written permission This macro calls the script name defined in the package Syst
60. on 1 Inthe Types list select the type UMLAttribute E 2 Create a template called declaration using the New Template button Change the generated text of the template so that it declares the visibility of the attribute followed by the name of this attribute Insert a carriage return at the end of the template so that each attribute is declared on a new line Edition Generation kiad SSSIQNMeEnLscion ae arom 1 ae y es UMLAssociation l Text Templates Scenarios e s UMLASsociationClass E Packages e UNLAssociationEnd a 3 tae File Templates id D System 325 Es UNL Attribute 11 see Macros 9 Tutorial 4 e UMLAttributeLink Services Profile e s UMLBinding e UMLCallction e UMLCallEvert e UML ChangeEvert Le UML Class 3 T String declaration visibility typeName name T Documentation Error rror in Text Template Tutorial declaration nknown referenced action typeName with O parameter 3 Figure 38 Template for an attribute declaration Note The visibility macro is defined in the System package Be aware that MIA Generation will notify you of an error after creation of the script declaration because the scripts typeName does not exist After creating this script the error will be removed MIA Generation Tutorial e 28 This document is the property of Mia Software It cannot be reproduced even partially by any means without prior written per
61. on UMLClass Then delete the template javaGenerationBody 3 Move the template javaEnumerationBody on the type UMLClass Enumeration and rename it into JavaGeneration Refactor gt Move from the Scripts list E Text Templates H T javaEnumerationBody EF toString El File Templates El El JavaGeneration El Macros e e attributes Acces attributesDeciar isEnumeratior jee superClassMann E Services E superllasses Mer Properties Rename Generate Refactor Copy Remove uk Copy Paste Declarations of b References to Add tags Become File Template Add precondition ME F Figure 89 Refactor menu Check the rename option and rename it into JavaGeneration MIA Generation Tutorial e 60 This document is the property of Mia Software It cannot be reproduced even partially by any means without prior written permission MIA Generation Move scripts A select the new location of selected scriptis Package E Tutorial cy Type s gt UMLClass Enumeration Category C default a I rename Ok Cancel Figure 90 Move scripts Dialog Box This document is the property of Mia Software It cannot be reproduced even partially by any means without prior written permission Tutorial e 61 4 Use Become File Template context menu from the Scripts list to change template JavaGeneration into file template Types Categories S
62. on nullif int n javax swing JUptionPane showlonftirmbialog context getFrame j Do you want to generate accessors 2 Java Generation j avax swing J0ptionPane YES NO CANCEL OPTION iE n javax swing JOptionPane CANCEL OPTION context cancelGeneration qenerateaccessors0ption new Boolean n Javax swing JUptionPane YES OPTION context setvalue qenerateAccessors generatedccessorsUption return generateAccessorsUption Figure 107 Macro generateAllAccessors MIA Generation Tutorial e 75 This document is the property of Mia Software It cannot be reproduced even partially by any means without prior written permission Modifiy the macro attributesAccessors to call generateAccessors String attributes Accessors if current getBoole an generatedAllAccessors return CUrrent apply attributes accessor else rrrr a f Ee tdi Figure 108 Macro attributeAccessors Launch the scenario Tutorial The dialog box appears only one time TavaGeneration ed 2 Do ou want to generate accessors Y Non Annuler You can test that context can clear or not between two generations using Clear Context before generating checkbox Generation options Tutorial x I gt General El File Ez Trace Report Mode Generate on SCREEN Generate into FILE Generation directory Directory eProgram Files MiA Generationgeneration me M Close c
63. on gt metamodels UML examples generators The project Tutorial scenario generation prj references scritos from First Generation of Java Code to Scenario Generation chapters Scripts from Advanced concepts chapter can be loaded with Tutorial with stereotype prj Tutorial with profile prj Tutorial with profile and pattern prj projects All concepts from this tutorial are detailed in MIA Generation manual A technical FAQ is also avalaible MIA Generation Tutorial e 1 This document is the property of Mia Software It cannot be reproduced even partially by any means without prior written permission First Generation of Java Code Start MIA Generation Architect from the Windows Start Menu MIA Generation Architect is an application that allows you to build a specific generator for a given context generation project is a grouping of everything that is necessary for a given generation e MIA Generation Project Default l 10 x File Edit Window Help oc SA EEF E AGAR Edition Generation Types Categories Scripts y UMLASsociationEnd 113 a default 3 Scripts y midis Le UMLAttribute 10 Tex Templates EM packages e UMLAttributeLink 3 i File Templates Lui Sr e UMLBinding 2 Macros Profile Ba Se UMLCallAction 2 O isActive e UMLCallEvert 2 D persistence e UMLChangeEvent 2 E Services e UML Class 13 8 current UMLClass e UNL Classifier 9 s UMLClassifierlm
64. onsole when generation i completed cancel Figure 109 Clear Context before generating MIA Generation Tutorial e 76 This document is the property of Mia Software It cannot be reproduced even partially by any means without prior written permission MIA Generation Javadoc You can find a Javadoc in the Help directory which provides MIA Generation APIs documention MIA Generation Javadoc Microsoft Internet Explorer Fichier Edition Affichage Faworis Outils 7 a Pr c dente 3 at O Rechercier L Paworis 6 Historique Eh a EW Adresse All Clacces Tae context variables map may contar dittereat kind of variables Packages e oystem variables these are variables provided by M14 Generation or variables i mia qen openapi created from the command line when the application was launched These Variables cant be removed e User variables these are variables defined durne the evaluation of ceneratioa scripts User variables may override System variable values la that case the related System values won t be visible as long as you don t clear the context map mMia gen openapl resort Context variables can ba tutialized through the command line used to launch MLA All Glasses Generation ny comand line parameter lice key voue will add a variable and its Call related value into the context map This can be used to easily parameterize ceneraters CallN Context WMiAOhect Repo
65. part 3 e UMLClassifierlnState 3 ba 4 SOUFCE Documentation Error e System Package contains scripts that provide access to the model Package System Figure 1 MIA Generation Architect MIA Generation Architect provides two main panels The Edition panel provides you with creation saving and edition functionnality For each element shown in the Navigator you can open a specific editor showing the corresponding element The Generation panel provides you with generation and trace functionnality MIA Generation Tutorial e 2 This document is the property of Mia Software It cannot be reproduced even partially by any means without prior written permission Creating a generation project A generation project is a grouping of everything that is necessary for a given generation A generation project can contain packages scenarios and a profile A project defines a generator based on scripts defined for a meta model A project allows you to save the entire work environment which can be restored at a later time There is always a current project in MIA Generation When the application is opened an empty project Default is created by default To create a new project you can click the New Project button Y or use the New button from the toolbar File Edit Window Help SAEF CET Edition Generation y Detautt ig SCenar y Project El Packag Open i Scenario N 13 o pen
66. perty of Mia Software It cannot be reproduced even partially by any means without prior written permission Generating a file template Once the objects and scripts have been selected you have only to launch the generation using the Generate button or the shorcut choose generation options Generation options JayaGeneration x Ib General El File a Trace Report Mode Generate on SCREEN C Generate into FILE Generation directory Directory eProgram Files M4 Generationwgeneration a Options Clear context before Generating Clear context when generation i completed Figure 20 Selection of the generation mode Select Generate on SCREEN and click on the button OK MIA Generation This document is the property of Mia Software It cannot be reproduced even partially by any means without prior written permission from the toolbar Before carrying out a generation you must Tutorial e 16 The virtually generated filenames appear in the Files list By selecting a filename the generated contents will appear in the Generated text pane You can see now that the generated text does indeed depend on the class where the File Template was evaluated Edition Generation Generated text del ublic class Address ode Tutorial mel f eneration Sig Parameters G Results 2 nen ETA o E rest tet Flee Trace Documentation Error 10 documentation
67. r String Boolean from a template MIA Generation Tutorial e 37 This document is the property of Mia Software It cannot be reproduced even partially by any means without prior written permission User Code Management In general it is better to architect the generation so that it is not necessary to insert user code in the generated files But it is impossible in some cases for example if it will take more time to model and generate business rules than to code them directly MIA Generation gives the possibility to delimit in the resulting text generation a zone that will be inserted manually We delimit this zone by using the scripts BeginTag and EndTag Take for example the method toString which in Java obtains a string representation of an object It is not possible to determine at generation time what the implementation of this toString method will be We can however generate a default implementation of this method and allow it to be modify manually by the following Create a template toString on the type UML Class Types Categories scripts s UMLAttribute 4 default 6 Scripts ee UMLClass 6 Text Templates e UMLModelElement 17 Y E E File Templates HE JavaGeneration F Macros Services YT String toString public String toString ii return instance of name T HM Figure 53 toString Template Call this template in the File Template JavaGeneration Types Categories Scripts
68. r de m ta modele Metamodel and System scripts The browser is compound of two areas the list of the metamodel types on the left and the available links and attributes for the selected type on the right For any type of model object a certain number of basic accessors are provided For every link L in the metamodel there is a service in the System package returning the object s linked to the role under an object table format if there are many objects For each attribute in the metamodel there is a macro returning a String that represents the attribute value MIA Generation Tutorial e 22 This document is the property of Mia Software It cannot be reproduced even partially by any means without prior written permission The service must therefore go through the list of objects attached to the current class by the link generalizations and return the object parent of each generalization Object superClasses gt UMLClass List generalizations current getLlist generalizations List parents new ArrayListi for Iterator i generallzations iterator l hasWNext j f UMLGeneralization generalization UMLGeneralization 1 nextl parents add generalization getParentiii return parents Figure 30 Body of the superClasses service We call the service generalizations defined in the System package by using the method getList which returns an instance of java util List
69. reating a generation unit To create a generation unit use Generate Generate from the toolbar if you are on the Edition panel MIA Generation Text Templates l File Templates HF JavaGeneration Macros z LEETE E F y E Pp mit me 7 ry default ric Mer b Properties Remove Cut Copy Paste Declarations of References to b Add tags Become Text Template Add precondition Whe b Figure 14 Scripts list context menu This document is the property of Mia Software It cannot be reproduced even partially by any means without prior written permission item from the Scripts list context menu or the Tutorial e 12 First a generation unit named lt Script Type gt is created and you just need to select objects to which the generation will apply Then if you click Generate item generation unit will be launch a ML4 Generation Project Tutorial iol xj File Edit Window Help FIT fal EKETE Edition Generation Parameters b gt Scenarios i Scenario Generation Units JavaGeneration UMLClass Type se UMLClass m Scripts F JavaGeneration UMLClass Add Edit Remove Objects Agda Edit Remove Generate Documentation Error o documentation HER Parameters Figure 15 Editing a Generation Unit A generation unit has been created for the JavaGeneration file template
70. ring ff Start of user code toString method body return instance of Employee fe End of user code toString method body Figure 59 Generation into a file MiA Generation i s itsi s s s lt C Tutoriale 41 This document is the property of Mia Software It cannot be reproduced even partially by any means without prior written permission Filename resolution Once a generation has completed the generated files are listed in the Results list It is then possible to view the contents of each generated file by selecting the file The contents appear in the textbox to the right of the file list If this filename is already absolute then the filename string is simply returned and used Otherwise this filename is resolved against the current generation directory lt is possible to sort results using View items from the Results context menu You can change results display with View gt File Name View gt Relative path View gt Full path items ey Parameters public Rank rank B m Results 1 El clprogram filesimia qeneratiomigeneratiomEmployee java PUbLic string getName ee Trai Per gt return this name Open b _ Open recent public void setName String value Properties this name value public String getFirst name return this first name Browse p Regenerate Close public void setFirst namne string value this first na
71. roperty of Mia Software It cannot be reproduced even partially by any means without prior written permission 2 Add a second macro attributesAccessors to allow the generation of the accessors for each attribute of the current class String attributes Accessorst EECULEM CUEEENE apply aELEIDUEeS ACCESSO 5 Figure 45 attributesAccessors macro 3 Modify the File Template JavaGeneration so it calls those two macros A code completion mechanism can help you create scripts By pressing the Control Space keys you can display a window containing the scripts you can use in this script In a template you can ask for this help after entering the start delimiter of a script by default Types Categories Scripts e UMLAttribute 4 default 5 Scripts ee UMLClass 5 Text Templates e UNLModelElemert 1 E File Templates El Fl JavaGeneration Eloiacros attributesAccezsorz lt lt attributesDeclarations gt superClassName E Services i sliperllasses UMLClass F String JavaGeneration public class name extends superllassName f LattributesDdeclarations attributesa ccessors Ga attributesDeclarations documentation falze identitier String Boolean isAbstract Figure 46 Include the attributes when generating a class MIA Generation Tutorial e 32 This document is the property of Mia Software It cannot be reproduced even partially by any means
72. stereotypeName equals Enumeration V7 SE ee ee om else if stereotypeName equals Business Biche ness else Other classes In that case it would be more interesting to use a profile A profile enables to customize a metamodel by adding new types It is a set of stereotypes each stereotype defining a new type MIA Generation Supports the concept of profile and extends its use to the meta model the concept of Profile can be seen like a means of extending a meta model easily The concept of profile introduced with UML 1 4 is a means to extend UML A profile is specified by a list of UML types to use a list of stereotypes a list of tagged values and a list of constraints Each user can define his own list of new classes He will then be able to define scripts directly on these classes and the imported models will be able to take account of these classes at the time of instantiation of the objects Implicitly a stereotype is a way to define a new type of object Thus MIA Generation provides the possibility to manipulate the stereotyped objects like objects of a specific type For instance with all of the classes that have a stereotype lt lt Table gt gt MIA Generation can instantiate a instance of a type Table a subclass of UMLClass rather than just an instance of UMLClass This enables to use polymorphism rather than if statements MIA Generation Tutorial e 58 This document is the property of Mia Software
73. tends superClassMame iT attributesDeclarations T attributesAccessors to tring T A Figure 74 javaClassBody Template MIA Generation Tutorial e 52 This document is the property of Mia Software It cannot be reproduced even partially by any means without prior written permission 3 We have to test if the current class is an enumeration or not Create a new macro named isEnumeration that returns an java lang Boolean instance Select the Boolean type from the Primitive combo box 3 Properties of isEnumeration x Macro jisEnumeration de Type UhiLClass 3 Package Tutorial 0 Category deta Creation date jeudi 22 mai 2005 11 56 16 Modification date jeudi 22 mai 2005 11 56 17 Attributes P Read only E Single evaluation Signature Documentation MOEA Return type Agd Edit Remove Parameters ewes Figure 75 isEnumeration macro Modify the text of the sEnumeration macro Types Categories Scripts e UMLAttripute 5 detfautt 10 Scripts e UMLClaze 107 E Text Templates e UMLModelElement 1 File Templates ee UlLPackage 1 Macros 2 attributesAccessors E attributesDeclarations g sEnumeration ii selectJavaGenerationkind jee superClassName E Services ze superllasses UMLClass Boolean isEnurmerationc if current getatereotypel null ss current getstereotypel qgetName equa
74. the same object is derived several times it will appear only once in this list Among these derived objects you can select exactly the objects on which you wish to launch a generation To do this use the arrows which enable you to add Address et Building objects A Selection of UMLClass instances xx Type of objects lA UMLClass th Subtypes objects Available objects Services Deduced objects e Enumeration Rank behaviors gt UMLSI A Address A Building cl Company Ay Director A Division ce Employee A Office selected objects a sEnumeration Rank os Address n Company Building e Director e Division pp Employee e Office clientDependenciez constrainingElemerr constraints gt UML current UMLClas documents gt UML generalizations L amp implementationLoca H OK Cancel Figure 18 Address and Building selection Once your choice is made click the OK button to update the list of the objects in the generation window The selected objects will then replace the previous ones Generaticn Units pe lek UMLClass gt Soc ipte F davacenerallor UhiLClasz 5 Javelsen ation LMILClass Agd Edit Remove Tibjects J Address UldL Class e Ending LUAS Add Edit Riera Se 1erate Figure 19 Selected objects MIA Generation Tutorial e 15 This document is the pro
75. til List and represents the list of objects sorted by ascending order For a descending order you must enter a third parameter boolean type true for ascending and false for descending MIA Generation Tutorial e 69 This document is the property of Mia Software It cannot be reproduced even partially by any means without prior written permission You can now test your generation The creation of scripts has been thus largely facilitated since it is possible to conceive of them by copying and pasting from existing code for a class Generated text reloaded from Rank java public class Rank public static final Rank DEVELOPER new Rank DPEVELOPER public static final Rank CONSULTANT new Rank CONSULTANT public static final Rank MANAGER new Rank MANAGER private String id public final int ord private Rank prev private Rank next private static int upperBound OU private static Rank first null private static Rank last null private Rank String anlD this id anll this ord upperBound if first null first this if last null i this prev last last next this last this Figure 103 Rank enumeration generation MIA Generation Tutorial e 70 This document is the property of Mia Software It cannot be reproduced even partially by any means without prior written permission Frameworks A number of core tasks crop up over and over again Most develop
76. tring toString public String toString BeginTag 1 return instance of name T EndTag 17 Figure 57 Modification of the toString template Go to the Generation tab and start the generation but this time choose to generate into a file Generation options JayaGeneration X b General El File a Trace Report hoe Generate on SCREEN Generation directory Directory eProgram Files MI4 Generation yeneration Options Clear context before generating Clear context when generation i completed cancel Figure 58 Generate into file MIA Generation Tutorial e 40 This document is the property of Mia Software It cannot be reproduced even partially by any means without prior written permission The first time that you generate into a file the file doesn t exist and is created Therefore there is no possibility for user code and the default implementation of toString is generated Edition Generation Generated text reloaded trom Employee java odel e Tutorial mal eneration ublic void setName String value Ely Parameters this name value E i Results 1 e nsee java i AU ES Ee ublic String getFirst name H Trace return this first name ublic void setfFirst name string value this first name value ublic Rank getRank return this rank ublic void setRank Rank value this rank value ublic String toSt
77. u Get Therefore you only need to type the code to be generated which is littered with macro names instead of programming it The creation of scripts is thus largely facilitated since it is possible to conceive them by copying and pasting from existing code for a class 1 Copy the content of Color java into the template JavaGeneration on UML Class Enumeration Types Categories Scripts de UMLAttribute 4 deraut 1 cripts es UMLClass 7 A a Text Templates e UMLClass Enumeration 1 E File Templates DRE laaceneration cc RACcros be Services F String JavaGeneration import java util se public final class Color public static final Color RED new Color Red public static final Color CREEN new Color Green public static final Color BLUE new Color Blue private String id public final int ord private Color prev private Color next private static int upperBound OU private static Color first null private static Color last null Figure 97 File Template JavaGeneration MIA Generation Tutorial e 67 This document is the property of Mia Software It cannot be reproduced even partially by any means without prior written permission 2 There is a declaration line for each color RED GREEN BLUE The relation One declaration for each attribute of the enumeration class means you must create a script on UMLAttribute that will be call from the UMLClass with an apply C
78. ut attributes declaration lines and copy them into a template named enumeratedConstantsDeclaration on UMLAttribute Types Categories Scripts e UML Attribute 5 defaut 5 Scripts e UMLClass 7 E Text Templates e UMLClass Enumeration 2 wf accessor 1 declaration Aue unerstedConstantDeclaration oe File Templates Fl Macros ervices T String enumeratedCon staniDeciaration public static final Color RED new Color RED I Figure 98 Template enumeratedConstantDeclaration on UMLAttribute Save the text after removing BLUE and GREEN lines You can see there are two informations to get from model at runtime the enumeration s name Color and the attribute s name RED public static final Color RED new Color RED Modify the text to call a new macro ownerName which get the owner s name and the macro name m String enumeratedConstantDeclaration y public static final owerName name new omerNaneJ nameJ 2 7 gt T Figure 99 Template enumeratedConstantDeclaration on UMLAttribute String ownerblarmel return current getOmner qetName 1 Figure 100 Macro ownerName on UMLAitribute MIA Generation Tutorial e 68 This document is the property of Mia Software It cannot be reproduced even partially by any means without prior written permission Replace the text Color with name in the file template JavaGeneration Fi
79. without prior written permission If we generate this File Template on the class Employee it creates the following text MIA Generation Generated text Class Address extends Ubject int number String 3 zip code String city String country ublic int getNumber return this number ublic void setNumberfint value this number value ublic String getatreet return this Street ublic void setstreet String value this street value ublic String getz2ip code Figure 47 Results of the generation with the Employe class This document is the property of Mia Software It cannot be reproduced even partially by any means without prior written permission Tutorial e 33 Creating a macro with parameters We are going to improve our generation by modifiying the Name macro to allow us to puts the first letter of the attribute name as a capital letter and replacing some characters in the attribute name Create a new macro String identifier String id Boolean firstletterToUppercase on the UMLModelElement type e Properties of Identifier x Macro identifier ee Type UMLModelElemert ae i X 0 Package Tutorial Y cript Paria E Category default Mame rirstLetterToUpperCase Creation date vendredi 23 mai 2005 Type Modification date vendredi 23 mai 20035 AMA E PPP E Object iia la Read only Primitive Boolean E Single evaluation Model MiA sddedElements Sig
80. work When code is generated the number of errors is considerably reduced In fact all typing errors copy and paste mistakes very common technique when a generator is not used omissions etc are avoided These types of errors are not necessarily glaringly obvious so the risk to leave some in the final code is significant However when using a code generator if a mistake is done when the script is written the error is generally reflected on all entities thus the detection is fast A script correction and a complete regeneration make it possible to correct the error MIA Generation Tutorial e 72 This document is the property of Mia Software It cannot be reproduced even partially by any means without prior written permission Using J2SE components into scripts You can use all Java 2 plateform J2SE APIs into MIA Generation scripts The javax swing JOptionPane class provides many APIs to display dialog boxes and to ask for user inputs See the documentation of JOptionPane for more information In the macro generateAccessors we will use the javax swing JOptionPane class to ask the user if attributes accessors must be generated Types Categories Scripts e UMLAttribute 5 default 5 Scripts e ev UMLClass 8 E Text Templates e UMLClass Enumeration 2 EE toString e UMLModelElement 1 El File Templates A WF JavaGeneration Fl Macros D attributesAccessors D attributesDeclarations o ae generateAccess
Download Pdf Manuals
Related Search
Related Contents
RV 1601 RV 1901 Phyto Démangeaison 心音図記録ユニット ACE-9100 オーディコア Copyright © All rights reserved.
Failed to retrieve file