Modelling and Programming

 

Modelling and programming have traditionally been seen as separate activities. Their respective technologies tend not to integrate. This is frustrating because models usually represent executing systems and programming languages need to provide features that map onto concepts from problem domains. This leads to a gap between models and programs that model-driven techniques seek to bridge. There are a number of ways in which this gap could be addressed:

 

o   Modelling languages can be made executable so that they completely address the systems they are used to represent. It is easier to map a complete model to an implementation than an incomplete one.

o   Languages can be made flexible so that domain specific features can be directly represented and thereby close the conceptual gap between the problem domain and its representation, or a model and its implementation.

o   Programming languages can subsume models so that programming and modelling are performed using the same platform. Programs can easily reason about, manipulate and transform models.

o   Both modelling and programming technologies can be organized in terms of meta-architectures that support reflection and meta-level extensions. General purpose features can co-exist with specialized language constructs.

 

XMF and XModeler were designed to address these issues.

 

XMF

 

XMF is a programming language designed to support meta-programming and domain specific languages. XMF runs on a VM written in Java in terms of a self-describing data-model. The structure of XMF data is shown as a class diagram in XModeler as:

:Overview_files:image001.png

 

The XMF data model is similar to MOF and ECore in that you can write programs that reflect on their own structure. Unlike MOF and Ecore, the XMF kernel meta-model includes behaviour:

:Overview_files:image003.png

 

XMF is both a compiled and interpreted language (like Lisp and Smalltalk) where both the compiler and the interpreter are written in XMF. The basic language included with XMF is based on OCL with the following differences:

o   Higher-order functions: functions make it easy to define general-purpose data transformations. OCL iterators are encoded using functions in XMF.

o   Variables and update: the addition of state to OCL turns it into a convenient very high-level programming language. If you use XMF to do modelling then you can ignore this feature.

o   Pattern matching: data can be matched and deconstructed using patterns. This is used extensively in model transformations.

 

The XMF VM supports the following features:

o   IO: XMF uses a variety of channels that work in the same way as Java streams. The IO package in XMF provides extensive support for serializing data, for example as XML.

o   Foreign Functions: it is easy to load Java classes and make them work as though they are XMF classes.

o   Threads: used, for example, in socket connections.

o   Daemons: used to monitor changes to slot values on any object.

o   A Meta-Object Protocol: allows key VM instructions to be extended by the user.

o   Undo: transactional state changes can be undone.

 

Another key feature of XMF is the ability to extend the core language with syntax classes. A Syntax class has a grammar that describes how to process the concrete form of the new language construct and how to produce a replacement abstract syntax structure. The grammar language and parsing machinery are all written in XMF:

:Overview_files:image005.png

XMF is a Java program and can be downloaded by following this link. Instructions for starting XMF are given here under Software -> XMF. There are many language constructs included in XMF including: loops; classes; XML processors; code generators; micro-Java; rule-based languages; data walkers; HTML generation; pretty printers. XMF classes allow new definitions to be added dynamically and therefore system classes can be extended.

 

XModeler

 

XModeler is a tool for executable modeling. It is build on top of XMF by adding language constructs for controlling GEF libraries on Eclipse. It can be used as an IDE for developing XMF programs and for modeling systems. Since it provides access to graphical primitives it allows graphical modeling languages to be developed in a number of ways, for example meta-packages are a lightweight way of producing a tailored language.

Here is a simple example of the use of XModeler to develop and view an XMF application. Firstly open a file browser containing a number of files. A manifest is like a Make-file on Unix; .xmf files contain XMF source code; .xml files contain diagram layout information:

:Overview_files:image007.png

 

The Library.xmf file contains a standard Library model written in XMF:

 

:Overview_files:image009.png

 

Compile and load the file. The resulting package can be browsed as a tree and viewed as a diagram:

 

:Overview_files:image011.png

 

Object diagrams (snapshots) can be created interactively or using XMF language constructs. Here is a simple snapshot creation program:

 

:Overview_files:image013.png

 

Here is another one:

 

:Overview_files:image015.png

 

Loading the snapshot and running test(2) produces the following diagram:

 

:Overview_files:image017.png

 

Remember the constraints defined on the classes in the Library model? We can run those against the snapshot and produce a report (too large to see everything):

 

:Overview_files:image019.png

 

How about those constraints? Some of them seem to have the same structure. Look at all_books_have_unique_titles and all_readers_have_unique_names. They do the same check, just using different slots – right? XMF allows us to capture this as a new language construct:

 

:Overview_files:image021.png

 

The definition of the new language construct is given as a syntax class called Unique:

 

:Overview_files:image023.png

 

XModeler can be downloaded here (for Windows and Mac) and includes extensive documentation including walkthroughs.