Model import and export

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

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.

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: http://viatra.inf.mit.bme.hu/download/hu.bme.mit.viatra.testimporter.zip

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

Fig. 1 Exporting models step 1

Fig. 2 Exporting models step 2

Fig. 2 Exporting models step 3

Importing UML2 models to VIATRA2

Fig. 2 Importing models step 1 (Creating model space)

Fig. 2 Importing models step 2 (Invoking the importer)

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