Jump to: navigation, search

Difference between revisions of "MoScript/Use Cases/Megamodel Population Part 2"

(Registering artifacts)
(Test)
 
(25 intermediate revisions by the same user not shown)
Line 5: Line 5:
  
 
* Download the Families to Persons source code from [http://www.eclipse.org/m2m/atl/atlTransformations/#Families2Persons here]
 
* Download the Families to Persons source code from [http://www.eclipse.org/m2m/atl/atlTransformations/#Families2Persons here]
* Unzip the project and import it into eclipse copying the fiels into the workspace
+
* Unzip the project and import it into eclipse copying the files into the workspace
  
 
===== Registering artifacts  =====
 
===== Registering artifacts  =====
<pre>program megamodelPopulation
 
  
using {
+
The first thing we have to do is to declare the variables we are going to use along the rest of the code. We declare variables for holding the ecore metametamodel, and the metamodels of the Families2PersonExample.
  ecore&nbsp;:&nbsp;!MetaMetamodel = OclUndefined
+
  familiesMetamodel&nbsp;:&nbsp;!Metamodel = OclUndefined
+
  personsMetamodel&nbsp;:&nbsp;!Metamodel = OclUndefined
+
}
+
  
do{
+
program megamodelPopulation
  '''-- Removes all the identified elements form the megamodel'''
+
  for(identifiedElement in&nbsp;!IdentifiedElement.allInstances()-&gt;select(ie | not (ie.identifier = OclUndefined) )) {
+
using {
    identifiedElement.remove();
+
  ecore&nbsp;:&nbsp;!MetaMetamodel = OclUndefined
  }
+
  familiesMetamodel&nbsp;:&nbsp;!Metamodel = OclUndefined
 +
  personsMetamodel&nbsp;:&nbsp;!Metamodel = OclUndefined
 +
}
  
  '''-- Creates the Ecore metametamodel element in the megamodel'''
+
After declaring variables we proceed to register the Ecore metametamodel in the megamodel to be able to register metamodels that conform to it.
  thisModule.register(
+
 
      thisModule.metametamodel(
+
do{
          thisModule.identifier('identifier', 'http://www.eclipse.org/emf/2002/Ecore', 'GlobalModelManagement::URI')
+
          ,thisModule.locator('locator', 'http://www.eclipse.org/emf/2002/Ecore',  
+
  thisModule.register(
                                        'GlobalModelManagement::EPackagesRegistryLocator')
+
      thisModule.metametamodel(
      )
+
            thisModule.identifier('identifier', 'http://www.eclipse.org/emf/2002/Ecore', 'GlobalModelManagement::URI')
  );
+
          ,thisModule.locator('locator', 'http://www.eclipse.org/emf/2002/Ecore',  
   
+
                                          'GlobalModelManagement::EPackagesRegistryLocator')
  ecore &lt;-&nbsp;!Model.allInstances()-&gt;any(m | m.identifier.value = 'http://www.eclipse.org/emf/2002/Ecore');
+
      )
   
+
  );
  '''-- Creates the Families metamodel element in the megamodel'''
+
 
  thisModule.register(
+
Next, we query the megamodel to find the just registered metametamodel and assign it to the ecore variable
    thisModule.metamodel(
+
 
      thisModule.identifier('identifier', '/Families2Persons/Families.ecore', 'GlobalModelManagement::URI'),
+
  ecore &lt;-&nbsp;!Model.allInstances()-&gt;any(m | m.identifier.value = 'http://www.eclipse.org/emf/2002/Ecore');
      thisModule.locator('locator', '/Families2Persons/Families.ecore', 'GlobalModelManagement::EFSLocator'),
+
 
      ecore
+
Next we register the Families.ecore and Persons.ecore metamodels in the megamodel. Note that the third parameter of the metamodel operation is the ecore variable, which corresponds to the Ecore metametamodel.
    )   
+
 
   );
+
  thisModule.register(
 +
    thisModule.metamodel(
 +
      thisModule.identifier('identifier', '/Families2Persons/Families.ecore', 'GlobalModelManagement::URI'),
 +
      thisModule.locator('locator', '/Families2Persons/Families.ecore', 'GlobalModelManagement::EFSLocator'),
 +
      ecore
 +
    )   
 +
  );
 +
 +
  thisModule.register(
 +
    thisModule.metamodel(
 +
      thisModule.identifier('identifier', '/Families2Persons/Persons.ecore', 'GlobalModelManagement::URI'),
 +
      thisModule.locator('locator', '/Families2Persons/Persons.ecore', 'GlobalModelManagement::EFSLocator'),
 +
      ecore
 +
    )    
 +
  );
 +
 
 +
Next we are going to register the sample-Families.xmi and sample-Persons.xmi model in the megamodel. First we query the megamodel to get the Families.ecore metamodel and assign it to the familiesMetamodel variable.
 +
 
 +
  familiesMetamodel <- !Model.allInstances()->any(m | m.identifier.value = '/Families2Persons/Families.ecore');
 +
 
 +
Next, we register the Families.ecore metamodel in the EMF package registry, so we are able to visualize the models conforming to it  with e.g. the Reflective Ecore Model Editor. Then, we register sample-Families.xmi model and make it conform to the Families.ecore metamodel passing the familiesMetamodel variable as third parameter.
 +
 
 +
  familiesMetamodel.registerInEMFpkgReg();
 
    
 
    
  '''-- Creates the Persons metamodel element in the megamodel'''
+
  thisModule.register(
  thisModule.register(
+
    thisModule.terminalmodel(
    thisModule.metamodel(
+
      thisModule.identifier('identifier', '/Families2Persons/sample-Families.xmi', 'GlobalModelManagement::URI'),
      thisModule.identifier('identifier', '/Families2Persons/Persons.ecore', 'GlobalModelManagement::URI'),
+
      thisModule.locator('locator', '/Families2Persons/sample-Families.xmi', 'GlobalModelManagement::EFSLocator'),
      thisModule.locator('locator', '/Families2Persons/Persons.ecore', 'GlobalModelManagement::EFSLocator'),
+
      familiesMetamodel
      ecore
+
    )
    )
+
  );
  );
+
 
+
  familiesMetamodel &lt;-&nbsp;!Model.allInstances()-&gt;any(m | m.identifier.value = '/Families2Persons/Families.ecore');
+
   
+
  '''-- Registers the Families metamodel in the EMF package register'''
+
  familiesMetamodel.registerInEMFpkgReg();
+
  
  '''-- Creates the Families model element in the megamodel'''
+
We repeat the operation with the Persons.ecore metamodel and the sample-Persons.xmi model.
  thisModule.register(
+
    thisModule.terminalmodel(
+
      thisModule.identifier('identifier', '/Families2Persons/sample-Families.xmi', 'GlobalModelManagement::URI'),
+
      thisModule.locator('locator', '/Families2Persons/sample-Families.xmi', 'GlobalModelManagement::EFSLocator'),
+
      familiesMetamodel
+
    )
+
  );
+
  
  personsMetamodel &lt;-&nbsp;!Model.allInstances()-&gt;any(m | m.identifier.value = '/Families2Persons/Persons.ecore');
+
  personsMetamodel <- !Model.allInstances()->any(m | m.identifier.value = '/Families2Persons/Persons.ecore');
 
      
 
      
  '''-- Registers the Persons metamodel in the EMF package register'''
+
  personsMetamodel.registerInEMFpkgReg();
  personsMetamodel.registerInEMFpkgReg();
+
 
+
  thisModule.register(
  '''-- Creates the Families model element in the megamodel'''
+
    thisModule.terminalmodel(
  thisModule.register(
+
      thisModule.identifier('identifier', '/Families2Persons/sample-Persons.xmi', 'GlobalModelManagement::URI'),
    thisModule.terminalmodel(
+
      thisModule.locator('locator', '/Families2Persons/sample-Persons.xmi', 'GlobalModelManagement::EFSLocator'),
      thisModule.identifier('identifier', '/Families2Persons/sample-Persons.xmi', 'GlobalModelManagement::URI'),
+
      personsMetamodel
      thisModule.locator('locator', '/Families2Persons/sample-Persons.xmi', 'GlobalModelManagement::EFSLocator'),
+
    )
      personsMetamodel
+
  );
    )
+
 
  );
+
Finally we register the Families2Person.atl ATL transformation module in the megamodel.
 
+
thisModule.register(
  '''-- Registers the Families2Person.atl transformations in the megamodel'''
+
  thisModule.atlModule(
  thisModule.register(
+
    thisModule.identifier('identifier', '/Families2Persons/Families2Persons.atl', 'GlobalModelManagement::URI'),
    thisModule.atlModule(
+
    thisModule.locator('locator', '/Families2Persons/Families2Persons.atl', 'GlobalModelManagement::EFSLocator')
      thisModule.identifier('identifier', '/Families2Persons/Families2Persons.atl', 'GlobalModelManagement::URI'),
+
  )
      thisModule.locator('locator', '/Families2Persons/Families2Persons.atl', 'GlobalModelManagement::EFSLocator')
+
);
    )
+
 
  );
+
You can find the example complete code with all the helpers here [http://docatlanmod.emn.fr/MoScript/usecases/megamodelPopulationPart2/megamodelPopulation.mscr  megamodelPopulation.mscr]
}
+
 
</pre>
+
===== Test  =====
 +
After running the example, open the AM3 Megamodeling perspective and select the Entity element in the tree. You will see the list of the registered models in the right panel. Double click on the ATLModule and the ATL transformation should open in an editor as in the following picture.
 +
 
 +
[[Image:MoScript-MegamodelPopulationPart2.png]]

Latest revision as of 07:41, 8 February 2012

Megamodel Population Part 2

Continuing with the use case Megamodel Population Part 1, this use cases shows how to programmatically populate the megamodel with models, metamodels and transformations. For this purpose we are going to populate it with the content of an ATL project that can be found in the ATL Transformations Zoo

Environment Preparation
  • Download the Families to Persons source code from here
  • Unzip the project and import it into eclipse copying the files into the workspace
Registering artifacts

The first thing we have to do is to declare the variables we are going to use along the rest of the code. We declare variables for holding the ecore metametamodel, and the metamodels of the Families2PersonExample.

program megamodelPopulation 

using { 
  ecore : !MetaMetamodel = OclUndefined
  familiesMetamodel : !Metamodel = OclUndefined
  personsMetamodel : !Metamodel = OclUndefined
}

After declaring variables we proceed to register the Ecore metametamodel in the megamodel to be able to register metamodels that conform to it.

do{ 

  thisModule.register(
      thisModule.metametamodel(
           thisModule.identifier('identifier', 'http://www.eclipse.org/emf/2002/Ecore', 'GlobalModelManagement::URI')
          ,thisModule.locator('locator', 'http://www.eclipse.org/emf/2002/Ecore', 
                                         'GlobalModelManagement::EPackagesRegistryLocator')
      )
  );

Next, we query the megamodel to find the just registered metametamodel and assign it to the ecore variable

  ecore <- !Model.allInstances()->any(m | m.identifier.value = 'http://www.eclipse.org/emf/2002/Ecore');

Next we register the Families.ecore and Persons.ecore metamodels in the megamodel. Note that the third parameter of the metamodel operation is the ecore variable, which corresponds to the Ecore metametamodel.

  thisModule.register(
    thisModule.metamodel(
      thisModule.identifier('identifier', '/Families2Persons/Families.ecore', 'GlobalModelManagement::URI'),
      thisModule.locator('locator', '/Families2Persons/Families.ecore', 'GlobalModelManagement::EFSLocator'),
      ecore
    )  
  );

  thisModule.register(
    thisModule.metamodel(
      thisModule.identifier('identifier', '/Families2Persons/Persons.ecore', 'GlobalModelManagement::URI'),
      thisModule.locator('locator', '/Families2Persons/Persons.ecore', 'GlobalModelManagement::EFSLocator'),
      ecore
    )   
  );

Next we are going to register the sample-Families.xmi and sample-Persons.xmi model in the megamodel. First we query the megamodel to get the Families.ecore metamodel and assign it to the familiesMetamodel variable.

  familiesMetamodel <- !Model.allInstances()->any(m | m.identifier.value = '/Families2Persons/Families.ecore');

Next, we register the Families.ecore metamodel in the EMF package registry, so we are able to visualize the models conforming to it with e.g. the Reflective Ecore Model Editor. Then, we register sample-Families.xmi model and make it conform to the Families.ecore metamodel passing the familiesMetamodel variable as third parameter.

  familiesMetamodel.registerInEMFpkgReg();
 
  thisModule.register(
    thisModule.terminalmodel(
      thisModule.identifier('identifier', '/Families2Persons/sample-Families.xmi', 'GlobalModelManagement::URI'),
      thisModule.locator('locator', '/Families2Persons/sample-Families.xmi', 'GlobalModelManagement::EFSLocator'),
      familiesMetamodel
    )
  );

We repeat the operation with the Persons.ecore metamodel and the sample-Persons.xmi model.

  personsMetamodel <- !Model.allInstances()->any(m | m.identifier.value = '/Families2Persons/Persons.ecore');
   
  personsMetamodel.registerInEMFpkgReg();
	
  thisModule.register(
    thisModule.terminalmodel(
      thisModule.identifier('identifier', '/Families2Persons/sample-Persons.xmi', 'GlobalModelManagement::URI'),
      thisModule.locator('locator', '/Families2Persons/sample-Persons.xmi', 'GlobalModelManagement::EFSLocator'),
      personsMetamodel
    )
  );

Finally we register the Families2Person.atl ATL transformation module in the megamodel.

thisModule.register(
  thisModule.atlModule(
    thisModule.identifier('identifier', '/Families2Persons/Families2Persons.atl', 'GlobalModelManagement::URI'),
    thisModule.locator('locator', '/Families2Persons/Families2Persons.atl', 'GlobalModelManagement::EFSLocator')
  )
);

You can find the example complete code with all the helpers here megamodelPopulation.mscr

Test

After running the example, open the AM3 Megamodeling perspective and select the Entity element in the tree. You will see the list of the registered models in the right panel. Double click on the ATLModule and the ATL transformation should open in an editor as in the following picture.

MoScript-MegamodelPopulationPart2.png