Jump to: navigation, search

VIATRA2/UseCases/ModelExportImport

< VIATRA2‎ | UseCases
Revision as of 12:11, 28 November 2012 by Rath.mit.bme.hu (Talk | contribs)

Model import and export

The VPM model space can be populated by various importer plugins including support for

  • UML2
  • BPEL and other business process modeling notations
  • various domain-specific models (using XML or EMF-based model representations)

The list of importers can be extended by users of the framework using the Eclipse extension point mechanism. There is also support for exporting models from the VPM format.

Model importers can be invoked from the popup menu of the open model spaces in the Model spaces view, using the Native Importers submenu. After selecting the importer type the file to be imported has to be selected.

Generic EMF metamodel and instance import

VIATRA2 has built-in support for importing EMF metamodela and instance models, with an experimantel exporter available as well.

If you would like to use EMF models, make sure to check out EMF-IncQuery (https://viatra.inf.mit.bme.hu/incquery), which can be used to define and match patterns over EMF models without importing or using the VIATRA2 framework.

On the other hand, if you want to use VIATRA2 for transformation as well, you can get the EMF importer from http://static.inf.mit.bme.hu/viatra/update/nightly/. You can invoke the EMF metamodel and instance importers from the "VIATRA2 model spaces" view, by right-clicking on the modelspace and selecting the proper importer from the "Native importers" list.

You can import a .ecore file without problems if the EMF importer feature is installed, but the instance importer will not work instantly. In order to make the instance importer work you need to either: a) install VIATRA2 from the update site in the host, have the EMF model project with the generated code in the workspace of host. Start the runtime after making sure that both VIATRA2 and the model plugin are among the plugins included in the runtime (you can check this on the Plugins tab in the Run Configurations dialog. Then, you can create a VIATRA2 model space file in the runtime workspace and use the instance importer to import your model (if you can open your instance without errors in the Sample Reflective Ecore Model Editor or the generated EMF tree editor, then the import should work as well). b) export the generated EMF model plugin (including .ecore, .genmodel, src) into the target platform and install VIATRA2 as in a). I would recommend against it, as it's usually better to differentiate the development and test Eclipse, but may work if you won't change the model plugin in the future.

The EMF instance importer component of VIATRA2 is only capable of handling models that are instances of registered packages. Otherwise, you can use VIATRA2 in the host as well (an other exception is probably the experimental EMF instance exporter function).

If your model has some special properties that prevents it from being correctly imported by the VIATRA2 EMF importer, you can contact us with some description, the model plugin and the instance model and we will try to help you solve the issue.

Creating model importers

The org.eclipse.viatra2.core.modelimport extension point is used by the VIATRA2 framework to add model import capabilities. The implementation has to implement the org.eclipse.viatra2.imports.NativeImporter interface, that provides methods for importing elements from a file and an InputStream.


public interface NativeImporter {
/**
* Processes the given file, and imports its content to the modelspace
* 
* @param f     File name
* @param fw    The current framework
* @throws VPMRuntimeException
*/
public void processFile(String f, IFramework fw) throws VPMRuntimeException;
/**
* Processes the given stream, and imports its content to the modelspace
* 
* @param f     The stream to process
* @param fw    The current framework
* @throws VPMRuntimeException
*/
public void process(InputStream f, IFramework fw)
		throws VPMRuntimeException;
}

The IFramework interface has to be used to get the IModelManager element, that provides direct API for creating model elements:

IModelManager modelManager = fw.getTopmodel().getModelManager();
try {
 //Creating the model elements
 modelManager.newEntity("test");
} catch (VPMCoreException e) {
// TODO Auto-generated catch block
e.printStackTrace();
throw new VPMRuntimeException(e.getMessage());
}

In general a model importer works by traversing the source model starting in the process, or processFile methods, and during the traversal the IModelManager instance can be used for code generation. The importer might also need to connect to already existing elements (e.g. metamodel elements for instanceOf relationships), that is also possible using the IModelManager.

You can find an empty skeleton Eclipse project for a model importer here: [1]

Exporting models

There are two basic ways to export the model space: either by writing a Java program that traverses the model space, or by writing a transformation program with output capabilities.

For the first option a similar program can be created to importers: the model manager can be used to get the different elements in Java code.

The transformation program may output strings: this solution can be used to create any kind of textual representation of the model. For more details see Code Generation.

Sample model import scenario: UML2

VIATRA2 supports model import for Eclipse UML2 models. This feature was developed and tested with using IBM Rational Software Architect 7.0, but (theoretically) it should also run for other UML tools providing UML2 export. Note: the UML2 importer is still in the development stage.

Now we provide a sample scenario how such UML2 models can be exported to VIATRA.

Exporting UML2 models from IBM Rational Software Architect 7.0

As the first step, your UML needs to be exported from IBM Rational Software Architect 7.0

  • Step 1: First, select the UML model in IBM RSA that you plan to export
    • Right-click on the selected project
    • Choose Export... from the pop-up menu
Fig. 1 Exporting models step 1
  • Step 2: Then select Other -> UML Model from the Export dialog
Fig. 2 Exporting models step 2
  • Step 3: Finally, choose the model you want to export and the destination directory.
    • Select Recreate IDs and deselect Export applied profiles
Fig. 2 Exporting models step 3

Importing UML2 models to VIATRA2

  • Step 0: If you would like to import a UML2 model into an existing model space, then skip Step 1 below.
    • If your model space does not contain the UML2 metamodel (available at uml2.metamodel), then
      • Create a new model space as described below
      • Afterwards, merge the new model space with your existing one (TODO)
  • Step 1: Create a new model space (see above) but also select UML2.1 metamodel in the model space wizard
Fig. 2 Importing models step 1 (Creating model space)
  • Step 2: Right click on the designated model space (with the FW icon) in VIATRA2 Model spaces. Then select Native importers -> UML2 Importer (Rational Software Modeler 7.0)
Fig. 2 Importing models step 2 (Invoking the importer)
  • Step 3: Select the previously exported UML2 model, and click on Open

You should find your UML2 model below uml2.models in the tree view editor of the corresponding model space.

Tips and tricks with using UML2 Profiles

  • take note of the VIATRA2 Preference Page on UML2 Profiles To Ignore. Unless you specify profiles that should not be ignored when importing UML2 models, your imported UML2 instance models will lose profile/stereotype information. For details, see http://www.eclipse.org/forums/index.php/t/350913/
  • make sure to include the UML2 Resources plug-in into an RCP application if you plan on embedding VIATRA2 and UML2 into custom RCP Applications.