Jump to: navigation, search

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

(New page: === Megamodel Population Part 1 === A requisite for start working with MoScript is to count with a populated megamodel i.e, a megamodel with elements, which point to modeling artefacts. Th...)
 
(Registering the EMF metametamodel)
 
(5 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
=== Megamodel Population Part 1 ===
 
=== Megamodel Population Part 1 ===
A requisite for start working with MoScript is to count with a populated megamodel i.e, a megamodel with elements, which point to modeling artefacts. This megamodel population can be done through the [http://wiki.eclipse.org/AM3 AM3] graphical user interface, nevertheless Registering a high amount of models through the GUI is a repetitive and time consuming task. In those cases is better to use textual syntax to populate the megamodel, so, in this use case we are going to show how is possible to programmatically populate the Megamodel with MoScript. For this purpose we are going to populate it with the content of an ATL project that can be found in the [http://www.eclipse.org/m2m/atl/atlTransformations/#Class2Relational ATL Transformations Zoo]
+
A requisite for start working with MoScript is to count with a populated megamodel i.e, a megamodel with elements, which point to modeling artefacts. This megamodel population can be done through the [http://wiki.eclipse.org/AM3 AM3] graphical user interface, nevertheless Registering a high amount of models through the GUI is a repetitive, error prone and time consuming task. In those cases is better to use textual syntax to populate the megamodel, so, in this use case we are going to show how is possible to programmatically populate the Megamodel with MoScript.
  
===== Environment Preparation =====
+
===== Registering the EMF metametamodel =====
  
* Download the Families to Persons source code from [http://www.eclipse.org/m2m/atl/atlTransformations/#Families2Persons here]
+
As first step we are going to register programmatically the Ecore metametamodel in the Megamodel, to be able to register metamodels that conform to it and subsequently models that conform to those metamodels. For this, we have to have in mind that in order for MoScript to be able manipulate any model (remember that a metametamodel is also a model), the model must have at least an identifier to unequivocally identify it, a locator, to be able to locate the file that represents the model, and a reference model describing it, in order to be able to inspect its content.  
* Unzip the project and import it into eclipse
+
* Create a MoScript project named megamodelPopulation with a file called megamodelPopulation.mscr
+
  
===== Registering the EMF metametamodel  =====
+
If we check the Megamodels metamodel ([https://dev.eclipse.org/svnroot/modeling/org.eclipse.mdt.modisco/incubation/trunk/am3/plugins/trunk/org.eclipse.gmt.am3.platform.extension.globalmodelmanagement/model/GlobalModelManagement.ecore GlobalModelManagement]) we will see that a Metametamodel is a ReferenceModel and has references to Identifier, Locator and a ReferenceModel among others (see the picture bellow) <br> [[Image:MoScript-MetaMetaModel.png]] [[Image:MoScript-IdentifierLocator.png]]  
As first step we are going to register programmatically the Ecore metametamodel in the Megamodel, to be able to register metamodels that conform to it and subsequently models that conform to those metamodels. For this, we have to have in mind that in order for MoScript to be able manipulate any model (remember that a metametamodel is also a model), the model must have at least an identifier to unequivocally identify it, a locator, to be able to locate the file that represents the model, and a reference model describing it, in order to be able to inspect its content.
+
 
 
+
The code for resgistering a MetaMetamodel in the Megamodel is the following:
If we check the Megamodels metamodel (that can be found in /org.eclipse.gmt.am3.platform.extension.globalmodelmanagement/model /GlobalModelManagement.ecore) we will see that a Metametamodel is a ReferenceModel and has references to identifier, locator and a ReferenceModel among others (see the picture bellow) <br>
+
[[Image:MoScript-MetaMetaModel.png]] [[Image:MoScript-IdentifierLocator.png]]
+
  
The code for resgistering a MetaMetamodel in the Megamodel is the following:
+
  '''program megamodelPopulation'''
+
  '''program modelsDiscovery'''
+
 
   
 
   
 
  do{
 
  do{
    ''-- Creates the Ecore metametamodel element in the megamodel''
+
    ''-- Creates the Ecore metametamodel element in the megamodel''
    thisModule.<span style="color:#800000">register</span>(
+
    thisModule.<span style="color:#800000">register</span>(
        thisModule.metametamodel(
+
        thisModule.metametamodel(
              thisModule.identifier('identifier', 'http://www.eclipse.org/emf/2002/Ecore', 'GlobalModelManagement::URI')
+
            thisModule.identifier('identifier', 'http://www.eclipse.org/emf/2002/Ecore', 'GlobalModelManagement::URI')
            ,thisModule.locator('locator', 'http://www.eclipse.org/emf/2002/Ecore',  
+
            ,thisModule.locator('locator', 'http://www.eclipse.org/emf/2002/Ecore',  
                                            'GlobalModelManagement::EPackagesRegistryLocator')
+
                                          'GlobalModelManagement::EPackagesRegistryLocator')
        )
+
        )
    );
+
    );
 
  }
 
  }
 
   
 
   
 
  ''-- *********** Helper for creating the tuple for the element type''
 
  ''-- *********** Helper for creating the tuple for the element type''
 
  ''-- *********** Metametamodel''
 
  ''-- *********** Metametamodel''
  '''helper def: metametamodel(identifier : TupleType(name: String, concreteType: String, value :OclAny)'''
+
  '''helper def: metametamodel(identifier&nbsp;: TupleType(name: String, concreteType: String, value&nbsp;:OclAny)'''
                          ''',locator : TupleType(name: String, concreteType: String, value :OclAny))'''
+
                          ''',locator&nbsp;: TupleType(name: String, concreteType: String, value&nbsp;:OclAny))'''
  ''':TupleType(name: String, concreteType: String, value :OclAny) ='''
+
  ''':TupleType(name: String, concreteType: String, value&nbsp;:OclAny) ='''
 
+
  let id: String = identifier.value.asSequence()->first().value in
+
  let id: String = identifier.value.asSequence()-&gt;first().value in
 
  let concreteType: String = 'GlobalModelManagement::Metametamodel' in
 
  let concreteType: String = 'GlobalModelManagement::Metametamodel' in
 
  let creationId: String = '@' + concreteType + '#' + id in
 
  let creationId: String = '@' + concreteType + '#' + id in
  let attributes : Set(TupleType(name: String, concreteType: String, value :OclAny)) =  
+
  let attributes&nbsp;: Set(TupleType(name: String, concreteType: String, value&nbsp;:OclAny)) =  
 
  Set{
 
  Set{
 
  Tuple{name = '__id', concreteType = 'String', value = id},
 
  Tuple{name = '__id', concreteType = 'String', value = id},
Line 51: Line 45:
 
  ''-- *********** Identifier''
 
  ''-- *********** Identifier''
 
  '''helper def: identifier(attrName: String, value: String, concreteType: String)'''  
 
  '''helper def: identifier(attrName: String, value: String, concreteType: String)'''  
  ''':TupleType(name: String, concreteType: String, value :OclAny) ='''
+
  ''':TupleType(name: String, concreteType: String, value&nbsp;:OclAny) ='''
 
   
 
   
  let elementAttribute : Set(TupleType(name: String, concreteType: String, value :OclAny)) =
+
  let elementAttribute&nbsp;: Set(TupleType(name: String, concreteType: String, value&nbsp;:OclAny)) =
 
  Set{Tuple{name = 'value', concreteType = 'String', value = value}} in
 
  Set{Tuple{name = 'value', concreteType = 'String', value = value}} in
 
  Tuple{name = attrName, concreteType = concreteType, value = elementAttribute}
 
  Tuple{name = attrName, concreteType = concreteType, value = elementAttribute}
Line 61: Line 55:
 
  ''-- *********** Locator''
 
  ''-- *********** Locator''
 
  '''helper def: locator(attrName: String, value: String, concreteType: String)'''  
 
  '''helper def: locator(attrName: String, value: String, concreteType: String)'''  
  ''':TupleType(name: String, concreteType: String, value :OclAny) ='''
+
  ''':TupleType(name: String, concreteType: String, value&nbsp;:OclAny) ='''
 
   
 
   
  let elementAttribute : Set(TupleType(name: String, concreteType: String, value :OclAny)) =
+
  let elementAttribute&nbsp;: Set(TupleType(name: String, concreteType: String, value&nbsp;:OclAny)) =
 
  Set{Tuple{name = 'value', concreteType = 'String', value = value}} in
 
  Set{Tuple{name = 'value', concreteType = 'String', value = value}} in
 
  Tuple{name = attrName, concreteType = concreteType, value = elementAttribute}
 
  Tuple{name = attrName, concreteType = concreteType, value = elementAttribute}
 
  ''';'''
 
  ''';'''
  
After running this program, you will notice that a MetaMetaModel element has been created in the megamodel as shown in the figure below.
+
After running this program, open the AM3 Megamodeling perspective and you will notice that a MetaMetaModel element has been created in the megamodel as shown in the figure below. [[Image:MoScript-MetaMetamodelRegistration.png]]
[[Image:MoScript-MetaMetamodelRegistration.png]]
+
 
+
===== Code explanation  =====
+
 
+
The operation that does the registration of a model in the Megamodel is ''<span style="color:#800000">register</span>''(model_element_tuple). The model_element_tuple parameter corresponds to a tuple with the following structure:
+
 
+
  TupleType(concreteType&nbsp;:String, value&nbsp;:Set(TupleType(...)))
+
 
+
Where
+
 
+
*'''concreteType''': Is a string with the concrete type of the model element to be created. The string must be in the form of ''Package::ConcreteType''. For instance GlobalModelManagement::URI, GlobalModelManagement::ReferenceModel etc.
+
*'''value''': Corresponds to a set of attributes and references of the model element, each of them described again by a tuple as follows:
+
**'''Attribute tuple''':<pre>TupleType(attributeName&nbsp;:String, primitiveType&nbsp;:String, attributeValue&nbsp;:String)</pre>
+
**'''Single value reference tuple''':<pre>TupleType(creationId&nbsp;:String, referenceName&nbsp;:String, concreteType&nbsp;:String, referenceValue&nbsp;:Set(TupleType(...)))</pre><pre>TupleType(referenceName: String, concreteType&nbsp;:String, creationId: String)</pre>
+
**'''Multi value reference tuple''':<pre>TupleType(referenceName&nbsp;:String, concreteType&nbsp;:String, referenceValue&nbsp;:Set(TupleType(...)))</pre>
+

Latest revision as of 05:16, 8 February 2012

Megamodel Population Part 1

A requisite for start working with MoScript is to count with a populated megamodel i.e, a megamodel with elements, which point to modeling artefacts. This megamodel population can be done through the AM3 graphical user interface, nevertheless Registering a high amount of models through the GUI is a repetitive, error prone and time consuming task. In those cases is better to use textual syntax to populate the megamodel, so, in this use case we are going to show how is possible to programmatically populate the Megamodel with MoScript.

Registering the EMF metametamodel

As first step we are going to register programmatically the Ecore metametamodel in the Megamodel, to be able to register metamodels that conform to it and subsequently models that conform to those metamodels. For this, we have to have in mind that in order for MoScript to be able manipulate any model (remember that a metametamodel is also a model), the model must have at least an identifier to unequivocally identify it, a locator, to be able to locate the file that represents the model, and a reference model describing it, in order to be able to inspect its content.

If we check the Megamodels metamodel (GlobalModelManagement) we will see that a Metametamodel is a ReferenceModel and has references to Identifier, Locator and a ReferenceModel among others (see the picture bellow)
MoScript-MetaMetaModel.png MoScript-IdentifierLocator.png

The code for resgistering a MetaMetamodel in the Megamodel is the following:

program megamodelPopulation

do{
   -- Creates the Ecore metametamodel element in the megamodel
   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')
       )
   );
}

-- *********** Helper for creating the tuple for the element type
-- *********** Metametamodel
helper def: metametamodel(identifier : TupleType(name: String, concreteType: String, value :OclAny)
                         ,locator : TupleType(name: String, concreteType: String, value :OclAny))
:TupleType(name: String, concreteType: String, value :OclAny) =

	let id: String = identifier.value.asSequence()->first().value in
	let concreteType: String = 'GlobalModelManagement::Metametamodel' in
	let creationId: String = '@' + concreteType + '#' + id in
	let attributes : Set(TupleType(name: String, concreteType: String, value :OclAny)) = 
		Set{
			Tuple{name = '__id', concreteType = 'String', value = id},
			identifier, 
		    locator, 
		    Tuple{name = 'conformsTo', concreteType = 'GlobalModelManagement::ReferenceModel', value = creationId}
		} in 
	Tuple{creationId = creationId, concreteType = concreteType, value = attributes} 
; 

-- *********** Helper for creating the tuple for the element type 
-- *********** Identifier
helper def: identifier(attrName: String, value: String, concreteType: String) 
:TupleType(name: String, concreteType: String, value :OclAny) =

	let elementAttribute : Set(TupleType(name: String, concreteType: String, value :OclAny)) =
		Set{Tuple{name = 'value', concreteType = 'String', value = value}} in
	Tuple{name = attrName, concreteType = concreteType, value = elementAttribute}	
;

-- *********** Helper for creating the tuple for the element type 
-- *********** Locator
helper def: locator(attrName: String, value: String, concreteType: String) 
:TupleType(name: String, concreteType: String, value :OclAny) =

	let elementAttribute : Set(TupleType(name: String, concreteType: String, value :OclAny)) =
		Set{Tuple{name = 'value', concreteType = 'String', value = value}} in
	Tuple{name = attrName, concreteType = concreteType, value = elementAttribute}	
;

After running this program, open the AM3 Megamodeling perspective and you will notice that a MetaMetaModel element has been created in the megamodel as shown in the figure below. MoScript-MetaMetamodelRegistration.png