Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

VIATRA2/UseCases/ModelExportImport

< VIATRA2‎ | UseCases
Revision as of 12:13, 23 February 2010 by Ujhelyiz.mit.bme.hu (Talk | contribs) (fix of a link)

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.

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.

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.

Back to the top