5 min. reading time

KerML (Kernel Modeling Language) is a model-based language that serves as the core for SysML v2. It is a metamodel-based language that provides a formal foundation for modeling and adheres to principles such as precision, extensibility, and interoperability. It is comparable to ECORE from the Eclipse Modeling Framework (EMF) - an abstract kernel for subsequent modeling tools. 

In model-based / modeldriven based tooling, the Eclipse Modeling Framework EMF was very influential. It is a comprehensive framework that covers a plethora of use cases. It can be easily extended with new use cases. Although it seems to be loosing a bit of traction with many parties moving to Python or web-based tech stacks and reinventing the wheel, it still plays a role in many frameworks (Franca, Topcased, Papyrus etc.).

The consortium of the GAIA-X lighthouse project COOPERANTS uses an in-house systems engineering tool of one of the members as a collaborative platform for multi-party systems engineering. Although that tool is not EMF-based, it uses the EMF based "Ecore"-format to define its meta-model. Ecore models are usually created by applying one of the following approaches:

  • Direct editing with Ecore-Tooling (not the greatest user experience)
  • Transforming an UML model to Ecore, based on a profile (e.g. with Magicdraw or Papyrus)
  • Textual Definition with the XCore tools, which provide a textual DSL for creating the artifacts
  • Deriving the model from an Xtext grammar

I personally like the XCore approach, since it is a nice user experience with a lean tooling. However, since the systems engineering community is adopting SysML v2 as a standard including a textual notation, why not have a look at that? So in the last weeks of COOPERANTS we started adopting KerML as modelling language for space metamodels.

Basic Modelling

The SysML pilot implementation comes with an example for an addressbook that illustrates that it is well suited also for data modelling:

private import ScalarValues::*;
private import Ecore::*;

package AddressBookModel {
	
	class Entry {
		name: String;
		address: String;
	}

	class AddressBook {
		enries: Entry[*];
	}
}
Listing 1: SysML Pilot AdressBook Example

 

A simple KerML textual notation to .ecore generator is written in a few hours. The major challenge is understanding the new meta-model and navigating through the model hierarchy (finding right way to get multiplicities and feature values) was one thing.

Exending KerML by adding metadata

Code generation or model transformation often needs additional data to define specifics of the target model, which are not direct model concepts in the source model. In the modelling process of Ecore with UML we might have used stereotypes and tagged values. These concepts did not find their way into SysML v2 directly. But SysML v2 has the concept of meta-data. We can use this to define some aspects required to configure a full .ecore:

private import ScalarValues::*;
library package Ecore {
	metaclass ECoreAnnotation {
		feature nsPrefix : String;
		feature nsURI : String;
		feature ANNOTATIONS_SOURCE : String;
		feature modelName : String;
	}
}

Listing 2: Metadata for an Ecore Package Annotation

Now we can augment our address book model to include additional information for the generated target ecore.

private import ScalarValues::*;
private import Ecore::*;

package AddressBookModel {

	@ECoreAnnotation {
		modelName = "AddressBook";
		nsURI = "https://addressbook";
	}
	class Entry {
		name: String;
		address: String;
	}
	
	class AddressBook {
		entries: Entry[*];
	}
}

Listing 3: Configuation of generated Ecore based on meta-data

Now we are able to configure our systems engineering's tool meta-model based on KerML and use .ecore as a standard interface / configuration file to configure the model. A nice advantage of the SysML v2 is the support of the textual notation. The pilot implementation of the textual notation is based on the great Xtext framework which was to a large degree sponsored, conceived and implemented by itemis AG.

For those who want to load the textual files in a standalone Java applications, there are a few code snippetes on the internet showing how to load Xtext models standalone. To simplify things further, here is a code snippet for loading KerML files in a Java application:

package com.itemis.ocean.sysml;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.xtext.resource.XtextResourceSet;
import org.omg.kerml.xtext.KerMLStandaloneSetup;
import org.omg.sysml.lang.sysml.SysMLPackage;

import com.google.common.collect.Streams;
import com.google.inject.Injector;

public class SysMLReader {
    public static void main(String[] args) {
        SysMLReader sreader = new SysMLReader();
        sreader.read();
    }

    public void read() {
        Injector injector = new KerMLStandaloneSetup().createInjectorAndDoEMFRegistration();
        SysMLPackage registerMe = SysMLPackage.eINSTANCE;
        injector.injectMembers(this);


        XtextResourceSet resourceSet = injector.getInstance(XtextResourceSet.class);
 Resource resource = resourceSet.getResource(URI.createFileURI("./Vehicles_3.kerml"), true);
 Streams.stream(resource.getAllContents()).forEach(System.out::println);
  }
}

Listing 4: Example implementation for Java

Hope that helps those who are interested in KerML/SysML v2 and make it accessible.

Further information:

 

Comments