Jump to: navigation, search

Difference between revisions of "MoScript"

Line 113: Line 113:
 
*<pre>Model&nbsp;:: save(location&nbsp;:String)</pre>This operation stores the model in '''''location'''''&nbsp;&nbsp; &nbsp;  
 
*<pre>Model&nbsp;:: save(location&nbsp;:String)</pre>This operation stores the model in '''''location'''''&nbsp;&nbsp; &nbsp;  
 
*<pre>ATLTransformation&nbsp;:: applyTo(Map{(key&nbsp;:String, model&nbsp;:Model),...,(..., ...)})&nbsp;:Map(key&nbsp;:String, model&nbsp;:Model)</pre>This operation applies the a transformation to one or more models. The '''''key''''' is the alias of that identifies the model inside an ATL transformation module and '''''model''''' is a model obtained from the megamodel.  
 
*<pre>ATLTransformation&nbsp;:: applyTo(Map{(key&nbsp;:String, model&nbsp;:Model),...,(..., ...)})&nbsp;:Map(key&nbsp;:String, model&nbsp;:Model)</pre>This operation applies the a transformation to one or more models. The '''''key''''' is the alias of that identifies the model inside an ATL transformation module and '''''model''''' is a model obtained from the megamodel.  
*<pre>register(TupleType(concreteType&nbsp;:String, value&nbsp;:Set(TupleType(...))))</pre>This operation does the registration of a model in the megamodel i.e. it creates a new element in the megamodel of type '''''concreteType'''''.  
+
*<pre>register(TupleType(concreteType&nbsp;:String, value&nbsp;:Set(TupleType(...))))</pre>This operation does the registration of a model in the megamodel i.e. it creates a new element in the megamodel of type '''''concreteType''''' 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>
 
*<pre>ReferenceModel&nbsp;:: registerInEMFpkgReg()</pre>This operation registers the reference model in the EMF packages registry
 
*<pre>ReferenceModel&nbsp;:: registerInEMFpkgReg()</pre>This operation registers the reference model in the EMF packages registry
  

Revision as of 10:19, 22 December 2011

< To: MDT
< To: MoDisco
< To: AM3

AM3
Download
Community
Mailing ListForum
Bugzilla
Opened bugs
All bugs
Contribute
Browse Source

The MoScript prototype (extending AM3), being developed by the AtlanMod Team, is part of the MoDisco project. It provides a textual domain-specific language for model management.

Overview

The goal of MoScript is to provide AM3 with a textual domain-specific language for model management, improving its model management task orchestration expressivity. With MoScript, users can automate model management tasks by means of OCL based scripts. For instance, user may write queries (based on model content, structure, relationships, and behavior derived through on-the-fly simulation) to retrieve models from model repositories, manipulate them (e.g., by running transformations on sets of models), and store them back in the repository. MoScript also allows to populate and update the megamodel automatically by doing reverse engineer of simple modeling artifact repositories.

Download and install

The MoScript prototype is available from the Eclipse-MDT MoDisco SVN (sources only). The steps to install MoScript are the following:

  1. Download the Eclipse Modeling Tools from here: Eclipse Modeling Tools (Indigo)
  2. Install ATL from sources:
    • Download the ATL source code project set file (.psf) from here [1].
    • Import it into Eclipse with File->Import->Team->Team Project Set.
    • Download the MoScript patch for ATL from Bugzilla – Bug 361688.
    • Click right click on any ATL plugin project and select Team->Apply Patch ... and select the patch to apply it to ATL.
  3. Install sublcipse and subversion if you have not done it yet.
  4. Install AM3 and MoScript from sources:
    • Open the SVN perspective by selecting Window -> Open Perspective-> SVN Repository Exploring perspective.
    • Add a new repository location by selecting File->New->Repository Location. The required parameters are the followings:
    • Browse the just created repository location until /plugins/trunk and checkout all the plugins

Documentation

You can find from this section the documentary resources around the MoScript prototype and underlying approach.

MoScript Hello World!

Create a new MoScript project by clicking on File-> New-> Project and selecting the MoScript project type under the AM3 Folder. MoScript-HelloWorld2.png

Then create a MoScript script by clicking in File-> New-> File. Give it the name helloWorld.mscr. When the file is open, fill it with the following script code:

program helloWorld

do{
 'HelloWorld'.debug();
}

After saving the file, if there are no errors, you should see a new binary file called helloWorld.asm in the project explorer or navigator.

Now that the code is ready, create a MoScript launcher to run the script, by clicking in Run-> Run Configurations... MoScript-HelloWorld3.png

Browse in the workspace for the HelloWorld.mscr file and select it. Then, in the advanced tab, check the options Clear console before launch and Print execution times to console, so that you can clearly see when de script finishes.

MoScript-HelloWorld4.png

Then press the Apply button and the Run button. In the console window you will see an error like the following:

Error loading file:...workspacePath/.am3/megamodel.xmi: java.io.FileNotFoundException: ... (No such file or directory)

This is because the megamodel file has not been created yet.

For creating the megamodel file, open the AM3 Perspective. MoScript-HelloWorld1.png

Create any model element in the megamodel left clicking in any element in the left panel, selecting new [element]. Give any value to the element and then use File->Save option to save the Megamodel. With this operation the Megamodel file is created in the filesystem. MoScript-HelloWorld5.png

Now try again to run the script by clicking on Run->Run History->Hello World and you should see the output in the console. MoScript-HelloWorld6.png

The MoScript Language

MoScript reuses a big part of the ATL syntax like the OCL expressions, the control flow statements and the helpers. If you have any doubt about the syntax of MoScript please try to solve it by using the ATL syntax. Please note that MoScript does not have the concept of Rule.

General Structure

A MoScript program has the following general structure:

program program_name

uses library ... 

[using {
-- Comments

-- Variable declarations 
variable :type = OclExpr;
...
}]

do {
-- Value assignements
variable <− OclExpr;

-- Operations invocations
save(...);

-- Operations invocations
... remove(OclExpr); 

-- Operations invocations
... register (...) ;
     
-- Control flow statements
if...  

-- Control flow statements
for . .
}

helper context OclAny def: helper_name( params ) :return_type	
. . . 
;

A program has two sections, the using and do sections. The using section is optional, and is used for declaring variables and assigning their initial value. The do section is mandatory and is the core of the program. In it, operations are used in combination with control flow statements and OCL queries to perform modelling artefacts manipulations.

Operations

  • Model :: allContentInstancesOf(elementType :String): Collection(OclAny)
    This operation dereferences and load the physical model represented by the Model element. Then it queries the model and return a collection of OCL elements of type elementType. The elements of the resulting collection are used as entry points to the model, from where the rest of the elements may be reached. Subsequent queries to the model content are made with standard OCL expressions.
  • Model :: inject(injectorName: String, modelElement: TupleType(...)) : Model
    This operation make a projection of model expressed in a textual syntax to a model in XMI conforming to a given metamodel. injectorName is the name of the injector that is going to be used to make the projection of the model and modelElement represents the metadata information that will describe the new model. The structure of the tuple is explained in ... 
  • Model :: save(location :String)
    This operation stores the model in location    
  • ATLTransformation :: applyTo(Map{(key :String, model :Model),...,(..., ...)}) :Map(key :String, model :Model)
    This operation applies the a transformation to one or more models. The key is the alias of that identifies the model inside an ATL transformation module and model is a model obtained from the megamodel.
  • register(TupleType(concreteType :String, value :Set(TupleType(...))))
    This operation does the registration of a model in the megamodel i.e. it creates a new element in the megamodel of type concreteType 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:
        TupleType(attributeName :String, primitiveType :String, attributeValue :String)
      • Single value reference tuple:
        TupleType(creationId :String, referenceName :String, concreteType :String, referenceValue :Set(TupleType(...)))
        TupleType(referenceName: String, concreteType :String, creationId: String)
      • Multi value reference tuple:
        TupleType(referenceName :String, concreteType :String, referenceValue :Set(TupleType(...)))
  • ReferenceModel :: registerInEMFpkgReg()
    This operation registers the reference model in the EMF packages registry

Examples

  • Get all the models in the megamodel, select the first and and get a collection of all its elements of type EClass.
    !Model.allInstances()->first().allContentInstancesOf('EClass');

Screencasts & slides

MoScript: A textual DSL for model manipulations (slides)

Related publications

MoScript: A DSL for querying and manipulating model repositories (paper)

Use Cases

MoScript comes with a set of use cases showing different possible uses of the MoScript tool in various contexts and for varied purposes (similarly to what is done in the M2M ATL project). A general description is given for each of these use cases, as well as some more precise documentations for many of them. For some, prototypes have already been implemented and are directly downloadable from their respective 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. This megamodel population can be done through the AM3 graphical user interface, nevertheless registering a high amount of models in the megamodel through the GUI is a repetitive and time consuming task. In those cases is better to use a textual syntax, so we can repeat the process the times we want, make changes easily to it or take it as base for future megamodel populations. In this use case we show how is possible to programmatically populate the Megamodel with MoScript. Click here for more details and actual resources...

YYY

To be completed.

Support

Relationships with other Eclipse Projects

MoScript reuses different existing EMP (Eclipse Modeling Project) projects: To be completed.