Skip to content
Nicolas B edited this page Sep 20, 2016 · 1 revision

JavaScript - Modelling Framework (core)

The JavaScript - Modelling Framework

The JavaScript - Modelling Framework (JS-MF) provides a set of model management tools embedded in JavaScript (à la embedded DSL). The purpose of JS-MF is both to provide both a framework for quick prototyping and a robust technology for online model management. JS-MF can run either on the server side (with NodeJS) or in the browser (for the browsers, a specific distribution is available to get rid-of NodeJS dependencies).

Its features are inspired by traditional modelling tools like the Eclipse Modelling Framework or the ATLAS Transformation Language (ATL).

The core component

The core component provides all you need to define metamodels and models. It allows:

  • The definition of Classes;
  • The definition of Enums;
  • The definition of Models;
  • The creation of Instances of classes and models;
  • The definition of custom types for attributes;
  • The definition of associated data on references.

Classes

JS-MF Classes use the standard differentiation between attributes and references.

Attributes are typed. A set of predefined types covers many standard JavaScript values, but the users can add custom types.

References should target other JSMF Classes, they can have an indicative cardinality (that can be checked, as other constraints, with jsmf-check).

JS-MF also provides multi-inheritance, where properties definition are resolved using a depth-first strategy.

Examples

Here is an excerpt of the traditional "Family to person" example, in JS-MF:

// Creation of a Person class with 2 attributes : name and age
const Person = new JSMF.Class('Person', {name : String, age: Number})
					
// Creation of a Family class with 1 attribute : familyName and one reference to person: familyMember
const Family = new JSMF.Class('Family', {familyName: String},
                                        {familyMember: {type: Person, cardinality: JSMF.Cardinality.any}})

In the examples directory, you can also find an implementation of the ArduinoML example.

Enums

Enums is the traditional "Enumeration type". As in many modelling languages, key values can be associated to the Enum values. If no key is provided, default keys will be generated.

Examples

// Without explicit keys
const Day = new Enum('Day', ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'])

// With explicit keys
const State = new Enum('State', {on: 1, off: 0})

Model

In JS-MF, a Model is basically a set of JS-MF objects (classes instances, classes, enums, or other models). There is no explicit difference between meta-models and models but a model can has a reference model. The reference model does not constrain the model content. However, the reference model can contain constraints that can be checked with JSMF-check (the JS-MF component dedicated to model verification).

The Model constructor provides facilities to add a whole model by adding only its entrypoint.

Example

Given the above classes of the family to person example:

// model declaration          Model name  -  Reference Model -  Model elements
const FamilyModel = new Model('FamilyModel',    undefined,     [Family, Member])