Model Components services

Modelio model component services provide a programmatic access to the model components of the currently opened project.

About Model Components

A complete presentation of Modelio Model Components can be found in the Modelio User documentation. However let us remind here their main characteristics:

  • A Model components is an independent, identified and coherent part of a larger model.
  • A Model components is packaged into an individual single file.
  • A Model component has a version number.
  • A Model component has to be deployed in a project for its contents to be available.
  • A Model component’s contents is read-only in the project it has been deployed in.

The model component API therefore naturally provides functions to:

  1. List the model components of the project
  2. Deploy a model component in the project
  3. Remove a model component from the project

IModelComponentService

The IModelComponentService object provided by Modelio represents the access point to the model component API.

Using the model component API consists in:

  1. Getting the IModelComponentService.
  2. Calling one of the provided methods.

Example:

1...
2IModelComponentService mcService = Modelio.getInstance().getModelComponentService();
3...

Listing the model components

From the IModelComponentService instance, listing the currently deployed model components is straightforward.

1...
2IModelComponentService mcService = Modelio.getInstance().getModelComponentService();
3
4for (IModelComponentDescriptor mcDesc : mcService.getModelComponents() ) {
5    System.out.println("  - " + mcDesc.getName() + ", " + mcDesc.getVersion().toString());
6}
7...

Note the type of the returned values which is IModelComponentDescriptor.
IModelComponentDescriptor is a convenient object that holds the main administrative data about a model component:

  1. its name
  2. its version
  3. its archive name

Listing the existing model components of the current project is typically used to check that a required model component is present and react accordingly if it is not present (warn the user, propose to deploy and so on)

Deploying a model component

Deploying a model component consists in making its contents available in the current project given its archive. this has to be done once in a project although there is no harm doing it several times except that the operation may take some time.
Updating a model component consists in deploying the next version of an already deployed model component. At the API level this case is treated exactly as an initial deployment.

 1...
 2IModelComponentService mcService = Modelio.getInstance().getModelComponentService();
 3
 4File archive = ... // code to get a Java File object representing the model component archive file path
 5IProgressMonitor monitor = null; 
 6
 7mcService.deployModelComponent(archive, monitor);
 8
 9...

The second parameter passed to the deployModelComponent() method is a progress monitor object from org.eclipse.core.runtime, see Eclipse documentation for more details on IProgressMonitor objects. This parameter can safely be null , but of course null will provide no monitoring at all.

Removing a model component

Removing a model component from the currently opened project consists in deleting all the model elements that the model components has brought in the model at deployment time.

This is a quite complex operation that can lead to serious side-effects:
Just imagine that your model is currently heavily using classifiers defined in the model component being removed, to type its attribute associations or parameters. Removing the model component will literally undefine the type of all these elements and most probably somewhat break the model. Furthermore, the removal of a model component might even fail if some elements using it cannot be modified for some reasons.

1...
2IModelComponentService mcService = Modelio.getInstance().getModelComponentService();
3IModelComponentDescriptor mcdescriptor = ... // code to get the descriptor of the modelcomponent to remove
4
5mcService.removeModelComponent(mcService);
6
7...

Note that there is no available IModelComponentDescriptor constructor and that only values returned by getModelComponents() or deployModelComponent() can be used.