Norwegian University of Science and Technology

Global navigation

This is an old revision of the document!

Using Javascript with Diamodl and Ecore

The Diamodl editor and runtime support using Javascript (by means of the GNU Rhino engine) for implementing functions and actions (e.g. enter and exit actions). The Javascript engine has been extended with support for Ecore, so Ecore classes and objects may be referred to and used in a natural way.

Javascript provides three means for navigating in data: in-scope variables, properties and indices. By utilising these, we can make Diamodl and Ecore model elements first-class citizens in Javascript.

Property access

Property access in Javascript uses dot or bracket syntax: .<property> or ['<property>'], e.g. or person['name'] both access the 'name' property of the object referred to by the person variable. The bracket syntax is mostly used when the property name contains special characters, like space, or is a reserved word.

Property access on Ecore objects are interpreted in two ways. First, it is used to refer to attributes and references (associations in UML terminology), resulting in either a simple value or a List (usually EList). Second, if there is no attribute or reference, the content of an object is searched through, looking for one with a 'name' attribute value equal to the property. This is a very useful shortcut, since many common classes defines a 'name' attribute. Among others, Ecore package (EPackage) objects contains a set of classes (EClass objects) with a name attribute. This means that aPackage.aClass accesses the class named 'aClass' in the package referenced by the 'aPackage' variable. Similarly, all Diamodl flow nodes have a name attribute and may be referenced as properties of their parents. E.g. accesses the input-send (named 'is') gate of interactor.

Index access

Index access in Javascript uses the bracket syntax: [n], e.g. persons[0] accesses the first object in the object referenced by the 'persons' variable. This works for arrays and lists, but may also be implemented for other kinds of objects.

Index access on Ecore objects accesses the content list of the object. E.g. if a mail folder ('MailFolder' object) contains messages ('Message' objects), folder[1] will access the second message in the object referenced by the 'folder' variable.

Pre-defined variables

The Ecore packages that are loaded are available as variables in the scope that Javascripts are executed in. By using property access, as described above, it is easy to locate specific Ecore classes.

Similarly, the top-level Diamodl interactor or diagram may be accessed by its name.

Ecore-specific functions

A small set of functions for operating on Ecore model element (e.g. classes) are defined.

2007/11/20 11:12, Hallvard Trætteberg
NTNU, NO-7491 Trondheim. Telephone: +47 73 59 50 00. Contact us
Editorial responsibility: