I suggest you start with the Eclipse Modeling Tools plus the Model-to-Model Operational QVT plugins (check how to download/install it).
Also, QVT requires a metamodel of the source and target languages being used (in case you don't know, a metamodel is a model that describes another model). In this example we'll use this simplified use case diagram metamodel. Lastly, of course, we need an actual model to be used as input! We will use this piece of a Meeting Scheduler use case diagram.
Ugly, right? Agreed... |
If you want to create your own use case models, you can use the default editor that Eclipse can create, which allow you to edit models in a tree-based view. You can create an editor for our use case metamodel by following the steps I and II from this tutorial by Vitor Souza (in step II.2, you can use "usecasepackage" as the base package name). Then follow step IV for actually creating the model (the model object for the step IV.4 is just "Model").
But now, let's go the transformations!
Quick and Dirty version:
- Run Eclipse with QVT
- Create a new Operational QVT Project (File/New/Other.../Model to Model Transformation/Operational QVT Project). In the wizard, be sure to select "Create a simple project".
- Import the metamodel (.ecore) and the model (.usecase) My favorite way of doing this is by just drag-and-dropping the files into the Project Explorer. Alternatively, right click your project, select 'Import...', General/File System
- Create a new Operational QVT Transformation (File/New/Other.../Model to Model Transformation/Operational QVT Transformation). In the Module name you write the name of the transformation you are creating.
- Now it is time for the obscure Eclipse configuration: go to Project/Properties/QVT settings/Metamodel Mappings, click 'Add' and define the source/target metamodels. In the source field you need to write the URI of the metamodel (in our example it's http://www.cin.ufpe.br/useCaseUri ). In the target field you can browse the current project and select the metamodel file.
- Code! Or use this transformation example.
- Now, more configuration. Right-click the transformation file and select Run As/Run Configurations... , select 'Operational QVT Interpreter' and click the 'New launch configuration' button. Go to the Model URI field and Browse the project to select the input model file (.usecase)
- Press "Apply", to save these settings
- Run!
Now if everything is right you will see... nothing. Just go check the transformation results in your target model and be happy! Once these settings are done, all you need to run the transformation again is to select the transformation in the 'Run' dropdown button.
Thorough version:
- Run Eclipse with QVT Please make it wear a good tennis as not to harm its feet.
- Create a new Operational QVT Project. To do so, go to File/New/Other... (Ctrl+N) and then select 'Operational QVT Project' in the 'Model to Model Transformation' folder. In the wizard, be sure to select "Create a simple project", as shown in the pictures below.
- Import the metamodel (.ecore) and the model (.usecase). There are several ways to do this. My favorite one is to simply drag the files and drop them into Eclipse's Project Explorer (or Package Explorer, depending on the version of Eclipse).
- Create a new Operational QVT Transformation (File/New/Other.../Model to Model Transformation/Operational QVT Transformation). In the Module name you write the name of the transformation you are creating.
- Now it is time for the obscure Eclipse configuration: go to Project/Properties/QVT settings/Metamodel Mappings, click 'Add' and define the source/target metamodels. In the source field you need to write the URI of the metamodel (in our example it's http://www.cin.ufpe.br/useCaseUri ). In the target field you can browse the current project and select the metamodel file.
- We're almost done with the configuration, now you already can code your transformations. These slides may help you with that. Or, use this example based on the paper "Towards Architectural Evolution through Model Transformations", from SEKE2012:
modeltype UseCase uses UseCase('http://www.cin.ufpe.br/useCaseUri'); transformation AddActor(inout useCaseModel : UseCase); main() { useCaseModel.rootObjects()[Model].map applyAddActor(); } mapping inout Model::applyAddActor() { self.actor += new Actor("newActor"); } constructor Actor::Actor(myName : String) { name := myName; }
- Now, more configuration. Right-click the transformation file and select Run As/Run Configurations... , select 'Operational QVT Interpreter' and click the 'New launch configuration' button. Go to the Model URI field and Browse the project to select the input model file (.usecase)
- Press "Apply", to save these settings
- Press Run!
File/New/Other... |
New Operational QVT Project |
Write the project name, select 'Create a simple project' and click Next |
Just finish |
Browse and select your input model |
You can check the model to see if the new Actor was created:
So, summing up all the files you need for this example: Use Case metamodel, Use Case example (meeting scheduler), Example Use Case transformation (Add Actor).
Thanks for this simple example! Its a good starting point.
ReplyDeleteHello,
ReplyDeleteI can't find the sources,
Hi,
ReplyDeleteI Can´t download the sources. Help me please
You can find more Use case diagram examples in the diagram community of Creately diagram software. There are 100s of use case diagrams drawn on various scenarios.
ReplyDeleteYou can refer to different types of online diagramming tools which have use case pages for different aspects. This will help you to easily figure out what exactly you want and at the meantime you can use those templates to draw your preferred Use case diagrams.
ReplyDeleteGreat and I have a nifty proposal: Where To Buy Houses That Need Renovation home remodeling contractors
ReplyDelete